Package org.iq80.leveldb.util
Class Slice
java.lang.Object
org.iq80.leveldb.util.Slice
- All Implemented Interfaces:
Comparable<Slice>
Little Endian slice of a byte array.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintCompares the content of the specified buffer to the content of this buffer.byte[]byte[]copyBytes(int index, int length) copySlice(int index, int length) Returns a copy of this buffer's sub-region.booleanbytegetByte(int index) Gets a byte at the specified absoluteindexin this buffer.byte[]getBytes()voidgetBytes(int index, byte[] destination, int destinationIndex, int length) Transfers this buffer's data to the specified destination starting at the specified absoluteindex.byte[]getBytes(int index, int length) voidgetBytes(int index, OutputStream out, int length) Transfers this buffer's data to the specified stream starting at the specified absoluteindex.voidgetBytes(int index, ByteBuffer destination) Transfers this buffer's data to the specified destination starting at the specified absoluteindexuntil the destination's position reaches its limit.intgetBytes(int index, GatheringByteChannel out, int length) Transfers this buffer's data to the specified channel starting at the specified absoluteindex.voidTransfers this buffer's data to the specified destination starting at the specified absoluteindex.intgetInt(int index) Gets a 32-bit integer at the specified absoluteindexin this buffer.longgetLong(int index) Gets a 64-bit long integer at the specified absoluteindexin this buffer.byte[]Gets the array underlying this slice.intGets the offset of this slice in the underlying array.shortgetShort(int index) Gets a 16-bit short integer at the specified absoluteindexin this slice.shortgetUnsignedByte(int index) Gets an unsigned byte at the specified absoluteindexin this buffer.inthashCode()input()Creates an input stream over this slice.intlength()Length of this slice.output()Creates an output stream over this slice.voidsetByte(int index, int value) Sets the specified byte at the specified absoluteindexin this buffer.voidsetBytes(int index, byte[] source, int sourceIndex, int length) Transfers the specified source array's data to this buffer starting at the specified absoluteindex.intsetBytes(int index, InputStream in, int length) Transfers the content of the specified source stream to this buffer starting at the specified absoluteindex.voidsetBytes(int index, ByteBuffer source) Transfers the specified source buffer's data to this buffer starting at the specified absoluteindexuntil the source buffer's position reaches its limit.intsetBytes(int index, FileChannel in, int position, int length) intsetBytes(int index, ScatteringByteChannel in, int length) Transfers the content of the specified source channel to this buffer starting at the specified absoluteindex.voidTransfers the specified source buffer's data to this buffer starting at the specified absoluteindex.voidsetInt(int index, int value) Sets the specified 32-bit integer at the specified absoluteindexin this buffer.voidsetLong(int index, long value) Sets the specified 64-bit long integer at the specified absoluteindexin this buffer.voidsetShort(int index, int value) Sets the specified 16-bit short integer at the specified absoluteindexin this buffer.slice()Returns a slice of this buffer's readable bytes.slice(int index, int length) Returns a slice of this buffer's sub-region.Converts this buffer's readable bytes into a NIO buffer.toByteBuffer(int index, int length) Converts this buffer's sub-region into a NIO buffer.toString()Decodes this buffer's sub-region into a string with the specified character set.Decodes this buffer's readable bytes into a string with the specified character set name.
-
Field Details
-
data
private final byte[] data -
offset
private final int offset -
length
private final int length -
hash
private int hash
-
-
Constructor Details
-
Slice
public Slice(int length) -
Slice
public Slice(byte[] data) -
Slice
public Slice(byte[] data, int offset, int length)
-
-
Method Details
-
length
public int length()Length of this slice. -
getRawArray
public byte[] getRawArray()Gets the array underlying this slice. -
getRawOffset
public int getRawOffset()Gets the offset of this slice in the underlying array. -
getByte
public byte getByte(int index) Gets a byte at the specified absoluteindexin this buffer.- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 1is greater thanthis.capacity
-
getUnsignedByte
public short getUnsignedByte(int index) Gets an unsigned byte at the specified absoluteindexin this buffer.- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 1is greater thanthis.capacity
-
getShort
public short getShort(int index) Gets a 16-bit short integer at the specified absoluteindexin this slice.- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 2is greater thanthis.capacity
-
getInt
public int getInt(int index) Gets a 32-bit integer at the specified absoluteindexin this buffer.- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 4is greater thanthis.capacity
-
getLong
public long getLong(int index) Gets a 64-bit long integer at the specified absoluteindexin this buffer.- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 8is greater thanthis.capacity
-
getBytes
Transfers this buffer's data to the specified destination starting at the specified absoluteindex.- Parameters:
dstIndex- the first index of the destinationlength- the number of bytes to transfer- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0, if the specifieddstIndexis less than0, ifindex + lengthis greater thanthis.capacity, or ifdstIndex + lengthis greater thandst.capacity
-
getBytes
public void getBytes(int index, byte[] destination, int destinationIndex, int length) Transfers this buffer's data to the specified destination starting at the specified absoluteindex.- Parameters:
destinationIndex- the first index of the destinationlength- the number of bytes to transfer- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0, if the specifieddstIndexis less than0, ifindex + lengthis greater thanthis.capacity, or ifdstIndex + lengthis greater thandst.length
-
getBytes
public byte[] getBytes() -
getBytes
public byte[] getBytes(int index, int length) -
getBytes
Transfers this buffer's data to the specified destination starting at the specified absoluteindexuntil the destination's position reaches its limit.- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0or ifindex + dst.remaining()is greater thanthis.capacity
-
getBytes
Transfers this buffer's data to the specified stream starting at the specified absoluteindex.- Parameters:
length- the number of bytes to transfer- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0or ifindex + lengthis greater thanthis.capacityIOException- if the specified stream threw an exception during I/O
-
getBytes
Transfers this buffer's data to the specified channel starting at the specified absoluteindex.- Parameters:
length- the maximum number of bytes to transfer- Returns:
- the actual number of bytes written out to the specified channel
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0or ifindex + lengthis greater thanthis.capacityIOException- if the specified channel threw an exception during I/O
-
setShort
public void setShort(int index, int value) Sets the specified 16-bit short integer at the specified absoluteindexin this buffer. The 16 high-order bits of the specified value are ignored.- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 2is greater thanthis.capacity
-
setInt
public void setInt(int index, int value) Sets the specified 32-bit integer at the specified absoluteindexin this buffer.- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 4is greater thanthis.capacity
-
setLong
public void setLong(int index, long value) Sets the specified 64-bit long integer at the specified absoluteindexin this buffer.- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 8is greater thanthis.capacity
-
setByte
public void setByte(int index, int value) Sets the specified byte at the specified absoluteindexin this buffer. The 24 high-order bits of the specified value are ignored.- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 1is greater thanthis.capacity
-
setBytes
Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex.- Parameters:
srcIndex- the first index of the sourcelength- the number of bytes to transfer- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0, if the specifiedsrcIndexis less than0, ifindex + lengthis greater thanthis.capacity, or ifsrcIndex + lengthis greater thansrc.capacity
-
setBytes
public void setBytes(int index, byte[] source, int sourceIndex, int length) Transfers the specified source array's data to this buffer starting at the specified absoluteindex.- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0, if the specifiedsrcIndexis less than0, ifindex + lengthis greater thanthis.capacity, or ifsrcIndex + lengthis greater thansrc.length
-
setBytes
Transfers the specified source buffer's data to this buffer starting at the specified absoluteindexuntil the source buffer's position reaches its limit.- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0or ifindex + src.remaining()is greater thanthis.capacity
-
setBytes
Transfers the content of the specified source stream to this buffer starting at the specified absoluteindex.- Parameters:
length- the number of bytes to transfer- Returns:
- the actual number of bytes read in from the specified channel.
-1if the specified channel is closed. - Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0or ifindex + lengthis greater thanthis.capacityIOException- if the specified stream threw an exception during I/O
-
setBytes
Transfers the content of the specified source channel to this buffer starting at the specified absoluteindex.- Parameters:
length- the maximum number of bytes to transfer- Returns:
- the actual number of bytes read in from the specified channel.
-1if the specified channel is closed. - Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0or ifindex + lengthis greater thanthis.capacityIOException- if the specified channel threw an exception during I/O
-
setBytes
- Throws:
IOException
-
copySlice
-
copySlice
Returns a copy of this buffer's sub-region. Modifying the content of the returned buffer or this buffer does not affect each other at all. -
copyBytes
public byte[] copyBytes() -
copyBytes
public byte[] copyBytes(int index, int length) -
slice
Returns a slice of this buffer's readable bytes. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes and marks. -
slice
Returns a slice of this buffer's sub-region. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes and marks. -
input
Creates an input stream over this slice. -
output
Creates an output stream over this slice. -
toByteBuffer
Converts this buffer's readable bytes into a NIO buffer. The returned buffer shares the content with this buffer. -
toByteBuffer
Converts this buffer's sub-region into a NIO buffer. The returned buffer shares the content with this buffer. -
equals
-
hashCode
public int hashCode() -
compareTo
Compares the content of the specified buffer to the content of this buffer. This comparison is performed byte by byte using an unsigned comparison.- Specified by:
compareToin interfaceComparable<Slice>
-
toString
Decodes this buffer's readable bytes into a string with the specified character set name. -
toString
Decodes this buffer's sub-region into a string with the specified character set. -
toString
-