public class ByteArrayBuilder
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_ASCII_ALLOCATION |
static int |
DEFAULT_OTHER_ALLOCATION |
static byte[] |
NULL |
Constructor and Description |
---|
ByteArrayBuilder()
Construct the ByteArrayBuilder with
the initial size and allocation size of 32
and the character set
StandardCharsets.US_ASCII |
ByteArrayBuilder(byte[] bytes)
Construct the ByteArrayBuilder with an existing byte array using it's
length as the initial length, the allocation size the larger of
the length and 32,
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 32
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 allocationSize,
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 a 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) |
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.
|
ByteArrayBuilder |
clear()
Clear the buffer, resetting it's length
|
protected int |
computeAmountToAllocate(int currentPosition,
int bytesNeeded) |
int |
copyTo(byte[] dest,
int destPos)
Copy the contents of the buffer to the byte array starting at the destination
positions supplied.
|
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
therefore reducing the number of possible allocations during those appends
|
boolean |
equals(byte[] bytes)
Determine if a byte array contains the same bytes as this buffer
|
byte[] |
internalArray()
Access the internal byte array of this buffer.
|
int |
length()
Get the length of the data in the buffer
|
ByteArrayBuilder |
setAllocationSize(int allocationSize)
Change the allocation size
|
byte[] |
toByteArray()
Copy the value in the buffer to a new byte array
|
java.lang.String |
toString() |
public static final int DEFAULT_ASCII_ALLOCATION
public static final int DEFAULT_OTHER_ALLOCATION
public static final byte[] NULL
public ByteArrayBuilder()
StandardCharsets.US_ASCII
public ByteArrayBuilder(int initialSize)
StandardCharsets.US_ASCII
initialSize
- the initial sizepublic ByteArrayBuilder(byte[] bytes)
StandardCharsets.US_ASCII
Then initializes the buffer with the supplied bytesbytes
- the bytespublic 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(int initialSize, int allocationSize, java.nio.charset.Charset defaultCharset)
initialSize
- the initial sizeallocationSize
- the allocationSize sizedefaultCharset
- the default character setpublic int length()
public boolean equals(byte[] bytes)
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 byte[] toByteArray()
public byte[] internalArray()
length()
protected int computeAmountToAllocate(int currentPosition, int bytesNeeded)
public ByteArrayBuilder ensureCapacity(int bytesNeeded)
bytesNeeded
- the number of bytes neededpublic ByteArrayBuilder clear()
public ByteArrayBuilder setAllocationSize(int allocationSize)
allocationSize
- the new allocation sizepublic 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 array;
must be non-negative and no larger than
array.length - offset
public 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;
must be non-negative and no larger than array.length
len
- The number of bytes to be read from the given array;
must be non-negative and no larger than
array.length - offset
public ByteArrayBuilder append(ByteArrayBuilder bab)
public java.lang.String toString()
toString
in class java.lang.Object