Package org.iq80.leveldb.util
Class SliceInput
java.lang.Object
java.io.InputStream
org.iq80.leveldb.util.SliceInput
- All Implemented Interfaces:
Closeable,DataInput,AutoCloseable
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of readable bytes which is equal to(this.slice.length() - this.position).booleanReturnstrueif and only ifavailable()is greater than0.intposition()Returns thepositionof this buffer.intread()booleanbytereadByte()Gets a byte at the currentpositionand increases thepositionby1in this buffer.byte[]readByteArray(int length) voidreadBytes(byte[] destination) Transfers this buffer's data to the specified destination starting at the currentpositionand increases thepositionby the number of the transferred bytes (=dst.length).voidreadBytes(byte[] destination, int destinationIndex, int length) Transfers this buffer's data to the specified destination starting at the currentpositionand increases thepositionby the number of the transferred bytes (=length).readBytes(int length) Transfers this buffer's data to a newly created buffer starting at the currentpositionand increases thepositionby the number of the transferred bytes (=length).voidreadBytes(OutputStream out, int length) Transfers this buffer's data to the specified stream starting at the currentposition.voidreadBytes(ByteBuffer destination) Transfers this buffer's data to the specified destination starting at the currentpositionuntil the destination's position reaches its limit, and increases thepositionby the number of the transferred bytes.intreadBytes(GatheringByteChannel out, int length) Transfers this buffer's data to the specified stream starting at the currentposition.voidTransfers this buffer's data to the specified destination starting at the currentpositionuntil the destination becomes non-writable, and increases thepositionby the number of the transferred bytes.voidTransfers this buffer's data to the specified destination starting at the currentpositionand increases thepositionby the number of the transferred bytes (=length).voidTransfers this buffer's data to the specified destination starting at the currentpositionand increases thepositionby the number of the transferred bytes (=length).charreadChar()Unsupported operationdoublefloatUnsupported operationvoidreadFully(byte[] destination) voidreadFully(byte[] destination, int offset, int length) intreadInt()Gets a 32-bit integer at the currentpositionand increases thepositionby4in this buffer.readLine()Unsupported operationlongreadLong()Gets a 64-bit integer at the currentpositionand increases thepositionby8in this buffer.shortGets a 16-bit short integer at the currentpositionand increases thepositionby2in this buffer.readSlice(int length) Returns a new slice of this buffer's sub-region starting at the currentpositionand increases thepositionby the size of the new slice (=length).intGets an unsigned byte at the currentpositionand increases thepositionby1in this buffer.longGets an unsigned 32-bit integer at the currentpositionand increases thepositionby4in this buffer.intreadUTF()Unsupported operationvoidsetPosition(int position) Sets thepositionof this buffer.intskipBytes(int length) slice()Returns a slice of this buffer's readable bytes.Converts this buffer's readable bytes into a NIO buffer.toString()Decodes this buffer's readable bytes into a string with the specified character set name.Methods inherited from class java.io.InputStream
close, mark, markSupported, nullInputStream, read, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Field Details
-
slice
-
position
private int position
-
-
Constructor Details
-
SliceInput
-
-
Method Details
-
position
public int position()Returns thepositionof this buffer. -
setPosition
public void setPosition(int position) Sets thepositionof this buffer.- Throws:
IndexOutOfBoundsException- if the specifiedpositionis less than0or greater thanthis.writerIndex
-
isReadable
public boolean isReadable()Returnstrueif and only ifavailable()is greater than0. -
available
public int available()Returns the number of readable bytes which is equal to(this.slice.length() - this.position).- Overrides:
availablein classInputStream
-
readBoolean
- Specified by:
readBooleanin interfaceDataInput- Throws:
IOException
-
read
public int read()- Specified by:
readin classInputStream
-
readByte
public byte readByte()Gets a byte at the currentpositionand increases thepositionby1in this buffer.- Specified by:
readBytein interfaceDataInput- Throws:
IndexOutOfBoundsException- ifthis.available()is less than1
-
readUnsignedByte
public int readUnsignedByte()Gets an unsigned byte at the currentpositionand increases thepositionby1in this buffer.- Specified by:
readUnsignedBytein interfaceDataInput- Throws:
IndexOutOfBoundsException- ifthis.available()is less than1
-
readShort
public short readShort()Gets a 16-bit short integer at the currentpositionand increases thepositionby2in this buffer.- Specified by:
readShortin interfaceDataInput- Throws:
IndexOutOfBoundsException- ifthis.available()is less than2
-
readUnsignedShort
- Specified by:
readUnsignedShortin interfaceDataInput- Throws:
IOException
-
readInt
public int readInt()Gets a 32-bit integer at the currentpositionand increases thepositionby4in this buffer.- Specified by:
readIntin interfaceDataInput- Throws:
IndexOutOfBoundsException- ifthis.available()is less than4
-
readUnsignedInt
public long readUnsignedInt()Gets an unsigned 32-bit integer at the currentpositionand increases thepositionby4in this buffer.- Throws:
IndexOutOfBoundsException- ifthis.available()is less than4
-
readLong
public long readLong()Gets a 64-bit integer at the currentpositionand increases thepositionby8in this buffer.- Specified by:
readLongin interfaceDataInput- Throws:
IndexOutOfBoundsException- ifthis.available()is less than8
-
readByteArray
public byte[] readByteArray(int length) -
readBytes
Transfers this buffer's data to a newly created buffer starting at the currentpositionand increases thepositionby the number of the transferred bytes (=length). The returned buffer'spositionandwriterIndexare0andlengthrespectively.- Parameters:
length- the number of bytes to transfer- Returns:
- the newly created buffer which contains the transferred bytes
- Throws:
IndexOutOfBoundsException- iflengthis greater thanthis.available()
-
readSlice
Returns a new slice of this buffer's sub-region starting at the currentpositionand increases thepositionby the size of the new slice (=length).- Parameters:
length- the size of the new slice- Returns:
- the newly created slice
- Throws:
IndexOutOfBoundsException- iflengthis greater thanthis.available()
-
readFully
public void readFully(byte[] destination) -
readBytes
public void readBytes(byte[] destination) Transfers this buffer's data to the specified destination starting at the currentpositionand increases thepositionby the number of the transferred bytes (=dst.length).- Throws:
IndexOutOfBoundsException- ifdst.lengthis greater thanthis.available()
-
readFully
public void readFully(byte[] destination, int offset, int length) -
readBytes
public void readBytes(byte[] destination, int destinationIndex, int length) Transfers this buffer's data to the specified destination starting at the currentpositionand increases thepositionby the number of the transferred bytes (=length).- Parameters:
destinationIndex- the first index of the destinationlength- the number of bytes to transfer- Throws:
IndexOutOfBoundsException- if the specifieddestinationIndexis less than0, iflengthis greater thanthis.available(), or ifdestinationIndex + lengthis greater thandestination.length
-
readBytes
Transfers this buffer's data to the specified destination starting at the currentpositionuntil the destination becomes non-writable, and increases thepositionby the number of the transferred bytes. This method is basically same withreadBytes(Slice, int, int), except that this method increases thewriterIndexof the destination by the number of the transferred bytes whilereadBytes(Slice, int, int)does not.- Throws:
IndexOutOfBoundsException- ifdestination.writableBytesis greater thanthis.available()
-
readBytes
Transfers this buffer's data to the specified destination starting at the currentpositionand increases thepositionby the number of the transferred bytes (=length). This method is basically same withreadBytes(Slice, int, int), except that this method increases thewriterIndexof the destination by the number of the transferred bytes (=length) whilereadBytes(Slice, int, int)does not.- Throws:
IndexOutOfBoundsException- iflengthis greater thanthis.available()or iflengthis greater thandestination.writableBytes
-
readBytes
Transfers this buffer's data to the specified destination starting at the currentpositionand increases thepositionby the number of the transferred bytes (=length).- Parameters:
destinationIndex- the first index of the destinationlength- the number of bytes to transfer- Throws:
IndexOutOfBoundsException- if the specifieddestinationIndexis less than0, iflengthis greater thanthis.available(), or ifdestinationIndex + lengthis greater thandestination.capacity
-
readBytes
Transfers this buffer's data to the specified destination starting at the currentpositionuntil the destination's position reaches its limit, and increases thepositionby the number of the transferred bytes.- Throws:
IndexOutOfBoundsException- ifdestination.remaining()is greater thanthis.available()
-
readBytes
Transfers this buffer's data to the specified stream starting at the currentposition.- Parameters:
length- the maximum number of bytes to transfer- Returns:
- the actual number of bytes written out to the specified channel
- Throws:
IndexOutOfBoundsException- iflengthis greater thanthis.available()IOException- if the specified channel threw an exception during I/O
-
readBytes
Transfers this buffer's data to the specified stream starting at the currentposition.- Parameters:
length- the number of bytes to transfer- Throws:
IndexOutOfBoundsException- iflengthis greater thanthis.available()IOException- if the specified stream threw an exception during I/O
-
skipBytes
public int skipBytes(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. This method is identical tobuf.slice(buf.position(), buf.available()()). This method does not modifypositionorwriterIndexof this buffer. -
toByteBuffer
Converts this buffer's readable bytes into a NIO buffer. The returned buffer might or might not share the content with this buffer, while they have separate indexes and marks. This method is identical tobuf.toByteBuffer(buf.position(), buf.available()()). This method does not modifypositionorwriterIndexof this buffer. -
toString
Decodes this buffer's readable bytes into a string with the specified character set name. This method is identical tobuf.toString(buf.position(), buf.available()(), charsetName). This method does not modifypositionorwriterIndexof this buffer.- Throws:
UnsupportedCharsetException- if the specified character set name is not supported by the current VM
-
toString
-
readChar
public char readChar()Unsupported operation- Specified by:
readCharin interfaceDataInput- Throws:
UnsupportedOperationException- always
-
readFloat
public float readFloat()Unsupported operation- Specified by:
readFloatin interfaceDataInput- Throws:
UnsupportedOperationException- always
-
readDouble
public double readDouble()- Specified by:
readDoublein interfaceDataInput
-
readLine
Unsupported operation- Specified by:
readLinein interfaceDataInput- Throws:
UnsupportedOperationException- always
-
readUTF
Unsupported operation- Specified by:
readUTFin interfaceDataInput- Throws:
UnsupportedOperationException- always
-