Package org.apache.cassandra.db.marshal
Class ByteArrayAccessor
- java.lang.Object
-
- org.apache.cassandra.db.marshal.ByteArrayAccessor
-
- All Implemented Interfaces:
ValueAccessor<byte[]>
public class ByteArrayAccessor extends java.lang.Object implements ValueAccessor<byte[]>
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.cassandra.db.marshal.ValueAccessor
ValueAccessor.ObjectFactory<V>
-
-
Field Summary
Fields Modifier and Type Field Description static ValueAccessor.ObjectFactory<byte[]>
factory
static ValueAccessor<byte[]>
instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
allocate(int size)
Allocate and return a {@param} instance of {@param size} bytes on the heap. <V2> int
compare(byte[] left, V2 right, ValueAccessor<V2> accessorR)
lexicographically compare {@param left} to {@param right}int
compareByteArrayTo(byte[] left, byte[] right)
compare a byte array on the left with a {@param} on the right} int
compareByteBufferTo(java.nio.ByteBuffer left, byte[] right)
compare a byte buffer on the left with a {@param} on the right} <V2> byte[]
convert(V2 src, ValueAccessor<V2> accessor)
Convert the data in {@param src} to {@param} {@param src} and the returned value may share a common byte array instance, so caller should assume that modifying the returned value will also modify the contents of {@param src} int
copyByteArrayTo(byte[] src, int srcOffset, byte[] dst, int dstOffset, int size)
copies a byte array into this accessors value.int
copyByteBufferTo(java.nio.ByteBuffer src, int srcOffset, byte[] dst, int dstOffset, int size)
copies a byte buffer into this accessors value.<V2> int
copyTo(byte[] src, int srcOffset, V2 dst, ValueAccessor<V2> dstAccessor, int dstOffset, int size)
copy the {@param size} bytes from the {@param src} value, starting at the offset {@param srcOffset} into the {@param dst} value, starting at the offset {@param dstOffset}, using the accessor {@param dstAccessor}byte[][]
createArray(int length)
allocate an instance of the accessors backing typevoid
digest(byte[] value, int offset, int size, Digest digest)
updates {@param digest} with {@param size} bytes from the contents of {@param value} starting at offset {@param offset}byte[]
empty()
return a value with a length of 0ValueAccessor.ObjectFactory<byte[]>
factory()
returns theValueAccessor.ObjectFactory
for the backing type {@param} byte
getByte(byte[] value, int offset)
returns a byte from offset {@param offset}double
getDouble(byte[] value, int offset)
float
getFloat(byte[] value, int offset)
int
getInt(byte[] value, int offset)
returns an int from offset {@param offset}long
getLong(byte[] value, int offset)
returns a long from offset {@param offset}short
getShort(byte[] value, int offset)
returns a short from offset {@param offset}int
getUnsignedShort(byte[] value, int offset)
returns an unsigned short from offset {@param offset}int
putByte(byte[] dst, int offset, byte value)
writes the byte value {@param value} to {@param dst} at offset {@param offset}int
putFloat(byte[] dst, int offset, float value)
writes the float value {@param value} to {@param dst} at offset {@param offset}int
putInt(byte[] dst, int offset, int value)
writes the int value {@param value} to {@param dst} at offset {@param offset}int
putLong(byte[] dst, int offset, long value)
writes the long value {@param value} to {@param dst} at offset {@param offset}int
putShort(byte[] dst, int offset, short value)
writes the short value {@param value} to {@param dst} at offset {@param offset}byte[]
read(DataInputPlus in, int length)
Reads a value of {@param length} bytes from {@param in}int
size(byte[] value)
byte[]
slice(byte[] input, int offset, int length)
Returns a value with the contents of {@param input} from {@param offset} to {@param length}.byte[]
toArray(byte[] value)
returns a byte[] with the contents of {@param value} Depending on the accessor implementation, this method may: * allocate a new byte[] object and copy data into it * return the value, if the backing type is byte[]byte[]
toArray(byte[] value, int offset, int length)
returns a byte[] with {@param length} bytes copied from the contents of {@param value} starting at offset {@param offset}.Ballot
toBallot(byte[] value)
returns a TimeUUID from offset 0java.nio.ByteBuffer
toBuffer(byte[] value)
returns a ByteBuffer with the contents of {@param value} Depending on the accessor implementation, this method may: * allocate a new ByteBuffer and copy data into it * return the value, if the backing type is a bytebufferbyte
toByte(byte[] value)
returns a byte from offset 0double
toDouble(byte[] value)
returns a double from offset 0float
toFloat(byte[] value)
returns a float from offset 0float[]
toFloatArray(byte[] value, int dimension)
returns a float[] from offset 0java.lang.String
toHex(byte[] value)
int
toInt(byte[] value)
returns an int from offset 0long
toLong(byte[] value)
returns a long from offset 0short
toShort(byte[] value)
returns a short from offset 0java.lang.String
toString(byte[] value, java.nio.charset.Charset charset)
TimeUUID
toTimeUUID(byte[] value)
returns a TimeUUID from offset 0java.util.UUID
toUUID(byte[] value)
returns a UUID from offset 0byte[]
valueOf(boolean v)
return a value with the bytes from {@param v}byte[]
valueOf(byte v)
return a value with the bytes from {@param v}byte[]
valueOf(byte[] bytes)
return a value containing the {@param bytes} Caller should assume that modifying the returned value will also modify the contents of {@param bytes}byte[]
valueOf(double v)
return a value with the bytes from {@param v}byte[]
valueOf(float v)
return a value with the bytes from {@param v}byte[]
valueOf(int v)
return a value with the bytes from {@param v}byte[]
valueOf(long v)
return a value with the bytes from {@param v}byte[]
valueOf(short v)
return a value with the bytes from {@param v}byte[]
valueOf(java.lang.String s, java.nio.charset.Charset charset)
return a value containing the bytes for the given string and charsetbyte[]
valueOf(java.nio.ByteBuffer bytes)
return a value containing the {@param bytes} {@param src} and the returned value may share a common byte array instance, so caller should assume that modifying the returned value will also modify the contents of {@param src}byte[]
valueOf(java.util.UUID v)
return a value with the bytes from {@param v}void
write(byte[] value, java.nio.ByteBuffer out)
Write the contents of the given value into the ByteBuffervoid
write(byte[] value, DataOutputPlus out)
Write the contents of the given value into the a DataOutputPlus-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.db.marshal.ValueAccessor
digest, getBoolean, getUnsignedVInt, getUnsignedVInt32, getVInt, getVInt32, hashCode, isEmpty, isEmptyFromOffset, putBytes, putBytes, putUnsignedVInt, putUnsignedVInt32, putVInt, putVInt32, remaining, sizeFromOffset, sizeWithShortLength, sizeWithVIntLength, sliceWithShortLength, toString, writeWithVIntLength
-
-
-
-
Field Detail
-
instance
public static final ValueAccessor<byte[]> instance
-
factory
public static final ValueAccessor.ObjectFactory<byte[]> factory
-
-
Method Detail
-
size
public int size(byte[] value)
- Specified by:
size
in interfaceValueAccessor<byte[]>
- Returns:
- the size of the given value
-
createArray
public byte[][] createArray(int length)
Description copied from interface:ValueAccessor
allocate an instance of the accessors backing type- Specified by:
createArray
in interfaceValueAccessor<byte[]>
- Parameters:
length
- size of backing typ to allocate
-
write
public void write(byte[] value, DataOutputPlus out) throws java.io.IOException
Description copied from interface:ValueAccessor
Write the contents of the given value into the a DataOutputPlus- Specified by:
write
in interfaceValueAccessor<byte[]>
- Throws:
java.io.IOException
-
write
public void write(byte[] value, java.nio.ByteBuffer out)
Description copied from interface:ValueAccessor
Write the contents of the given value into the ByteBuffer- Specified by:
write
in interfaceValueAccessor<byte[]>
-
copyTo
public <V2> int copyTo(byte[] src, int srcOffset, V2 dst, ValueAccessor<V2> dstAccessor, int dstOffset, int size)
Description copied from interface:ValueAccessor
copy the {@param size} bytes from the {@param src} value, starting at the offset {@param srcOffset} into the {@param dst} value, starting at the offset {@param dstOffset}, using the accessor {@param dstAccessor}- Specified by:
copyTo
in interfaceValueAccessor<byte[]>
- Type Parameters:
V2
- the destination value type- Returns:
- the number of bytes copied ({@param size})
-
copyByteArrayTo
public int copyByteArrayTo(byte[] src, int srcOffset, byte[] dst, int dstOffset, int size)
Description copied from interface:ValueAccessor
copies a byte array into this accessors value.- Specified by:
copyByteArrayTo
in interfaceValueAccessor<byte[]>
-
copyByteBufferTo
public int copyByteBufferTo(java.nio.ByteBuffer src, int srcOffset, byte[] dst, int dstOffset, int size)
Description copied from interface:ValueAccessor
copies a byte buffer into this accessors value.- Specified by:
copyByteBufferTo
in interfaceValueAccessor<byte[]>
-
digest
public void digest(byte[] value, int offset, int size, Digest digest)
Description copied from interface:ValueAccessor
updates {@param digest} with {@param size} bytes from the contents of {@param value} starting at offset {@param offset}- Specified by:
digest
in interfaceValueAccessor<byte[]>
-
read
public byte[] read(DataInputPlus in, int length) throws java.io.IOException
Description copied from interface:ValueAccessor
Reads a value of {@param length} bytes from {@param in}- Specified by:
read
in interfaceValueAccessor<byte[]>
- Throws:
java.io.IOException
-
slice
public byte[] slice(byte[] input, int offset, int length)
Description copied from interface:ValueAccessor
Returns a value with the contents of {@param input} from {@param offset} to {@param length}. Depending on the accessor implementation, this method may: * allocate a new {@param} object of {@param length}, and copy data into it * return a view of {@param input} where changes to one will be reflected in the other - Specified by:
slice
in interfaceValueAccessor<byte[]>
-
compare
public <V2> int compare(byte[] left, V2 right, ValueAccessor<V2> accessorR)
Description copied from interface:ValueAccessor
lexicographically compare {@param left} to {@param right}- Specified by:
compare
in interfaceValueAccessor<byte[]>
- Type Parameters:
V2
- backing type of
-
compareByteArrayTo
public int compareByteArrayTo(byte[] left, byte[] right)
Description copied from interface:ValueAccessor
compare a byte array on the left with a {@param} on the right} - Specified by:
compareByteArrayTo
in interfaceValueAccessor<byte[]>
-
compareByteBufferTo
public int compareByteBufferTo(java.nio.ByteBuffer left, byte[] right)
Description copied from interface:ValueAccessor
compare a byte buffer on the left with a {@param} on the right} - Specified by:
compareByteBufferTo
in interfaceValueAccessor<byte[]>
-
toBuffer
public java.nio.ByteBuffer toBuffer(byte[] value)
Description copied from interface:ValueAccessor
returns a ByteBuffer with the contents of {@param value} Depending on the accessor implementation, this method may: * allocate a new ByteBuffer and copy data into it * return the value, if the backing type is a bytebuffer- Specified by:
toBuffer
in interfaceValueAccessor<byte[]>
-
toArray
public byte[] toArray(byte[] value)
Description copied from interface:ValueAccessor
returns a byte[] with the contents of {@param value} Depending on the accessor implementation, this method may: * allocate a new byte[] object and copy data into it * return the value, if the backing type is byte[]- Specified by:
toArray
in interfaceValueAccessor<byte[]>
-
toArray
public byte[] toArray(byte[] value, int offset, int length)
Description copied from interface:ValueAccessor
returns a byte[] with {@param length} bytes copied from the contents of {@param value} starting at offset {@param offset}. Depending on the accessor implementation, this method may: * allocate a new byte[] object and copy data into it * return the value, if the backing type is byte[], offset is 0 and {@param length} == size(value)- Specified by:
toArray
in interfaceValueAccessor<byte[]>
-
toString
public java.lang.String toString(byte[] value, java.nio.charset.Charset charset) throws java.nio.charset.CharacterCodingException
- Specified by:
toString
in interfaceValueAccessor<byte[]>
- Throws:
java.nio.charset.CharacterCodingException
-
toHex
public java.lang.String toHex(byte[] value)
- Specified by:
toHex
in interfaceValueAccessor<byte[]>
-
toByte
public byte toByte(byte[] value)
Description copied from interface:ValueAccessor
returns a byte from offset 0- Specified by:
toByte
in interfaceValueAccessor<byte[]>
-
getByte
public byte getByte(byte[] value, int offset)
Description copied from interface:ValueAccessor
returns a byte from offset {@param offset}- Specified by:
getByte
in interfaceValueAccessor<byte[]>
-
toShort
public short toShort(byte[] value)
Description copied from interface:ValueAccessor
returns a short from offset 0- Specified by:
toShort
in interfaceValueAccessor<byte[]>
-
getShort
public short getShort(byte[] value, int offset)
Description copied from interface:ValueAccessor
returns a short from offset {@param offset}- Specified by:
getShort
in interfaceValueAccessor<byte[]>
-
getUnsignedShort
public int getUnsignedShort(byte[] value, int offset)
Description copied from interface:ValueAccessor
returns an unsigned short from offset {@param offset}- Specified by:
getUnsignedShort
in interfaceValueAccessor<byte[]>
-
toInt
public int toInt(byte[] value)
Description copied from interface:ValueAccessor
returns an int from offset 0- Specified by:
toInt
in interfaceValueAccessor<byte[]>
-
getInt
public int getInt(byte[] value, int offset)
Description copied from interface:ValueAccessor
returns an int from offset {@param offset}- Specified by:
getInt
in interfaceValueAccessor<byte[]>
-
getFloat
public float getFloat(byte[] value, int offset)
- Specified by:
getFloat
in interfaceValueAccessor<byte[]>
-
getDouble
public double getDouble(byte[] value, int offset)
- Specified by:
getDouble
in interfaceValueAccessor<byte[]>
-
toLong
public long toLong(byte[] value)
Description copied from interface:ValueAccessor
returns a long from offset 0- Specified by:
toLong
in interfaceValueAccessor<byte[]>
-
getLong
public long getLong(byte[] value, int offset)
Description copied from interface:ValueAccessor
returns a long from offset {@param offset}- Specified by:
getLong
in interfaceValueAccessor<byte[]>
-
toFloat
public float toFloat(byte[] value)
Description copied from interface:ValueAccessor
returns a float from offset 0- Specified by:
toFloat
in interfaceValueAccessor<byte[]>
-
toFloatArray
public float[] toFloatArray(byte[] value, int dimension)
Description copied from interface:ValueAccessor
returns a float[] from offset 0- Specified by:
toFloatArray
in interfaceValueAccessor<byte[]>
-
toDouble
public double toDouble(byte[] value)
Description copied from interface:ValueAccessor
returns a double from offset 0- Specified by:
toDouble
in interfaceValueAccessor<byte[]>
-
toUUID
public java.util.UUID toUUID(byte[] value)
Description copied from interface:ValueAccessor
returns a UUID from offset 0- Specified by:
toUUID
in interfaceValueAccessor<byte[]>
-
toTimeUUID
public TimeUUID toTimeUUID(byte[] value)
Description copied from interface:ValueAccessor
returns a TimeUUID from offset 0- Specified by:
toTimeUUID
in interfaceValueAccessor<byte[]>
-
toBallot
public Ballot toBallot(byte[] value)
Description copied from interface:ValueAccessor
returns a TimeUUID from offset 0- Specified by:
toBallot
in interfaceValueAccessor<byte[]>
-
putByte
public int putByte(byte[] dst, int offset, byte value)
Description copied from interface:ValueAccessor
writes the byte value {@param value} to {@param dst} at offset {@param offset}- Specified by:
putByte
in interfaceValueAccessor<byte[]>
- Returns:
- the number of bytes written to {@param value}
-
putShort
public int putShort(byte[] dst, int offset, short value)
Description copied from interface:ValueAccessor
writes the short value {@param value} to {@param dst} at offset {@param offset}- Specified by:
putShort
in interfaceValueAccessor<byte[]>
- Returns:
- the number of bytes written to {@param value}
-
putInt
public int putInt(byte[] dst, int offset, int value)
Description copied from interface:ValueAccessor
writes the int value {@param value} to {@param dst} at offset {@param offset}- Specified by:
putInt
in interfaceValueAccessor<byte[]>
- Returns:
- the number of bytes written to {@param value}
-
putLong
public int putLong(byte[] dst, int offset, long value)
Description copied from interface:ValueAccessor
writes the long value {@param value} to {@param dst} at offset {@param offset}- Specified by:
putLong
in interfaceValueAccessor<byte[]>
- Returns:
- the number of bytes written to {@param value}
-
putFloat
public int putFloat(byte[] dst, int offset, float value)
Description copied from interface:ValueAccessor
writes the float value {@param value} to {@param dst} at offset {@param offset}- Specified by:
putFloat
in interfaceValueAccessor<byte[]>
- Returns:
- the number of bytes written to {@param value}
-
empty
public byte[] empty()
Description copied from interface:ValueAccessor
return a value with a length of 0- Specified by:
empty
in interfaceValueAccessor<byte[]>
-
valueOf
public byte[] valueOf(byte[] bytes)
Description copied from interface:ValueAccessor
return a value containing the {@param bytes} Caller should assume that modifying the returned value will also modify the contents of {@param bytes}- Specified by:
valueOf
in interfaceValueAccessor<byte[]>
-
valueOf
public byte[] valueOf(java.nio.ByteBuffer bytes)
Description copied from interface:ValueAccessor
return a value containing the {@param bytes} {@param src} and the returned value may share a common byte array instance, so caller should assume that modifying the returned value will also modify the contents of {@param src}- Specified by:
valueOf
in interfaceValueAccessor<byte[]>
-
valueOf
public byte[] valueOf(java.lang.String s, java.nio.charset.Charset charset)
Description copied from interface:ValueAccessor
return a value containing the bytes for the given string and charset- Specified by:
valueOf
in interfaceValueAccessor<byte[]>
-
valueOf
public byte[] valueOf(java.util.UUID v)
Description copied from interface:ValueAccessor
return a value with the bytes from {@param v}- Specified by:
valueOf
in interfaceValueAccessor<byte[]>
-
valueOf
public byte[] valueOf(boolean v)
Description copied from interface:ValueAccessor
return a value with the bytes from {@param v}- Specified by:
valueOf
in interfaceValueAccessor<byte[]>
-
valueOf
public byte[] valueOf(byte v)
Description copied from interface:ValueAccessor
return a value with the bytes from {@param v}- Specified by:
valueOf
in interfaceValueAccessor<byte[]>
-
valueOf
public byte[] valueOf(short v)
Description copied from interface:ValueAccessor
return a value with the bytes from {@param v}- Specified by:
valueOf
in interfaceValueAccessor<byte[]>
-
valueOf
public byte[] valueOf(int v)
Description copied from interface:ValueAccessor
return a value with the bytes from {@param v}- Specified by:
valueOf
in interfaceValueAccessor<byte[]>
-
valueOf
public byte[] valueOf(long v)
Description copied from interface:ValueAccessor
return a value with the bytes from {@param v}- Specified by:
valueOf
in interfaceValueAccessor<byte[]>
-
valueOf
public byte[] valueOf(float v)
Description copied from interface:ValueAccessor
return a value with the bytes from {@param v}- Specified by:
valueOf
in interfaceValueAccessor<byte[]>
-
valueOf
public byte[] valueOf(double v)
Description copied from interface:ValueAccessor
return a value with the bytes from {@param v}- Specified by:
valueOf
in interfaceValueAccessor<byte[]>
-
convert
public <V2> byte[] convert(V2 src, ValueAccessor<V2> accessor)
Description copied from interface:ValueAccessor
Convert the data in {@param src} to {@param} {@param src} and the returned value may share a common byte array instance, so caller should assume that modifying the returned value will also modify the contents of {@param src} - Specified by:
convert
in interfaceValueAccessor<byte[]>
-
allocate
public byte[] allocate(int size)
Description copied from interface:ValueAccessor
Allocate and return a {@param} instance of {@param size} bytes on the heap. - Specified by:
allocate
in interfaceValueAccessor<byte[]>
-
factory
public ValueAccessor.ObjectFactory<byte[]> factory()
Description copied from interface:ValueAccessor
returns theValueAccessor.ObjectFactory
for the backing type {@param} - Specified by:
factory
in interfaceValueAccessor<byte[]>
-
-