public class ByteArrayBuilder extends BuilderBase
ALLOCATION_BOUNDARY, allocationSize, DEFAULT_ASCII_ALLOCATION, DEFAULT_OTHER_ALLOCATION, defaultCharset, NULL
Constructor and Description |
---|
ByteArrayBuilder()
Construct the ByteArrayBuilder with
the initial size and allocation size of
and the character set
StandardCharsets.US_ASCII |
ByteArrayBuilder(byte[] bytes)
Construct the ByteArrayBuilder copying all the bytes
using the character set
StandardCharsets.US_ASCII
and the character set StandardCharsets.US_ASCII
Then initializes the buffer with the supplied bytes |
ByteArrayBuilder(byte[] bytes,
int len)
Construct the ByteArrayBuilder copying the specified number of bytes;
and the character set
StandardCharsets.US_ASCII
Then initializes the buffer with the supplied bytes |
ByteArrayBuilder(java.nio.charset.Charset defaultCharset)
Construct the ByteArrayBuilder with the supplied character set
with the default initial size and allocation size determined by that character set
|
ByteArrayBuilder(int initialSize)
Construct the ByteArrayBuilder with the supplied initial size,
allocation size of
and the character set
StandardCharsets.US_ASCII |
ByteArrayBuilder(int initialSize,
java.nio.charset.Charset defaultCharset)
Construct the ByteArrayBuilder with the supplied initial size and character set
with the allocation size determined by that character set.
|
ByteArrayBuilder(int initialSize,
int allocationSizeSuggestion,
java.nio.charset.Charset defaultCharset)
Construct the ByteArrayBuilder with the supplied initial size,
allocation size and character set
|
Modifier and Type | Method and Description |
---|---|
ByteArrayBuilder |
append(byte b)
Append a byte as is
|
ByteArrayBuilder |
append(byte[] src)
Append an entire byte array
|
ByteArrayBuilder |
append(byte[] src,
int len)
Append a byte array
|
ByteArrayBuilder |
append(byte[] src,
int offset,
int len)
Append a byte array
|
ByteArrayBuilder |
append(ByteArrayBuilder bab)
Appends the data bytes from an existing byte array builder
|
ByteArrayBuilder |
append(java.nio.CharBuffer src)
Append a CharBuffer with default charset.
|
ByteArrayBuilder |
append(java.nio.CharBuffer src,
java.nio.charset.Charset charset)
Append a CharBuffer with specified charset.
|
ByteArrayBuilder |
append(int i)
Append a String representation of the number.
|
ByteArrayBuilder |
append(java.lang.String src)
Append a String with the default charset.
|
ByteArrayBuilder |
append(java.lang.String src,
java.nio.charset.Charset charset)
Append a String with specified charset.
|
int |
appendUnchecked(byte b)
Append a single byte without checking that the builder has the capacity
|
int |
appendUnchecked(byte[] src)
Append the entire byte array without checking that the builder has the capacity
|
int |
appendUnchecked(byte[] src,
int srcPos,
int len)
Append the entire byte array without checking that the builder has the capacity
|
int |
capacity()
Get the number of bytes currently allocated (available) without resizing
|
ByteArrayBuilder |
clear()
Clear the buffer, resetting its length but not capacity
|
int |
copyTo(byte[] dest,
int destPos)
Copy the contents of the buffer to the byte array starting at the destination
positions supplied.
|
void |
copyTo(java.io.OutputStream out)
Copy the contents of the buffer to the output stream
|
ByteArrayBuilder |
ensureCapacity(int bytesNeeded)
Ensures that the buffer can accept the number of bytes needed
Useful if the size of multiple append operations is known ahead of time
|
boolean |
equals(byte[] bytes)
Determine if a byte array contains the same bytes as this builder
|
byte[] |
internalArray()
Access the internal byte array of this buffer.
|
int |
length()
Get the length of the data in the buffer
|
ByteArrayBuilder |
setAllocationSize(int allocationSizeSuggestion)
Change the allocation size
|
byte[] |
toByteArray()
Copy the value in the buffer to a new byte array
|
java.lang.String |
toString() |
_setAllocationSize, bufferAllocSize, getAllocationSize
public ByteArrayBuilder(int initialSize, int allocationSizeSuggestion, java.nio.charset.Charset defaultCharset)
initialSize
- the initial sizeallocationSizeSuggestion
- the allocationSize size suggestiondefaultCharset
- the default character setpublic ByteArrayBuilder()
StandardCharsets.US_ASCII
public ByteArrayBuilder(int initialSize)
StandardCharsets.US_ASCII
initialSize
- the initial sizepublic ByteArrayBuilder(java.nio.charset.Charset defaultCharset)
defaultCharset
- the default character setpublic ByteArrayBuilder(int initialSize, java.nio.charset.Charset defaultCharset)
initialSize
- the initial sizedefaultCharset
- the default character setpublic ByteArrayBuilder(byte[] bytes)
StandardCharsets.US_ASCII
and the character set StandardCharsets.US_ASCII
Then initializes the buffer with the supplied bytesbytes
- the bytespublic ByteArrayBuilder(byte[] bytes, int len)
StandardCharsets.US_ASCII
Then initializes the buffer with the supplied bytesbytes
- the byteslen
- the number of bytes to copypublic int length()
length
in class BuilderBase
public int capacity()
capacity
in class BuilderBase
public boolean equals(byte[] bytes)
equals
in class BuilderBase
bytes
- the bytespublic int copyTo(byte[] dest, int destPos)
length()
method has been called
and the destination byte array has enough space allocateddest
- the destination byte arraydestPos
- the starting position in the destination byte arraypublic void copyTo(java.io.OutputStream out) throws java.io.IOException
out
- the output streamjava.io.IOException
- if an I/O error occurspublic byte[] toByteArray()
toByteArray
in class BuilderBase
public byte[] internalArray()
length()
internalArray
in class BuilderBase
public ByteArrayBuilder ensureCapacity(int bytesNeeded)
bytesNeeded
- the number of bytes neededpublic ByteArrayBuilder clear()
public ByteArrayBuilder setAllocationSize(int allocationSizeSuggestion)
allocationSizeSuggestion
- the new allocation size suggestionpublic ByteArrayBuilder append(int i)
i
- the numberpublic ByteArrayBuilder append(java.lang.String src)
src
- The String from which bytes are to be readpublic ByteArrayBuilder append(java.lang.String src, java.nio.charset.Charset charset)
src
- The String from which bytes are to be readcharset
- the charset for encodingpublic ByteArrayBuilder append(java.nio.CharBuffer src)
src
- The CharBuffer from which bytes are to be readpublic ByteArrayBuilder append(java.nio.CharBuffer src, java.nio.charset.Charset charset)
src
- The CharBuffer from which bytes are to be readcharset
- the charset for encodingpublic ByteArrayBuilder append(byte b)
b
- the bytepublic ByteArrayBuilder append(byte[] src)
src
- The array from which bytes are to be readpublic ByteArrayBuilder append(byte[] src, int len)
src
- The array from which bytes are to be readlen
- The number of bytes to be read from the given arraypublic ByteArrayBuilder append(byte[] src, int offset, int len)
src
- The array from which bytes are to be readoffset
- The offset within the array of the first byte to be read;len
- The number of bytes to be read from the given array;public ByteArrayBuilder append(ByteArrayBuilder bab)
bab
- an existing builderpublic int appendUnchecked(byte b)
appendUnchecked
in class BuilderBase
b
- the bytepublic int appendUnchecked(byte[] src)
appendUnchecked
in class BuilderBase
src
- the source byte arraypublic int appendUnchecked(byte[] src, int srcPos, int len)
appendUnchecked
in class BuilderBase
src
- the source byte arraysrcPos
- starting position in the source array.len
- the number of array elements to be copied.public java.lang.String toString()
toString
in class java.lang.Object