public class Slice extends RocksObject
Base class for slices which will receive byte[] based access to the underlying data.
byte[] backed slices typically perform better with
small keys and values. When using larger keys and
values consider using DirectSlice
nativeHandle_
Constructor and Description |
---|
Slice(byte[] data)
Constructs a slice where the data is a copy of
the byte array.
|
Slice(byte[] data,
int offset)
Constructs a slice where the data is a copy of
the byte array from a specific offset.
|
Slice(java.lang.String str)
Constructs a slice where the data is taken from
a String.
|
Modifier and Type | Method and Description |
---|---|
int |
compare(org.rocksdb.AbstractSlice<?> other)
Three-way key comparison
|
protected void |
createNewSliceFromString(java.lang.String str) |
T |
data()
Returns the data of the slice.
|
protected byte[] |
data0(long handle)
Access to the data is provided by the
subtype as it needs to handle the
generic typing.
|
protected void |
disposeInternal()
Deletes underlying C++ slice pointer
and any buffered data.
|
boolean |
empty()
Return true if the length of the
data is zero.
|
boolean |
equals(java.lang.Object other)
If other is a slice object, then
we defer to
compare
to check equality, otherwise we return false. |
int |
size()
Return the length (in bytes) of the data.
|
boolean |
startsWith(org.rocksdb.AbstractSlice<?> prefix)
Determines whether this slice starts with
another slice
|
java.lang.String |
toString() |
java.lang.String |
toString(boolean hex)
Creates a string representation of the data
|
disOwnNativeHandle, dispose, finalize, isInitialized, isOwningNativeHandle
public Slice(java.lang.String str)
Constructs a slice where the data is taken from a String.
str
- String value.public Slice(byte[] data, int offset)
Constructs a slice where the data is a copy of the byte array from a specific offset.
data
- byte array.offset
- offset within the byte array.public Slice(byte[] data)
Constructs a slice where the data is a copy of the byte array.
data
- byte array.protected void disposeInternal()
Deletes underlying C++ slice pointer and any buffered data.
Note that this function should be called only after all RocksDB instances referencing the slice are closed. Otherwise an undefined behavior will occur.
protected final byte[] data0(long handle)
handle
- The address of the underlying
native object.public T data()
AbstractSlice.data0(long)
public int size()
public boolean empty()
public java.lang.String toString(boolean hex)
hex
- When true, the representation
will be encoded in hexadecimal.public java.lang.String toString()
toString
in class java.lang.Object
public int compare(org.rocksdb.AbstractSlice<?> other)
other
- A slice to compare againstpublic boolean equals(java.lang.Object other)
compare
to check equality, otherwise we return false.equals
in class java.lang.Object
other
- Object to test for equalitythis.compare(other) == 0
,
false otherwise.public boolean startsWith(org.rocksdb.AbstractSlice<?> prefix)
prefix
- Another slice which may of may not
be a prefix of this slice.prefix
sliceprotected void createNewSliceFromString(java.lang.String str)