@Mutable @ThreadSafety(level=NOT_THREADSAFE) public final class ByteStringBuffer extends java.lang.Object implements java.io.Serializable, java.lang.Appendable
Constructor and Description |
---|
ByteStringBuffer()
Creates a new empty byte string buffer with a default initial capacity.
|
ByteStringBuffer(int initialCapacity)
Creates a new byte string buffer with the specified capacity.
|
Modifier and Type | Method and Description |
---|---|
ByteStringBuffer |
append(boolean b)
Appends the provided boolean value to this buffer.
|
ByteStringBuffer |
append(byte b)
Appends the provided byte to this buffer.
|
ByteStringBuffer |
append(byte[] b)
Appends the contents of the provided byte array to this buffer.
|
ByteStringBuffer |
append(byte[] b,
int off,
int len)
Appends the specified portion of the provided byte array to this buffer.
|
ByteStringBuffer |
append(ByteString b)
Appends the provided byte string to this buffer.
|
ByteStringBuffer |
append(ByteStringBuffer buffer)
Appends the provided byte string buffer to this buffer.
|
ByteStringBuffer |
append(char c)
Appends the provided character to this buffer.
|
ByteStringBuffer |
append(char[] c)
Appends the contents of the provided character array to this buffer.
|
ByteStringBuffer |
append(char[] c,
int off,
int len)
Appends the specified portion of the provided character array to this
buffer.
|
ByteStringBuffer |
append(java.lang.CharSequence s)
Appends the provided character sequence to this buffer.
|
ByteStringBuffer |
append(java.lang.CharSequence s,
int start,
int end)
Appends the provided character sequence to this buffer.
|
ByteStringBuffer |
append(int i)
Appends the provided integer value to this buffer.
|
ByteStringBuffer |
append(long l)
Appends the provided long value to this buffer.
|
ByteStringBuffer |
appendCodePoint(int codePoint)
Appends the provided code point to this buffer.
|
java.io.InputStream |
asInputStream()
Creates an input stream that may be used to read content from this buffer.
|
byte |
byteAt(int offset)
Retrieves the byte at the specified offset in the buffer.
|
byte[] |
bytesAt(int offset,
int length)
Retrieves the specified subset of bytes from the buffer.
|
int |
capacity()
Returns the current capacity for this buffer.
|
ByteStringBuffer |
clear()
Clears the contents of this buffer.
|
ByteStringBuffer |
clear(boolean zero)
Clears the contents of this buffer.
|
ByteStringBuffer |
delete(int len)
Deletes the specified number of bytes from the beginning of the buffer.
|
ByteStringBuffer |
delete(int off,
int len)
Deletes the indicated number of bytes from the specified location in the
buffer.
|
ByteStringBuffer |
duplicate()
Creates a duplicate of this byte string buffer.
|
boolean |
endsWith(byte[] bytes)
Indicates whether this buffer ends with the specified set of bytes.
|
void |
ensureCapacity(int minimumCapacity)
Ensures that the total capacity of this buffer is at least equal to the
specified size.
|
boolean |
equals(java.lang.Object o)
Indicates whether the provided object is a byte string buffer with contents
that are identical to that of this buffer.
|
byte[] |
getBackingArray()
Retrieves the current backing array for this buffer.
|
int |
hashCode()
Retrieves a hash code for this byte array.
|
ByteStringBuffer |
insert(int pos,
boolean b)
Inserts the provided boolean value to this buffer.
|
ByteStringBuffer |
insert(int pos,
byte b)
Inserts the provided byte at the specified position in this buffer.
|
ByteStringBuffer |
insert(int pos,
byte[] b)
Inserts the contents of the provided byte array at the specified position
in this buffer.
|
ByteStringBuffer |
insert(int pos,
byte[] b,
int off,
int len)
Inserts a portion of the data in the provided array at the specified
position in this buffer.
|
ByteStringBuffer |
insert(int pos,
ByteString b)
Inserts the provided byte string into this buffer at the specified
position.
|
ByteStringBuffer |
insert(int pos,
ByteStringBuffer buffer)
Inserts the provided byte string buffer into this buffer at the specified
position.
|
ByteStringBuffer |
insert(int pos,
char c)
Inserts the provided character into this buffer at the provided position.
|
ByteStringBuffer |
insert(int pos,
char[] c)
Inserts the contents of the provided character array into this buffer at
the specified position.
|
ByteStringBuffer |
insert(int pos,
char[] c,
int off,
int len)
Inserts the specified portion of the provided character array to this
buffer at the specified position.
|
ByteStringBuffer |
insert(int pos,
java.lang.CharSequence s)
Inserts the provided character sequence to this buffer at the specified
position.
|
ByteStringBuffer |
insert(int pos,
int i)
Inserts the provided integer value to this buffer.
|
ByteStringBuffer |
insert(int pos,
long l)
Inserts the provided long value to this buffer.
|
ByteStringBuffer |
insertCodePoint(int pos,
int codePoint)
Inserts the provided code point into this buffer.
|
boolean |
isEmpty()
Indicates whether this buffer is currently empty.
|
int |
length()
Retrieves the number of bytes contained in this buffer.
|
void |
readFrom(java.io.File file)
Reads the contents of the specified file into this buffer, appending it to
the end of the buffer.
|
void |
readFrom(java.io.InputStream inputStream)
Reads data from the provided input stream into this buffer, appending it to
the end of the buffer.
|
ByteStringBuffer |
set(boolean b)
Sets the contents of this buffer to include only the provided boolean
value.
|
ByteStringBuffer |
set(byte b)
Sets the contents of this buffer to include only the provided byte.
|
ByteStringBuffer |
set(byte[] b)
Sets the contents of this buffer to the contents of the provided byte
array.
|
ByteStringBuffer |
set(byte[] b,
int off,
int len)
Sets the contents of this buffer to the specified portion of the provided
byte array.
|
ByteStringBuffer |
set(ByteString b)
Sets the contents of this buffer to the contents of the provided byte
string.
|
ByteStringBuffer |
set(ByteStringBuffer buffer)
Sets the contents of this buffer to the contents of the provided byte
string buffer.
|
ByteStringBuffer |
set(char c)
Sets the contents of this buffer to include only the provided character.
|
ByteStringBuffer |
set(char[] c)
Sets the contents of this buffer to the contents of the provided character
array.
|
ByteStringBuffer |
set(char[] c,
int off,
int len)
Sets the contents of this buffer to the specified portion of the provided
character array.
|
ByteStringBuffer |
set(java.lang.CharSequence s)
Sets the contents of this buffer to the specified portion of the provided
character sequence.
|
ByteStringBuffer |
set(int i)
Sets the contents of this buffer to include only the provided integer
value.
|
ByteStringBuffer |
set(long l)
Sets the contents of this buffer to include only the provided long value.
|
void |
setCapacity(int capacity)
Sets the capacity equal to the specified value.
|
void |
setLength(int length)
Sets the length of this buffer to the specified value.
|
boolean |
startsWith(byte[] bytes)
Indicates whether this buffer starts with the specified set of bytes.
|
byte[] |
toByteArray()
Returns a new byte array with the content from this buffer.
|
ByteString |
toByteString()
Returns a new byte string with the content from this buffer.
|
java.lang.String |
toString()
Retrieves a string representation of the contents for this buffer.
|
ByteStringBuffer |
trimToSize()
Trims the backing array to the minimal size required for this buffer.
|
void |
write(java.io.OutputStream outputStream)
Writes the contents of this byte string buffer to the provided output
stream.
|
public ByteStringBuffer()
public ByteStringBuffer(int initialCapacity)
initialCapacity
- The initial capacity to use for the buffer. It
must be greater than or equal to zero.@NotNull public ByteStringBuffer append(boolean b)
b
- The boolean value to be appended to this buffer.@NotNull public ByteStringBuffer append(byte b)
b
- The byte to be appended to this buffer.@NotNull public ByteStringBuffer append(@NotNull byte[] b) throws java.lang.NullPointerException
b
- The array whose contents should be appended to this buffer. It
must not be null
.java.lang.NullPointerException
- If the provided array is null
.@NotNull public ByteStringBuffer append(@NotNull byte[] b, int off, int len) throws java.lang.NullPointerException, java.lang.IndexOutOfBoundsException
b
- The array whose contents should be appended to this buffer.off
- The offset within the array at which to begin copying data.len
- The number of bytes to copy.java.lang.NullPointerException
- If the provided array is null
.java.lang.IndexOutOfBoundsException
- If the offset or length are negative,
if the offset plus the length is beyond
the end of the provided array.@NotNull public ByteStringBuffer append(@NotNull ByteString b) throws java.lang.NullPointerException
b
- The byte string to be appended to this buffer.java.lang.NullPointerException
- If the provided byte string is null
.@NotNull public ByteStringBuffer append(@NotNull ByteStringBuffer buffer) throws java.lang.NullPointerException
buffer
- The buffer whose contents should be appended to this
buffer.java.lang.NullPointerException
- If the provided buffer is null
.@NotNull public ByteStringBuffer append(char c)
append
in interface java.lang.Appendable
c
- The character to be appended to this buffer.@NotNull public ByteStringBuffer append(@NotNull char[] c) throws java.lang.NullPointerException
c
- The array whose contents should be appended to this buffer.java.lang.NullPointerException
- If the provided array is null
.@NotNull public ByteStringBuffer append(@NotNull char[] c, int off, int len) throws java.lang.NullPointerException, java.lang.IndexOutOfBoundsException
c
- The array whose contents should be appended to this buffer.off
- The offset within the array at which to begin copying data.len
- The number of characters to copy.java.lang.NullPointerException
- If the provided array is null
.java.lang.IndexOutOfBoundsException
- If the offset or length are negative,
if the offset plus the length is beyond
the end of the provided array.@NotNull public ByteStringBuffer append(@NotNull java.lang.CharSequence s) throws java.lang.NullPointerException
append
in interface java.lang.Appendable
s
- The character sequence to append to this buffer.java.lang.NullPointerException
- If the provided character sequence is
null
.@NotNull public ByteStringBuffer append(@NotNull java.lang.CharSequence s, int start, int end) throws java.lang.NullPointerException, java.lang.IndexOutOfBoundsException
append
in interface java.lang.Appendable
s
- The character sequence to append to this buffer.start
- The position in the sequence of the first character in the
sequence to be appended to this buffer.end
- The position in the sequence immediately after the position
of the last character to be appended.java.lang.NullPointerException
- If the provided character sequence is
null
.java.lang.IndexOutOfBoundsException
- If the provided start or end positions
are outside the bounds of the given
character sequence.@NotNull public ByteStringBuffer append(int i)
i
- The integer value to be appended to this buffer.@NotNull public ByteStringBuffer append(long l)
l
- The long value to be appended to this buffer.@NotNull public ByteStringBuffer appendCodePoint(int codePoint)
codePoint
- The code point to append to this buffer.@NotNull public ByteStringBuffer insert(int pos, boolean b) throws java.lang.IndexOutOfBoundsException
pos
- The position at which the value is to be inserted.b
- The boolean value to be inserted into this buffer.java.lang.IndexOutOfBoundsException
- If the specified position is negative
or greater than the current length.@NotNull public ByteStringBuffer insert(int pos, byte b) throws java.lang.IndexOutOfBoundsException
pos
- The position at which the byte is to be inserted.b
- The byte to be inserted into this buffer.java.lang.IndexOutOfBoundsException
- If the specified position is negative
or greater than the current length.@NotNull public ByteStringBuffer insert(int pos, @NotNull byte[] b) throws java.lang.NullPointerException, java.lang.IndexOutOfBoundsException
pos
- The position at which the data is to be inserted.b
- The array whose contents should be inserted into this buffer.java.lang.NullPointerException
- If the provided array is null
.java.lang.IndexOutOfBoundsException
- If the specified position is negative
or greater than the current length.@NotNull public ByteStringBuffer insert(int pos, @NotNull byte[] b, int off, int len) throws java.lang.NullPointerException, java.lang.IndexOutOfBoundsException
pos
- The position at which the data is to be inserted.b
- The array whose contents should be inserted into this buffer.off
- The offset within the array at which to begin copying data.len
- The number of bytes to copy.java.lang.NullPointerException
- If the provided array is null
.java.lang.IndexOutOfBoundsException
- If the specified position is negative
or greater than the current length, if
the offset or length are negative, if
the offset plus the length is beyond
the end of the provided array.@NotNull public ByteStringBuffer insert(int pos, @NotNull ByteString b) throws java.lang.NullPointerException, java.lang.IndexOutOfBoundsException
pos
- The position at which the data is to be inserted.b
- The byte string to insert into this buffer.java.lang.NullPointerException
- If the provided byte string is null
.java.lang.IndexOutOfBoundsException
- If the specified position is negative
or greater than the current length.@NotNull public ByteStringBuffer insert(int pos, @NotNull ByteStringBuffer buffer) throws java.lang.NullPointerException, java.lang.IndexOutOfBoundsException
pos
- The position at which the data is to be inserted.buffer
- The buffer whose contents should be inserted into this
buffer.java.lang.NullPointerException
- If the provided buffer is null
.java.lang.IndexOutOfBoundsException
- If the specified position is negative
or greater than the current length.@NotNull public ByteStringBuffer insert(int pos, char c) throws java.lang.IndexOutOfBoundsException
pos
- The position at which the character is to be inserted.c
- The character to be inserted into this buffer.java.lang.IndexOutOfBoundsException
- If the specified position is negative
or greater than the current length.@NotNull public ByteStringBuffer insert(int pos, @NotNull char[] c) throws java.lang.NullPointerException, java.lang.IndexOutOfBoundsException
pos
- The position at which the data is to be inserted.c
- The array whose contents should be inserted into this buffer.java.lang.NullPointerException
- If the provided array is null
.java.lang.IndexOutOfBoundsException
- If the specified position is negative
or greater than the current length.@NotNull public ByteStringBuffer insert(int pos, @NotNull char[] c, int off, int len) throws java.lang.NullPointerException, java.lang.IndexOutOfBoundsException
pos
- The position at which the data is to be inserted.c
- The array whose contents should be inserted into this buffer.off
- The offset within the array at which to begin copying data.len
- The number of characters to copy.java.lang.NullPointerException
- If the provided array is null
.java.lang.IndexOutOfBoundsException
- If the specified position is negative
or greater than the current length, if
the offset or length are negative, if
the offset plus the length is beyond
the end of the provided array.@NotNull public ByteStringBuffer insert(int pos, @NotNull java.lang.CharSequence s) throws java.lang.NullPointerException, java.lang.IndexOutOfBoundsException
pos
- The position at which the data is to be inserted.s
- The character sequence to insert into this buffer.java.lang.NullPointerException
- If the provided character sequence is
null
.java.lang.IndexOutOfBoundsException
- If the specified position is negative
or greater than the current length.@NotNull public ByteStringBuffer insert(int pos, int i) throws java.lang.IndexOutOfBoundsException
pos
- The position at which the value is to be inserted.i
- The integer value to be inserted into this buffer.java.lang.IndexOutOfBoundsException
- If the specified position is negative
or greater than the current length.@NotNull public ByteStringBuffer insert(int pos, long l) throws java.lang.IndexOutOfBoundsException
pos
- The position at which the value is to be inserted.l
- The long value to be inserted into this buffer.java.lang.IndexOutOfBoundsException
- If the specified position is negative
or greater than the current length.@NotNull public ByteStringBuffer insertCodePoint(int pos, int codePoint) throws java.lang.IndexOutOfBoundsException
pos
- The position at which the code point is to be inserted.codePoint
- The code point to be inserted.java.lang.IndexOutOfBoundsException
- If the specified position is negative
or greater than the current length.@NotNull public ByteStringBuffer delete(int len) throws java.lang.IndexOutOfBoundsException
len
- The number of bytes to delete.java.lang.IndexOutOfBoundsException
- If the specified length is negative,
or if it is greater than the number of
bytes currently contained in this
buffer.@NotNull public ByteStringBuffer delete(int off, int len) throws java.lang.IndexOutOfBoundsException
off
- The position in the buffer at which the content to delete
begins.len
- The number of bytes to remove from the buffer.java.lang.IndexOutOfBoundsException
- If the offset or length is negative, or
if the combination of the offset and
length is greater than the end of the
content in the buffer.@NotNull public ByteStringBuffer set(boolean b)
b
- The boolean value to use as the content for this buffer.@NotNull public ByteStringBuffer set(byte b)
b
- The byte to use as the content for this buffer.@NotNull public ByteStringBuffer set(@NotNull byte[] b) throws java.lang.NullPointerException
b
- The byte array containing the content to use for this buffer.java.lang.NullPointerException
- If the provided array is null
.@NotNull public ByteStringBuffer set(@NotNull byte[] b, int off, int len) throws java.lang.NullPointerException, java.lang.IndexOutOfBoundsException
b
- The byte array containing the content to use for this buffer.off
- The offset within the array at which to begin copying data.len
- The number of bytes to copy.java.lang.NullPointerException
- If the provided array is null
.java.lang.IndexOutOfBoundsException
- If the offset or length are negative,
if the offset plus the length is beyond
the end of the provided array.@NotNull public ByteStringBuffer set(@NotNull ByteString b) throws java.lang.NullPointerException
b
- The byte string that should be used as the content for this
buffer.java.lang.NullPointerException
- If the provided byte string is null
.@NotNull public ByteStringBuffer set(@NotNull ByteStringBuffer buffer) throws java.lang.NullPointerException
buffer
- The buffer whose contents should be used as the content for
this buffer.java.lang.NullPointerException
- If the provided buffer is null
.@NotNull public ByteStringBuffer set(char c)
c
- The character use as the content for this buffer.@NotNull public ByteStringBuffer set(@NotNull char[] c) throws java.lang.NullPointerException
c
- The character array containing the content to use for this
buffer.java.lang.NullPointerException
- If the provided array is null
.@NotNull public ByteStringBuffer set(@NotNull char[] c, int off, int len) throws java.lang.NullPointerException, java.lang.IndexOutOfBoundsException
c
- The character array containing the content to use for this
buffer.off
- The offset within the array at which to begin copying data.len
- The number of characters to copy.java.lang.NullPointerException
- If the provided array is null
.java.lang.IndexOutOfBoundsException
- If the offset or length are negative,
if the offset plus the length is beyond
the end of the provided array.@NotNull public ByteStringBuffer set(@NotNull java.lang.CharSequence s) throws java.lang.NullPointerException
s
- The character sequence to use as the content for this buffer.java.lang.NullPointerException
- If the provided character sequence is
null
.@NotNull public ByteStringBuffer set(int i)
i
- The integer value to use as the content for this buffer.@NotNull public ByteStringBuffer set(long l)
l
- The long value to use as the content for this buffer.@NotNull public ByteStringBuffer clear()
@NotNull public ByteStringBuffer clear(boolean zero)
zero
- Indicates whether to overwrite the content of the backing
array with all zeros in order to wipe out any sensitive data
it may contain.@NotNull public byte[] getBackingArray()
length()
bytes.public boolean isEmpty()
true
if this buffer is currently empty, or false
if not.public int length()
public void setLength(int length) throws java.lang.IndexOutOfBoundsException
length
- The new length to use for the buffer. It must be greater
than or equal to zero.java.lang.IndexOutOfBoundsException
- If the provided length is negative.public int capacity()
public void ensureCapacity(int minimumCapacity)
minimumCapacity
- The minimum capacity for this buffer.public void setCapacity(int capacity) throws java.lang.IndexOutOfBoundsException
capacity
- The new capacity for this buffer. It must be greater
than or equal to zero.java.lang.IndexOutOfBoundsException
- If the provided capacity is negative.@NotNull public ByteStringBuffer trimToSize()
public byte byteAt(int offset) throws java.lang.IndexOutOfBoundsException
offset
- The offset of the byte to read. It must be between greater
than or equal to zero and less than length()
.java.lang.IndexOutOfBoundsException
- If the provided offset is negative or
greater than or equal to the length of
the buffer.@NotNull public byte[] bytesAt(int offset, int length) throws java.lang.IndexOutOfBoundsException
offset
- The offset of the first byte to retrieve. It must be
greater than or equal to zero and less than
length()
.length
- The number of bytes to retrieve. It must be greater than
or equal to zero, and the sum of offset
and
length
must be less than or equal to
length()
.java.lang.IndexOutOfBoundsException
- If either the offset or the length is
negative, or if the offsset plus the
length is greater than or equal to the
length of the buffer.public boolean startsWith(@NotNull byte[] bytes)
bytes
- The bytes for which to make the determination.true
if this buffer starts with the specified set of
bytes, or false
if not.public boolean endsWith(@NotNull byte[] bytes)
bytes
- The bytes for which to make the determination.true
if this buffer ends with the specified set of bytes,
or false
if not.@NotNull public byte[] toByteArray()
@NotNull public ByteString toByteString()
@NotNull public java.io.InputStream asInputStream()
public void readFrom(@NotNull java.io.File file) throws java.io.IOException
file
- The file to be read.java.io.IOException
- If an unexpected problem occurs.public void readFrom(@NotNull java.io.InputStream inputStream) throws java.io.IOException
inputStream
- The input stream from which data is to be read.java.io.IOException
- If an unexpected problem occurs.public void write(@NotNull java.io.OutputStream outputStream) throws java.io.IOException
outputStream
- The output stream to which the data should be
written.java.io.IOException
- If a problem occurs while writing to the provided
output stream.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(@Nullable java.lang.Object o)
equals
in class java.lang.Object
o
- The object for which to make the determination.true
if the provided object is considered equal to this
buffer, or false
if not.@NotNull public ByteStringBuffer duplicate()