- java.lang.Object
-
- de.carne.util.ByteString
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<ByteString>
public final class ByteString extends java.lang.Object implements java.io.Serializable, java.lang.Comparable<ByteString>
Immutable byte string support.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static ByteStringEMPTYThe empty byte string.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description bytebyteAt(int index)Gets the this instance's byte value at the given index.byte[]bytes()Gets a copy of this instance's byte values.intcompareTo(ByteString o)static ByteStringcopy(byte... bytes)Constructs a new ByteString instance by copying the submitted bytes.static ByteStringcopy(byte[] bytes, int start, int length)Constructs a new ByteString instance by copying the submitted bytes.voidcopyTo(byte[] dest, int destPos)Copies this instances bytes to a destination buffer.booleanequals(@Nullable java.lang.Object obj)inthashCode()intlength()Gets the length of this instance.ByteStringslice(int sliceStart, int sliceLength)Slices a sub-section from this instance.java.lang.StringtoString()static ByteStringwrap(byte... bytes)Constructs a new ByteString instance by wrapping the submitted bytes directly.static ByteStringwrap(byte[] bytes, int start, int length)Constructs a new ByteString instance by wrapping the submitted bytes directly.voidwrite(java.io.OutputStream out)Copies this instances bytes to the given OutputStream.
-
-
-
Field Detail
-
EMPTY
public static final ByteString EMPTY
The empty byte string.
-
-
Method Detail
-
wrap
public static ByteString wrap(byte... bytes)
Constructs a new ByteString instance by wrapping the submitted bytes directly.- Parameters:
bytes- the bytes to wrap.- Returns:
- the constructed ByteString instance.
-
wrap
public static ByteString wrap(byte[] bytes, int start, int length)
Constructs a new ByteString instance by wrapping the submitted bytes directly.- Parameters:
bytes- the bytes to wrap.start- the index of the first byte to wrap.length- the number of bytes to wrap.- Returns:
- the constructed ByteString instance.
-
copy
public static ByteString copy(byte... bytes)
Constructs a new ByteString instance by copying the submitted bytes.- Parameters:
bytes- the bytes to copy.- Returns:
- the constructed ByteString instance.
-
copy
public static ByteString copy(byte[] bytes, int start, int length)
Constructs a new ByteString instance by copying the submitted bytes.- Parameters:
bytes- the bytes to copy.start- the index of the first byte to copy.length- the number of bytes to copy.- Returns:
- the constructed ByteString instance.
-
length
public int length()
Gets the length of this instance.- Returns:
- the length of this instance.
-
bytes
public byte[] bytes()
Gets a copy of this instance's byte values.- Returns:
- a copy of this instance's byte values.
-
byteAt
public byte byteAt(int index)
Gets the this instance's byte value at the given index.- Parameters:
index- the index of the byte to get.- Returns:
- the byte value at the given index.
-
copyTo
public void copyTo(byte[] dest, int destPos)Copies this instances bytes to a destination buffer.- Parameters:
dest- the buffer to copy into.destPos- the buffer position to start copying at.
-
write
public void write(java.io.OutputStream out) throws java.io.IOExceptionCopies this instances bytes to the given OutputStream.- Parameters:
out- the OutputStream to write to.- Throws:
java.io.IOException- if an I/O error occurs.
-
slice
public ByteString slice(int sliceStart, int sliceLength)
Slices a sub-section from this instance.- Parameters:
sliceStart- the index of the first byte to slice.sliceLength- the number of bytes to slice.- Returns:
- the sliced byte string.
-
compareTo
public int compareTo(ByteString o)
- Specified by:
compareToin interfacejava.lang.Comparable<ByteString>
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(@Nullable java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-