public final class ImmutableByteSequence
extends java.lang.Object
BIG_ENDIAN order.
Sequences can be created copying from an already existing representation of a
sequence of bytes, such as ByteBuffer or byte[]; or by
copying bytes from a primitive data type, such as long, int
or short. In the first case, bytes are assumed to be already given in
big-endian order, while in the second case big-endianness is enforced by this
class.
| Modifier and Type | Method and Description |
|---|---|
byte[] |
asArray()
Creates a new byte array view of this sequence.
|
java.nio.ByteBuffer |
asReadOnlyBuffer()
Returns a view of this sequence as a read-only
ByteBuffer. |
static ImmutableByteSequence |
copyFrom(byte original)
Creates a new byte sequence of 1 byte containing the given value.
|
static ImmutableByteSequence |
copyFrom(byte[] original)
Creates a new immutable byte sequence with the same content and order of
the passed byte array.
|
static ImmutableByteSequence |
copyFrom(byte[] original,
int fromIdx,
int toIdx)
Creates a new immutable byte sequence with the same content and order of
the passed byte array, from/to the given indexes (inclusive).
|
static ImmutableByteSequence |
copyFrom(java.nio.ByteBuffer original)
Creates a new immutable byte sequence copying bytes from the given
ByteBuffer
ByteBuffer. |
static ImmutableByteSequence |
copyFrom(int original)
Creates a new byte sequence of 4 bytes containing the given int value.
|
static ImmutableByteSequence |
copyFrom(long original)
Creates a new byte sequence of 8 bytes containing the given long value.
|
static ImmutableByteSequence |
copyFrom(short original)
Creates a new byte sequence of 2 bytes containing the given short value.
|
boolean |
equals(java.lang.Object obj) |
int |
hashCode() |
static ImmutableByteSequence |
ofOnes(int size)
Creates a new byte sequence of the given size where alla bits are 1.
|
static ImmutableByteSequence |
ofZeros(int size)
Creates a new byte sequence of the given size where alla bits are 0.
|
int |
size()
Gets the number of bytes in this sequence.
|
java.lang.String |
toString() |
public static ImmutableByteSequence copyFrom(byte[] original)
original - a byte array valuepublic static ImmutableByteSequence copyFrom(byte[] original, int fromIdx, int toIdx)
original - a byte array valuefromIdx - starting indextoIdx - ending indexpublic static ImmutableByteSequence copyFrom(java.nio.ByteBuffer original)
ByteBuffer. If the byte buffer order is not big-endian
bytes will be copied in reverse order.original - a byte bufferpublic static ImmutableByteSequence copyFrom(long original)
original - a long valuepublic static ImmutableByteSequence copyFrom(int original)
original - an int valuepublic static ImmutableByteSequence copyFrom(short original)
original - a short valuepublic static ImmutableByteSequence copyFrom(byte original)
original - a byte valuepublic static ImmutableByteSequence ofZeros(int size)
size - number of bytespublic static ImmutableByteSequence ofOnes(int size)
size - number of bytespublic java.nio.ByteBuffer asReadOnlyBuffer()
ByteBuffer.
The returned buffer will have position 0, while limit and capacity will
be set to this sequence size(). The buffer order will be
big-endian.
public int size()
public byte[] asArray()
public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object