public class ByteString extends Object
array(). Care must be taken when directly accessing the memory as that may invalidate assumptions that
this object is immutable.| Modifier and Type | Class and Description |
|---|---|
protected static interface |
ByteString.ByteStringFactory
Allows sub classes to take advantage of
ByteString operations which need to generate new
ByteString objects. |
| Modifier and Type | Field and Description |
|---|---|
static ByteString |
EMPTY_STRING |
protected static int |
HASH_CODE_PRIME |
protected byte[] |
value
If this value is modified outside the constructor then call
arrayChanged(). |
| Constructor and Description |
|---|
ByteString(byte[] value)
Initialize this byte string based upon a byte array.
|
ByteString(byte[] value,
boolean copy)
Initialize this byte string based upon a byte array.
|
ByteString(byte[] value,
int start,
int length,
boolean copy)
Construct a new
BinaryString object from a byte[] array. |
ByteString(ByteBuffer value)
Create a copy of the underlying storage from
value. |
ByteString(ByteBuffer value,
boolean copy)
Initialize a
ByteString based upon the underlying storage from value. |
ByteString(ByteBuffer value,
int start,
int length,
boolean copy)
Initialize a
ByteString based upon the underlying storage from value. |
ByteString(ByteString value,
boolean copy)
Create a new object which is equal to
value. |
ByteString(char[] value,
Charset charset)
|
ByteString(char[] value,
Charset charset,
int start,
int length)
|
ByteString(CharSequence value,
Charset charset)
|
ByteString(CharSequence value,
Charset charset,
int start,
int length)
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
array()
This gives direct access to the underlying storage array.
|
void |
arrayChanged()
During normal use cases the
ByteString should be immutable, but if the underlying array is shared,
and changes then this needs to be called. |
int |
arrayOffset()
The offset into
array() for which data for this ByteString begins. |
byte |
byteAt(int index) |
void |
copy(int srcIdx,
byte[] dst,
int dstIdx,
int length)
Copies the content of this string to a byte array.
|
boolean |
equals(Object obj) |
int |
forEachByte(ByteProcessor visitor)
Iterates over the readable bytes of this buffer with the specified
processor in ascending order. |
int |
forEachByte(int index,
int length,
ByteProcessor visitor)
Iterates over the specified area of this buffer with the specified
processor in ascending order. |
int |
forEachByteDesc(ByteProcessor visitor)
Iterates over the readable bytes of this buffer with the specified
processor in descending order. |
int |
forEachByteDesc(int index,
int length,
ByteProcessor visitor)
Iterates over the specified area of this buffer with the specified
processor in descending order. |
static ByteString |
fromAscii(CharSequence value)
Create a new
ByteString assuming ASCII encoding of value. |
int |
hashCode() |
boolean |
isEmpty() |
boolean |
isEntireArrayUsed()
Determine if the storage represented by
array() is entirely used. |
int |
length() |
double |
parseAsciiDouble() |
double |
parseAsciiDouble(int start,
int end) |
float |
parseAsciiFloat() |
float |
parseAsciiFloat(int start,
int end) |
int |
parseAsciiInt() |
int |
parseAsciiInt(int radix) |
int |
parseAsciiInt(int start,
int end) |
int |
parseAsciiInt(int start,
int end,
int radix) |
long |
parseAsciiLong() |
long |
parseAsciiLong(int radix) |
long |
parseAsciiLong(int start,
int end) |
long |
parseAsciiLong(int start,
int end,
int radix) |
short |
parseAsciiShort() |
short |
parseAsciiShort(int radix) |
short |
parseAsciiShort(int start,
int end) |
short |
parseAsciiShort(int start,
int end,
int radix) |
char |
parseChar() |
char |
parseChar(int start) |
ByteString |
subSequence(int start)
Copies a range of characters into a new string.
|
ByteString |
subSequence(int start,
int end)
Copies a range of characters into a new string.
|
ByteString |
subSequence(int start,
int end,
boolean copy)
Either copy or share a subset of underlying sub-sequence of bytes.
|
protected ByteString |
subSequence(int start,
int end,
boolean copy,
ByteString.ByteStringFactory factory)
Either copy or share a subset of underlying sub-sequence of bytes.
|
byte[] |
toByteArray()
Converts this string to a byte array.
|
byte[] |
toByteArray(int start,
int end)
Converts a subset of this string to a byte array.
|
String |
toString()
Translates the entire byte string to a
String. |
String |
toString(Charset charset)
Translates the entire byte string to a
String using the charset encoding. |
String |
toString(Charset charset,
int start,
int end)
|
String |
toString(int start,
int end)
|
public static final ByteString EMPTY_STRING
protected static final int HASH_CODE_PRIME
protected final byte[] value
arrayChanged().public ByteString(byte[] value)
public ByteString(byte[] value,
boolean copy)
copy determines if a copy is made or the array is shared.public ByteString(byte[] value,
int start,
int length,
boolean copy)
BinaryString object from a byte[] array.copy - true then a copy of the memory will be made. false the underlying memory
will be shared.public ByteString(ByteString value, boolean copy)
value.value - The object to replicate.copy - true mean the underlying storage will be copied.
false means the underlying storage will be shared.public ByteString(ByteBuffer value)
value.
The copy will start at Buffer.position() and copy Buffer.remaining() bytes.public ByteString(ByteBuffer value, boolean copy)
ByteString based upon the underlying storage from value.
There is a potential to share the underlying array storage if ByteBuffer.hasArray() is true.
if copy is true a copy will be made of the memory.
if copy is false the underlying storage will be shared, if possible.public ByteString(ByteBuffer value, int start, int length, boolean copy)
ByteString based upon the underlying storage from value.
There is a potential to share the underlying array storage if ByteBuffer.hasArray() is true.
if copy is true a copy will be made of the memory.
if copy is false the underlying storage will be shared, if possible.public ByteString(char[] value,
Charset charset)
public ByteString(char[] value,
Charset charset,
int start,
int length)
value into a ByteString using the encoding type of charset.
The copy will start at index start and copy length bytes.public ByteString(CharSequence value, Charset charset)
public ByteString(CharSequence value, Charset charset, int start, int length)
value into a ByteString using the encoding type of charset.
The copy will start at index start and copy length bytes.public static final ByteString fromAscii(CharSequence value)
ByteString assuming ASCII encoding of value.value - value to translate assuming ASCII encoding.public final int forEachByte(ByteProcessor visitor) throws Exception
processor in ascending order.-1 if the processor iterated to or beyond the end of the readable bytes.
The last-visited index If the ByteProcessor.process(byte) returned false.Exceptionpublic final int forEachByte(int index,
int length,
ByteProcessor visitor)
throws Exception
processor in ascending order.
(i.e. index, (index + 1), .. (index + length - 1)).-1 if the processor iterated to or beyond the end of the specified area.
The last-visited index If the ByteProcessor.process(byte) returned false.Exceptionpublic final int forEachByteDesc(ByteProcessor visitor) throws Exception
processor in descending order.-1 if the processor iterated to or beyond the beginning of the readable bytes.
The last-visited index If the ByteProcessor.process(byte) returned false.Exceptionpublic final int forEachByteDesc(int index,
int length,
ByteProcessor visitor)
throws Exception
processor in descending order.
(i.e. (index + length - 1), (index + length - 2), ... index).-1 if the processor iterated to or beyond the beginning of the specified area.
The last-visited index If the ByteProcessor.process(byte) returned false.Exceptionpublic final byte byteAt(int index)
public final boolean isEmpty()
public final int length()
public void arrayChanged()
ByteString should be immutable, but if the underlying array is shared,
and changes then this needs to be called.public final byte[] array()
toByteArray() should be preferred over this method.
If the return value is changed then arrayChanged() must be called.arrayOffset(),
isEntireArrayUsed()public final int arrayOffset()
array() for which data for this ByteString begins.array(),
isEntireArrayUsed()public final boolean isEntireArrayUsed()
array() is entirely used.array()public final byte[] toByteArray()
public final byte[] toByteArray(int start,
int end)
start, end).public final void copy(int srcIdx,
byte[] dst,
int dstIdx,
int length)
srcIdx - the starting offset of characters to copy.dst - the destination byte array.dstIdx - the starting offset in the destination byte array.length - the number of characters to copy.public ByteString subSequence(int start)
start - the offset of the first character (inclusive).IndexOutOfBoundsException - if start < 0 or start > length().public ByteString subSequence(int start, int end)
start - the offset of the first character (inclusive).end - The index to stop at (exclusive).IndexOutOfBoundsException - if start < 0 or start > length().public ByteString subSequence(int start, int end, boolean copy)
start - the offset of the first character (inclusive).end - The index to stop at (exclusive).copy - If true then a copy of the underlying storage will be made.
If false then the underlying storage will be shared.IndexOutOfBoundsException - if start < 0 or start > length().protected ByteString subSequence(int start, int end, boolean copy, ByteString.ByteStringFactory factory)
start - the offset of the first character (inclusive).end - The index to stop at (exclusive).copy - If true then a copy of the underlying storage will be made.
If false then the underlying storage will be shared.factory - The factory used to generate a new ByteString object.IndexOutOfBoundsException - if start < 0 or start > length().public final int parseAsciiInt()
public final int parseAsciiInt(int radix)
public final int parseAsciiInt(int start,
int end)
public final int parseAsciiInt(int start,
int end,
int radix)
public final long parseAsciiLong()
public final long parseAsciiLong(int radix)
public final long parseAsciiLong(int start,
int end)
public final long parseAsciiLong(int start,
int end,
int radix)
public final char parseChar()
public char parseChar(int start)
public final short parseAsciiShort()
public final short parseAsciiShort(int radix)
public final short parseAsciiShort(int start,
int end)
public final short parseAsciiShort(int start,
int end,
int radix)
public final float parseAsciiFloat()
public final float parseAsciiFloat(int start,
int end)
public final double parseAsciiDouble()
public final double parseAsciiDouble(int start,
int end)
public final String toString(Charset charset)
String using the charset encoding.#toString(Charset, int, int)}public final String toString(int start, int end)
#toString(Charset, int, int)}Copyright © 2008–2015 The Netty Project. All rights reserved.