Class SliceInput

java.lang.Object
java.io.InputStream
org.iq80.leveldb.util.SliceInput
All Implemented Interfaces:
Closeable, DataInput, AutoCloseable

public final class SliceInput extends InputStream implements DataInput
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int
     
    private final Slice
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the number of readable bytes which is equal to (this.slice.length() - this.position).
    boolean
    Returns true if and only if available() is greater than 0.
    int
    Returns the position of this buffer.
    int
     
    boolean
     
    byte
    Gets a byte at the current position and increases the position by 1 in this buffer.
    byte[]
    readByteArray(int length)
     
    void
    readBytes(byte[] destination)
    Transfers this buffer's data to the specified destination starting at the current position and increases the position by the number of the transferred bytes (= dst.length).
    void
    readBytes(byte[] destination, int destinationIndex, int length)
    Transfers this buffer's data to the specified destination starting at the current position and increases the position by the number of the transferred bytes (= length).
    readBytes(int length)
    Transfers this buffer's data to a newly created buffer starting at the current position and increases the position by the number of the transferred bytes (= length).
    void
    readBytes(OutputStream out, int length)
    Transfers this buffer's data to the specified stream starting at the current position.
    void
    readBytes(ByteBuffer destination)
    Transfers this buffer's data to the specified destination starting at the current position until the destination's position reaches its limit, and increases the position by the number of the transferred bytes.
    int
    readBytes(GatheringByteChannel out, int length)
    Transfers this buffer's data to the specified stream starting at the current position.
    void
    readBytes(Slice destination)
    Transfers this buffer's data to the specified destination starting at the current position until the destination becomes non-writable, and increases the position by the number of the transferred bytes.
    void
    readBytes(Slice destination, int length)
    Transfers this buffer's data to the specified destination starting at the current position and increases the position by the number of the transferred bytes (= length).
    void
    readBytes(Slice destination, int destinationIndex, int length)
    Transfers this buffer's data to the specified destination starting at the current position and increases the position by the number of the transferred bytes (= length).
    char
    Unsupported operation
    double
     
    float
    Unsupported operation
    void
    readFully(byte[] destination)
     
    void
    readFully(byte[] destination, int offset, int length)
     
    int
    Gets a 32-bit integer at the current position and increases the position by 4 in this buffer.
    Unsupported operation
    long
    Gets a 64-bit integer at the current position and increases the position by 8 in this buffer.
    short
    Gets a 16-bit short integer at the current position and increases the position by 2 in this buffer.
    readSlice(int length)
    Returns a new slice of this buffer's sub-region starting at the current position and increases the position by the size of the new slice (= length).
    int
    Gets an unsigned byte at the current position and increases the position by 1 in this buffer.
    long
    Gets an unsigned 32-bit integer at the current position and increases the position by 4 in this buffer.
    int
     
    Unsupported operation
    void
    setPosition(int position)
    Sets the position of this buffer.
    int
    skipBytes(int length)
     
    Returns a slice of this buffer's readable bytes.
    Converts this buffer's readable bytes into a NIO buffer.
     
    toString(Charset charset)
    Decodes this buffer's readable bytes into a string with the specified character set name.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • slice

      private final Slice slice
    • position

      private int position
  • Constructor Details

    • SliceInput

      public SliceInput(Slice slice)
  • Method Details

    • position

      public int position()
      Returns the position of this buffer.
    • setPosition

      public void setPosition(int position)
      Sets the position of this buffer.
      Throws:
      IndexOutOfBoundsException - if the specified position is less than 0 or greater than this.writerIndex
    • isReadable

      public boolean isReadable()
      Returns true if and only if available() is greater than 0.
    • available

      public int available()
      Returns the number of readable bytes which is equal to (this.slice.length() - this.position).
      Overrides:
      available in class InputStream
    • readBoolean

      public boolean readBoolean() throws IOException
      Specified by:
      readBoolean in interface DataInput
      Throws:
      IOException
    • read

      public int read()
      Specified by:
      read in class InputStream
    • readByte

      public byte readByte()
      Gets a byte at the current position and increases the position by 1 in this buffer.
      Specified by:
      readByte in interface DataInput
      Throws:
      IndexOutOfBoundsException - if this.available() is less than 1
    • readUnsignedByte

      public int readUnsignedByte()
      Gets an unsigned byte at the current position and increases the position by 1 in this buffer.
      Specified by:
      readUnsignedByte in interface DataInput
      Throws:
      IndexOutOfBoundsException - if this.available() is less than 1
    • readShort

      public short readShort()
      Gets a 16-bit short integer at the current position and increases the position by 2 in this buffer.
      Specified by:
      readShort in interface DataInput
      Throws:
      IndexOutOfBoundsException - if this.available() is less than 2
    • readUnsignedShort

      public int readUnsignedShort() throws IOException
      Specified by:
      readUnsignedShort in interface DataInput
      Throws:
      IOException
    • readInt

      public int readInt()
      Gets a 32-bit integer at the current position and increases the position by 4 in this buffer.
      Specified by:
      readInt in interface DataInput
      Throws:
      IndexOutOfBoundsException - if this.available() is less than 4
    • readUnsignedInt

      public long readUnsignedInt()
      Gets an unsigned 32-bit integer at the current position and increases the position by 4 in this buffer.
      Throws:
      IndexOutOfBoundsException - if this.available() is less than 4
    • readLong

      public long readLong()
      Gets a 64-bit integer at the current position and increases the position by 8 in this buffer.
      Specified by:
      readLong in interface DataInput
      Throws:
      IndexOutOfBoundsException - if this.available() is less than 8
    • readByteArray

      public byte[] readByteArray(int length)
    • readBytes

      public Slice readBytes(int length)
      Transfers this buffer's data to a newly created buffer starting at the current position and increases the position by the number of the transferred bytes (= length). The returned buffer's position and writerIndex are 0 and length respectively.
      Parameters:
      length - the number of bytes to transfer
      Returns:
      the newly created buffer which contains the transferred bytes
      Throws:
      IndexOutOfBoundsException - if length is greater than this.available()
    • readSlice

      public Slice readSlice(int length)
      Returns a new slice of this buffer's sub-region starting at the current position and increases the position by the size of the new slice (= length).
      Parameters:
      length - the size of the new slice
      Returns:
      the newly created slice
      Throws:
      IndexOutOfBoundsException - if length is greater than this.available()
    • readFully

      public void readFully(byte[] destination)
      Specified by:
      readFully in interface DataInput
    • readBytes

      public void readBytes(byte[] destination)
      Transfers this buffer's data to the specified destination starting at the current position and increases the position by the number of the transferred bytes (= dst.length).
      Throws:
      IndexOutOfBoundsException - if dst.length is greater than this.available()
    • readFully

      public void readFully(byte[] destination, int offset, int length)
      Specified by:
      readFully in interface DataInput
    • readBytes

      public void readBytes(byte[] destination, int destinationIndex, int length)
      Transfers this buffer's data to the specified destination starting at the current position and increases the position by the number of the transferred bytes (= length).
      Parameters:
      destinationIndex - the first index of the destination
      length - the number of bytes to transfer
      Throws:
      IndexOutOfBoundsException - if the specified destinationIndex is less than 0, if length is greater than this.available(), or if destinationIndex + length is greater than destination.length
    • readBytes

      public void readBytes(Slice destination)
      Transfers this buffer's data to the specified destination starting at the current position until the destination becomes non-writable, and increases the position by the number of the transferred bytes. This method is basically same with readBytes(Slice, int, int), except that this method increases the writerIndex of the destination by the number of the transferred bytes while readBytes(Slice, int, int) does not.
      Throws:
      IndexOutOfBoundsException - if destination.writableBytes is greater than this.available()
    • readBytes

      public void readBytes(Slice destination, int length)
      Transfers this buffer's data to the specified destination starting at the current position and increases the position by the number of the transferred bytes (= length). This method is basically same with readBytes(Slice, int, int), except that this method increases the writerIndex of the destination by the number of the transferred bytes (= length) while readBytes(Slice, int, int) does not.
      Throws:
      IndexOutOfBoundsException - if length is greater than this.available() or if length is greater than destination.writableBytes
    • readBytes

      public void readBytes(Slice destination, int destinationIndex, int length)
      Transfers this buffer's data to the specified destination starting at the current position and increases the position by the number of the transferred bytes (= length).
      Parameters:
      destinationIndex - the first index of the destination
      length - the number of bytes to transfer
      Throws:
      IndexOutOfBoundsException - if the specified destinationIndex is less than 0, if length is greater than this.available(), or if destinationIndex + length is greater than destination.capacity
    • readBytes

      public void readBytes(ByteBuffer destination)
      Transfers this buffer's data to the specified destination starting at the current position until the destination's position reaches its limit, and increases the position by the number of the transferred bytes.
      Throws:
      IndexOutOfBoundsException - if destination.remaining() is greater than this.available()
    • readBytes

      public int readBytes(GatheringByteChannel out, int length) throws IOException
      Transfers this buffer's data to the specified stream starting at the current position.
      Parameters:
      length - the maximum number of bytes to transfer
      Returns:
      the actual number of bytes written out to the specified channel
      Throws:
      IndexOutOfBoundsException - if length is greater than this.available()
      IOException - if the specified channel threw an exception during I/O
    • readBytes

      public void readBytes(OutputStream out, int length) throws IOException
      Transfers this buffer's data to the specified stream starting at the current position.
      Parameters:
      length - the number of bytes to transfer
      Throws:
      IndexOutOfBoundsException - if length is greater than this.available()
      IOException - if the specified stream threw an exception during I/O
    • skipBytes

      public int skipBytes(int length)
      Specified by:
      skipBytes in interface DataInput
    • slice

      public Slice 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 to buf.slice(buf.position(), buf.available()()). This method does not modify position or writerIndex of this buffer.
    • toByteBuffer

      public ByteBuffer 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 to buf.toByteBuffer(buf.position(), buf.available()()). This method does not modify position or writerIndex of this buffer.
    • toString

      public String toString(Charset charset)
      Decodes this buffer's readable bytes into a string with the specified character set name. This method is identical to buf.toString(buf.position(), buf.available()(), charsetName). This method does not modify position or writerIndex of this buffer.
      Throws:
      UnsupportedCharsetException - if the specified character set name is not supported by the current VM
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • readChar

      public char readChar()
      Unsupported operation
      Specified by:
      readChar in interface DataInput
      Throws:
      UnsupportedOperationException - always
    • readFloat

      public float readFloat()
      Unsupported operation
      Specified by:
      readFloat in interface DataInput
      Throws:
      UnsupportedOperationException - always
    • readDouble

      public double readDouble()
      Specified by:
      readDouble in interface DataInput
    • readLine

      public String readLine()
      Unsupported operation
      Specified by:
      readLine in interface DataInput
      Throws:
      UnsupportedOperationException - always
    • readUTF

      public String readUTF()
      Unsupported operation
      Specified by:
      readUTF in interface DataInput
      Throws:
      UnsupportedOperationException - always