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>
- Direct Known Subclasses:
MutableByteSequence
public class ArrayByteSequence extends ByteSequence implements Serializable
An implementation ofByteSequencethat uses a backing byte array.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ArrayByteSequence(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.ArrayByteSequence(String s)Creates a new sequence from the given string.ArrayByteSequence(ByteBuffer buffer)Creates a new sequence based on a byte buffer.ArrayByteSequence(ByteSequence byteSequence)Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description bytebyteAt(int i)Gets a byte within this sequence.byte[]getBackingArray()Gets the backing byte array for this sequence.booleanisBackedByArray()Determines whether this sequence is backed by a byte array.intlength()Gets the length of this sequence.intoffset()Gets the offset for this sequence.ByteSequencesubSequence(int start, int end)Returns a portion of this sequence.byte[]toArray()Returns a byte array containing the bytes in this sequence.StringtoString()-
Methods inherited from class org.apache.accumulo.core.data.ByteSequence
compareBytes, compareTo, equals, hashCode
-
-
-
-
Constructor Detail
-
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
public ArrayByteSequence(String s)
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
public ArrayByteSequence(ByteBuffer buffer)
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
-
ArrayByteSequence
public ArrayByteSequence(ByteSequence byteSequence)
Copy constructor. Copies contents of byteSequence.- Since:
- 2.0.0
-
-
Method Detail
-
byteAt
public byte byteAt(int i)
Description copied from class:ByteSequenceGets a byte within this sequence.- Specified by:
byteAtin classByteSequence- Parameters:
i- index into sequence- Returns:
- byte
-
getBackingArray
public byte[] getBackingArray()
Description copied from class:ByteSequenceGets the backing byte array for this sequence.- Specified by:
getBackingArrayin classByteSequence- Returns:
- byte array
-
isBackedByArray
public boolean isBackedByArray()
Description copied from class:ByteSequenceDetermines whether this sequence is backed by a byte array.- Specified by:
isBackedByArrayin classByteSequence- Returns:
- true if sequence is backed by a byte array
-
length
public int length()
Description copied from class:ByteSequenceGets the length of this sequence.- Specified by:
lengthin classByteSequence- Returns:
- sequence length
-
offset
public int offset()
Description copied from class:ByteSequenceGets the offset for this sequence. This value represents the starting point for the sequence in the backing array, if there is one.- Specified by:
offsetin classByteSequence- Returns:
- offset (inclusive)
-
subSequence
public ByteSequence subSequence(int start, int end)
Description copied from class:ByteSequenceReturns a portion of this sequence.- Specified by:
subSequencein classByteSequence- Parameters:
start- index of subsequence start (inclusive)end- index of subsequence end (exclusive)
-
toArray
public byte[] toArray()
Description copied from class:ByteSequenceReturns 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:
toArrayin classByteSequence- Returns:
- byte array
-
-