Package org.apache.accumulo.core.data
Class ArrayByteSequence
java.lang.Object
org.apache.accumulo.core.data.ByteSequence
org.apache.accumulo.core.data.ArrayByteSequence
- All Implemented Interfaces:
Serializable
,Comparable<ByteSequence>
An implementation of
ByteSequence
that uses a backing byte array.- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionArrayByteSequence
(byte[] data) Creates a new sequence.ArrayByteSequence
(byte[] data, int offset, int length) Creates a new sequence from a subsequence of the given byte array.Creates a new sequence from the given string.ArrayByteSequence
(ByteBuffer buffer) Creates a new sequence based on a byte buffer. -
Method Summary
Modifier and TypeMethodDescriptionbyte
byteAt
(int i) Gets a byte within this sequence.byte[]
Gets the backing byte array for this sequence.boolean
Determines whether this sequence is backed by a byte array.int
length()
Gets the length of this sequence.int
offset()
Gets the offset for this sequence.subSequence
(int start, int end) Returns a portion of this sequence.byte[]
toArray()
Returns a byte array containing the bytes in this sequence.toString()
Methods inherited from class org.apache.accumulo.core.data.ByteSequence
compareBytes, compareTo, equals, hashCode
-
Field Details
-
data
protected byte[] data -
offset
protected int offset -
length
protected int length
-
-
Constructor Details
-
ArrayByteSequence
public ArrayByteSequence(byte[] data) Creates a new sequence. The given byte array is used directly as the backing array, so later changes made to the array reflect into the new sequence.- Parameters:
data
- byte data
-
ArrayByteSequence
public ArrayByteSequence(byte[] data, int offset, int length) Creates a new sequence from a subsequence of the given byte array. The given byte array is used directly as the backing array, so later changes made to the (relevant portion of the) array reflect into the new sequence.- Parameters:
data
- byte dataoffset
- starting offset in byte array (inclusive)length
- number of bytes to include in sequence- Throws:
IllegalArgumentException
- if the offset or length are out of bounds for the given byte array
-
ArrayByteSequence
Creates a new sequence from the given string. The bytes are determined from the string using the default platform encoding.- Parameters:
s
- string to represent as bytes
-
ArrayByteSequence
Creates a new sequence based on a byte buffer. If the byte buffer has an array, that array (and the buffer's offset and limit) are used; otherwise, a new backing array is created and a relative bulk get is performed to transfer the buffer's contents (starting at its current position and not beyond its limit).- Parameters:
buffer
- byte buffer
-
-
Method Details
-
byteAt
public byte byteAt(int i) Description copied from class:ByteSequence
Gets a byte within this sequence.- Specified by:
byteAt
in classByteSequence
- Parameters:
i
- index into sequence- Returns:
- byte
-
getBackingArray
public byte[] getBackingArray()Description copied from class:ByteSequence
Gets the backing byte array for this sequence.- Specified by:
getBackingArray
in classByteSequence
- Returns:
- byte array
-
isBackedByArray
public boolean isBackedByArray()Description copied from class:ByteSequence
Determines whether this sequence is backed by a byte array.- Specified by:
isBackedByArray
in classByteSequence
- Returns:
- true if sequence is backed by a byte array
-
length
public int length()Description copied from class:ByteSequence
Gets the length of this sequence.- Specified by:
length
in classByteSequence
- Returns:
- sequence length
-
offset
public int offset()Description copied from class:ByteSequence
Gets the offset for this sequence. This value represents the starting point for the sequence in the backing array, if there is one.- Specified by:
offset
in classByteSequence
- Returns:
- offset (inclusive)
-
subSequence
Description copied from class:ByteSequence
Returns a portion of this sequence.- Specified by:
subSequence
in classByteSequence
- Parameters:
start
- index of subsequence start (inclusive)end
- index of subsequence end (exclusive)
-
toArray
public byte[] toArray()Description copied from class:ByteSequence
Returns a byte array containing the bytes in this sequence. This method may copy the sequence data or may return a backing byte array directly.- Specified by:
toArray
in classByteSequence
- Returns:
- byte array
-
toString
-