Class SingleByteBuff

java.lang.Object
org.apache.hadoop.hbase.nio.ByteBuff
org.apache.hadoop.hbase.nio.SingleByteBuff
All Implemented Interfaces:
HBaseReferenceCounted, org.apache.hbase.thirdparty.io.netty.util.ReferenceCounted

@Private public class SingleByteBuff extends ByteBuff
An implementation of ByteBuff where a single BB backs the BBI. This just acts as a wrapper over a normal BB - offheap or onheap
  • Field Details

  • Constructor Details

  • Method Details

    • position

      public int position()
      Description copied from class: ByteBuff
      Returns this ByteBuff's current position
      Specified by:
      position in class ByteBuff
    • position

      public SingleByteBuff position(int position)
      Description copied from class: ByteBuff
      Sets this ByteBuff's position to the given value.
      Specified by:
      position in class ByteBuff
      Returns:
      this object
    • skip

      public SingleByteBuff skip(int len)
      Description copied from class: ByteBuff
      Jumps the current position of this ByteBuff by specified length.
      Specified by:
      skip in class ByteBuff
      Parameters:
      len - the length to be skipped
    • moveBack

      public SingleByteBuff moveBack(int len)
      Description copied from class: ByteBuff
      Jumps back the current position of this ByteBuff by specified length.
      Specified by:
      moveBack in class ByteBuff
      Parameters:
      len - the length to move back
    • capacity

      public int capacity()
      Description copied from class: ByteBuff
      Returns the total capacity of this ByteBuff.
      Specified by:
      capacity in class ByteBuff
    • limit

      public int limit()
      Description copied from class: ByteBuff
      Returns the limit of this ByteBuff
      Specified by:
      limit in class ByteBuff
    • limit

      public SingleByteBuff limit(int limit)
      Description copied from class: ByteBuff
      Marks the limit of this ByteBuff
      Specified by:
      limit in class ByteBuff
    • rewind

      Description copied from class: ByteBuff
      Rewinds this ByteBuff and the position is set to 0
      Specified by:
      rewind in class ByteBuff
    • mark

      public SingleByteBuff mark()
      Description copied from class: ByteBuff
      Marks the current position of the ByteBuff
      Specified by:
      mark in class ByteBuff
    • asSubByteBuffer

      public ByteBuffer asSubByteBuffer(int length)
      Description copied from class: ByteBuff
      Returns bytes from current position till length specified, as a single ByteBuffer. When all these bytes happen to be in a single ByteBuffer, which this object wraps, that ByteBuffer item as such will be returned. So users are warned not to change the position or limit of this returned ByteBuffer. The position of the returned byte buffer is at the begin of the required bytes. When the required bytes happen to span across multiple ByteBuffers, this API will copy the bytes to a newly created ByteBuffer of required size and return that.
      Specified by:
      asSubByteBuffer in class ByteBuff
      Parameters:
      length - number of bytes required.
      Returns:
      bytes from current position till length specified, as a single ByteButter.
    • asSubByteBuffer

      public void asSubByteBuffer(int offset, int length, ObjectIntPair<ByteBuffer> pair)
      Description copied from class: ByteBuff
      Returns bytes from given offset till length specified, as a single ByteBuffer. When all these bytes happen to be in a single ByteBuffer, which this object wraps, that ByteBuffer item as such will be returned (with offset in this ByteBuffer where the bytes starts). So users are warned not to change the position or limit of this returned ByteBuffer. When the required bytes happen to span across multiple ByteBuffers, this API will copy the bytes to a newly created ByteBuffer of required size and return that.
      Specified by:
      asSubByteBuffer in class ByteBuff
      Parameters:
      offset - the offset in this ByteBuff from where the subBuffer should be created
      length - the length of the subBuffer
      pair - a pair that will have the bytes from the current position till length specified, as a single ByteBuffer and offset in that Buffer where the bytes starts. Since this API gets called in a loop we are passing a pair to it which could be created outside the loop and the method would set the values on the pair that is passed in by the caller. Thus it avoids more object creations that would happen if the pair that is returned is created by this method every time.
    • remaining

      public int remaining()
      Description copied from class: ByteBuff
      Returns the number of elements between the current position and the limit.
      Specified by:
      remaining in class ByteBuff
    • hasRemaining

      public boolean hasRemaining()
      Description copied from class: ByteBuff
      Returns true if there are elements between the current position and the limit.
      Specified by:
      hasRemaining in class ByteBuff
    • reset

      Description copied from class: ByteBuff
      Similar to ByteBuffer.reset(), ensures that this ByteBuff is reset back to last marked position.
      Specified by:
      reset in class ByteBuff
      Returns:
      This ByteBuff
    • slice

      Description copied from class: ByteBuff
      Returns an ByteBuff which is a sliced version of this ByteBuff. The position, limit and mark of the new ByteBuff will be independent than that of the original ByteBuff. The content of the new ByteBuff will start at this ByteBuff's current position
      Specified by:
      slice in class ByteBuff
      Returns:
      a sliced ByteBuff
    • duplicate

      Description copied from class: ByteBuff
      Returns an ByteBuff which is a duplicate version of this ByteBuff. The position, limit and mark of the new ByteBuff will be independent than that of the original ByteBuff. The content of the new ByteBuff will start at this ByteBuff's current position The position, limit and mark of the new ByteBuff would be identical to this ByteBuff in terms of values.
      Specified by:
      duplicate in class ByteBuff
      Returns:
      a sliced ByteBuff
    • get

      public byte get()
      Description copied from class: ByteBuff
      A relative method that returns byte at the current position. Increments the current position by the size of a byte.
      Specified by:
      get in class ByteBuff
      Returns:
      the byte at the current position
    • get

      public byte get(int index)
      Description copied from class: ByteBuff
      Fetches the byte at the given index. Does not change position of the underlying ByteBuffers
      Specified by:
      get in class ByteBuff
      Returns:
      the byte at the given index
    • getByteAfterPosition

      public byte getByteAfterPosition(int offset)
      Description copied from class: ByteBuff
      Fetches the byte at the given offset from current position. Does not change position of the underlying ByteBuffers.
      Specified by:
      getByteAfterPosition in class ByteBuff
      Returns:
      the byte value at the given index.
    • put

      public SingleByteBuff put(byte b)
      Description copied from class: ByteBuff
      Writes a byte to this ByteBuff at the current position and increments the position
      Specified by:
      put in class ByteBuff
      Returns:
      this object
    • put

      public SingleByteBuff put(int index, byte b)
      Description copied from class: ByteBuff
      Writes a byte to this ByteBuff at the given index
      Specified by:
      put in class ByteBuff
      Returns:
      this object
    • get

      public void get(byte[] dst, int offset, int length)
      Description copied from class: ByteBuff
      Copies the specified number of bytes from this ByteBuff's current position to the byte[]'s offset. Also advances the position of the ByteBuff by the given length.
      Specified by:
      get in class ByteBuff
      Parameters:
      dst - the byte[] to which the ByteBuff's content is to be copied
      offset - within the current array
      length - upto which the bytes to be copied
    • get

      public void get(int sourceOffset, byte[] dst, int offset, int length)
      Description copied from class: ByteBuff
      Copies the specified number of bytes from this ByteBuff's given position to the byte[]'s offset. The position of the ByteBuff remains in the current position only
      Specified by:
      get in class ByteBuff
      Parameters:
      sourceOffset - the offset in this ByteBuff from where the copy should happen
      dst - the byte[] to which the ByteBuff's content is to be copied
      offset - within the current array
      length - upto which the bytes to be copied
    • get

      public void get(byte[] dst)
      Description copied from class: ByteBuff
      Copies the content from this ByteBuff's current position to the byte array and fills it. Also advances the position of the ByteBuff by the length of the byte[].
      Specified by:
      get in class ByteBuff
      Parameters:
      dst - the byte[] to which the ByteBuff's content is to be copied
    • put

      public SingleByteBuff put(int offset, ByteBuff src, int srcOffset, int length)
      Description copied from class: ByteBuff
      Copies the contents from the src ByteBuff to this ByteBuff. This will be absolute positional copying and won't affect the position of any of the buffers.
      Specified by:
      put in class ByteBuff
      Parameters:
      offset - the position in this ByteBuff to which the copy should happen
      src - the src ByteBuff
      srcOffset - the offset in the src ByteBuff from where the elements should be read
      length - the length up to which the copy should happen
    • put

      public SingleByteBuff put(byte[] src, int offset, int length)
      Description copied from class: ByteBuff
      Copies from the given byte[] to this ByteBuff
      Specified by:
      put in class ByteBuff
      Parameters:
      src - source byte array
      offset - the position in the byte array from which the copy should be done
      length - the length upto which the copy should happen
      Returns:
      this ByteBuff
    • put

      public SingleByteBuff put(byte[] src)
      Description copied from class: ByteBuff
      Copies from the given byte[] to this ByteBuff
      Specified by:
      put in class ByteBuff
      Parameters:
      src - source byte array
      Returns:
      this ByteBuff
    • hasArray

      public boolean hasArray()
      Description copied from class: ByteBuff
      Returns true or false if the underlying BB support hasArray
      Specified by:
      hasArray in class ByteBuff
    • array

      public byte[] array()
      Description copied from class: ByteBuff
      Returns the byte[] if the underlying BB has single BB and hasArray true
      Specified by:
      array in class ByteBuff
    • arrayOffset

      public int arrayOffset()
      Description copied from class: ByteBuff
      Returns the arrayOffset of the byte[] incase of a single BB backed ByteBuff
      Specified by:
      arrayOffset in class ByteBuff
    • getShort

      public short getShort()
      Description copied from class: ByteBuff
      Returns the short value at the current position. Also advances the position by the size of short.
      Specified by:
      getShort in class ByteBuff
    • getShort

      public short getShort(int index)
      Description copied from class: ByteBuff
      Fetches the short value at the given index. Does not change position of the underlying ByteBuffers. The caller is sure that the index will be after the current position of this ByteBuff. So even if the current short does not fit in the current item we can safely move to the next item and fetch the remaining bytes forming the short
      Specified by:
      getShort in class ByteBuff
      Returns:
      the short value at the given index
    • getShortAfterPosition

      public short getShortAfterPosition(int offset)
      Description copied from class: ByteBuff
      Fetches the short value at the given offset from current position. Does not change position of the underlying ByteBuffers.
      Specified by:
      getShortAfterPosition in class ByteBuff
      Returns:
      the short value at the given index.
    • getInt

      public int getInt()
      Description copied from class: ByteBuff
      Returns the int value at the current position. Also advances the position by the size of int.
      Specified by:
      getInt in class ByteBuff
    • putInt

      public SingleByteBuff putInt(int value)
      Description copied from class: ByteBuff
      Writes an int to this ByteBuff at its current position. Also advances the position by size of int.
      Specified by:
      putInt in class ByteBuff
    • getInt

      public int getInt(int index)
      Description copied from class: ByteBuff
      Fetches the int at the given index. Does not change position of the underlying ByteBuffers. Even if the current int does not fit in the current item we can safely move to the next item and fetch the remaining bytes forming the int.
      Specified by:
      getInt in class ByteBuff
    • getIntAfterPosition

      public int getIntAfterPosition(int offset)
      Description copied from class: ByteBuff
      Fetches the int value at the given offset from current position. Does not change position of the underlying ByteBuffers.
      Specified by:
      getIntAfterPosition in class ByteBuff
    • getLong

      public long getLong()
      Description copied from class: ByteBuff
      Returns the long value at the current position. Also advances the position by the size of long.
      Specified by:
      getLong in class ByteBuff
    • putLong

      public SingleByteBuff putLong(long value)
      Description copied from class: ByteBuff
      Writes a long to this ByteBuff at its current position. Also advances the position by size of long.
      Specified by:
      putLong in class ByteBuff
    • getLong

      public long getLong(int index)
      Description copied from class: ByteBuff
      Fetches the long at the given index. Does not change position of the underlying ByteBuffers. The caller is sure that the index will be after the current position of this ByteBuff. So even if the current long does not fit in the current item we can safely move to the next item and fetch the remaining bytes forming the long
      Specified by:
      getLong in class ByteBuff
      Returns:
      the long value at the given index
    • getLongAfterPosition

      public long getLongAfterPosition(int offset)
      Description copied from class: ByteBuff
      Fetches the long value at the given offset from current position. Does not change position of the underlying ByteBuffers.
      Specified by:
      getLongAfterPosition in class ByteBuff
      Returns:
      the long value at the given index.
    • toBytes

      public byte[] toBytes(int offset, int length)
      Description copied from class: ByteBuff
      Copy the content from this ByteBuff to a byte[] based on the given offset and length.
      Specified by:
      toBytes in class ByteBuff
    • get

      public void get(ByteBuffer out, int sourceOffset, int length)
      Description copied from class: ByteBuff
      Copies the content from this ByteBuff to a ByteBuffer Note : This will advance the position marker of out but not change the position maker for this ByteBuff
      Specified by:
      get in class ByteBuff
      Parameters:
      out - the ByteBuffer to which the copy has to happen
      sourceOffset - the offset in the ByteBuff from which the elements has to be copied
      length - the length in this ByteBuff upto which the elements has to be copied
    • read

      public int read(ReadableByteChannel channel) throws IOException
      Description copied from class: ByteBuff
      Reads bytes from the given channel into this ByteBuf.
      Specified by:
      read in class ByteBuff
      Throws:
      IOException
    • read

      public int read(FileChannel channel, long offset) throws IOException
      Description copied from class: ByteBuff
      Reads bytes from FileChannel into this ByteBuff
      Specified by:
      read in class ByteBuff
      Throws:
      IOException
    • write

      public int write(FileChannel channel, long offset) throws IOException
      Description copied from class: ByteBuff
      Write this ByteBuff's data into target file
      Specified by:
      write in class ByteBuff
      Throws:
      IOException
    • nioByteBuffers

      Specified by:
      nioByteBuffers in class ByteBuff
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • retain