Class ByteBufferUtils

java.lang.Object
org.apache.hadoop.hbase.util.ByteBufferUtils

@Deprecated @Public public final class ByteBufferUtils extends Object
Deprecated.
This class will become IA.Private in HBase 3.0. Downstream folks shouldn't use it.
Utility functions for working with byte buffers, such as reading/writing variable-length long numbers.
  • Field Details

  • Constructor Details

  • Method Details

    • writeVLong

      public static void writeVLong(ByteBuffer out, long i)
      Deprecated.
      Similar to WritableUtils.writeVLong(java.io.DataOutput, long), but writes to a ByteBuffer.
    • readVLong

      public static long readVLong(ByteBuff buf)
      Deprecated.
      Similar to WritableUtils.readVLong(java.io.DataInput) but reads from a ByteBuff.
    • readVLong

      public static long readVLong(ByteBuffer buf)
      Deprecated.
      Similar to WritableUtils.readVLong(DataInput) but reads from a ByteBuffer.
    • putCompressedInt

      public static int putCompressedInt(OutputStream out, int value) throws IOException
      Deprecated.
      Put in buffer integer using 7 bit encoding. For each written byte: 7 bits are used to store value 1 bit is used to indicate whether there is next bit.
      Parameters:
      value - Int to be compressed.
      out - Where to put compressed data
      Returns:
      Number of bytes written.
      Throws:
      IOException - on stream error
    • putInt

      public static void putInt(OutputStream out, int value) throws IOException
      Deprecated.
      Put in output stream 32 bit integer (Big Endian byte order).
      Parameters:
      out - Where to put integer.
      value - Value of integer.
      Throws:
      IOException - On stream error.
    • toByte

      public static byte toByte(ByteBuffer buffer, int offset)
      Deprecated.
    • moveBufferToStream

      public static void moveBufferToStream(OutputStream out, ByteBuffer in, int length) throws IOException
      Deprecated.
      Copy the data to the output stream and update position in buffer.
      Parameters:
      out - the stream to write bytes to
      in - the buffer to read bytes from
      length - the number of bytes to copy
      Throws:
      IOException
    • copyBufferToStream

      public static void copyBufferToStream(OutputStream out, ByteBuffer in, int offset, int length) throws IOException
      Deprecated.
      Copy data from a buffer to an output stream. Does not update the position in the buffer.
      Parameters:
      out - the stream to write bytes to
      in - the buffer to read bytes from
      offset - the offset in the buffer (from the buffer's array offset) to start copying bytes from
      length - the number of bytes to copy
      Throws:
      IOException
    • copyBufferToStream

      public static void copyBufferToStream(DataOutput out, ByteBuffer in, int offset, int length) throws IOException
      Deprecated.
      Copy data from a buffer to an output stream. Does not update the position in the buffer.
      Parameters:
      out - the output stream to write bytes to
      in - the buffer to read bytes from
      offset - the offset in the buffer (from the buffer's array offset) to start copying bytes from
      length - the number of bytes to copy
      Throws:
      IOException
    • putLong

      public static int putLong(OutputStream out, long value, int fitInBytes) throws IOException
      Deprecated.
      Throws:
      IOException
    • putByte

      public static int putByte(ByteBuffer buffer, int offset, byte b)
      Deprecated.
    • longFitsIn

      public static int longFitsIn(long value)
      Deprecated.
      Check how many bytes are required to store value.
      Parameters:
      value - Value which size will be tested.
      Returns:
      How many bytes are required to store value.
    • intFitsIn

      public static int intFitsIn(int value)
      Deprecated.
      Check how many bytes is required to store value.
      Parameters:
      value - Value which size will be tested.
      Returns:
      How many bytes are required to store value.
    • readCompressedInt

      public static int readCompressedInt(InputStream input) throws IOException
      Deprecated.
      Read integer from stream coded in 7 bits and increment position.
      Returns:
      the integer that has been read
      Throws:
      IOException - on stream error
    • readCompressedInt

      public static int readCompressedInt(ByteBuffer buffer)
      Deprecated.
      Read integer from buffer coded in 7 bits and increment position.
      Returns:
      Read integer.
    • readLong

      public static long readLong(InputStream in, int fitInBytes) throws IOException
      Deprecated.
      Read long which was written to fitInBytes bytes and increment position.
      Parameters:
      fitInBytes - In how many bytes given long is stored.
      Returns:
      The value of parsed long.
      Throws:
      IOException - on stream error
    • readLong

      public static long readLong(ByteBuffer in, int fitInBytes)
      Deprecated.
      Read long which was written to fitInBytes bytes and increment position.
      Parameters:
      fitInBytes - In how many bytes given long is stored.
      Returns:
      The value of parsed long.
    • copyFromStreamToBuffer

      public static void copyFromStreamToBuffer(ByteBuffer out, DataInputStream in, int length) throws IOException
      Deprecated.
      Copy the given number of bytes from the given stream and put it at the current position of the given buffer, updating the position in the buffer.
      Parameters:
      out - the buffer to write data to
      in - the stream to read data from
      length - the number of bytes to read/write
      Throws:
      IOException
    • drainInputStreamToBuffer

      Deprecated.
      Copy from the InputStream to a new heap ByteBuffer until the InputStream is exhausted.
      Throws:
      IOException
    • copyFromBufferToBuffer

      public static void copyFromBufferToBuffer(ByteBuffer in, ByteBuffer out)
      Deprecated.
      Copy one buffer's whole data to another. Write starts at the current position of 'out' buffer. Note : This will advance the position marker of out and also change the position maker for in.
      Parameters:
      in - source buffer
      out - destination buffer
    • copyFromBufferToBuffer

      public static void copyFromBufferToBuffer(ByteBuffer in, ByteBuffer out, int sourceOffset, int destinationOffset, int length)
      Deprecated.
      Copy from one buffer to another from given offset. This will be absolute positional copying and won't affect the position of any of the buffers.
      Parameters:
      in - input bytebuffer
      out - destination bytebuffer
      sourceOffset - offset of source buffer
      destinationOffset - offset of destination buffer
      length - the number of bytes to copy
    • copyFromBufferToBuffer

      public static void copyFromBufferToBuffer(ByteBuffer in, ByteBuffer out, int sourceOffset, int length)
      Deprecated.
      Copy from one buffer to another from given offset.

      Note : This will advance the position marker of out but not change the position maker for in

      Parameters:
      in - source buffer
      out - destination buffer
      sourceOffset - offset in the source buffer
      length - how many bytes to copy
    • findCommonPrefix

      public static int findCommonPrefix(ByteBuffer buffer, int offsetLeft, int offsetRight, int limit)
      Deprecated.
      Find length of common prefix of two parts in the buffer
      Parameters:
      buffer - Where parts are located.
      offsetLeft - Offset of the first part.
      offsetRight - Offset of the second part.
      limit - Maximal length of common prefix.
      Returns:
      Length of prefix.
    • findCommonPrefix

      public static int findCommonPrefix(byte[] left, int leftOffset, int leftLength, byte[] right, int rightOffset, int rightLength)
      Deprecated.
      Find length of common prefix in two arrays.
      Parameters:
      left - Array to be compared.
      leftOffset - Offset in left array.
      leftLength - Length of left array.
      right - Array to be compared.
      rightOffset - Offset in right array.
      rightLength - Length of right array.
    • findCommonPrefix

      public static int findCommonPrefix(ByteBuffer left, int leftOffset, int leftLength, ByteBuffer right, int rightOffset, int rightLength)
      Deprecated.
      Find length of common prefix in two arrays.
      Parameters:
      left - ByteBuffer to be compared.
      leftOffset - Offset in left ByteBuffer.
      leftLength - Length of left ByteBuffer.
      right - ByteBuffer to be compared.
      rightOffset - Offset in right ByteBuffer.
      rightLength - Length of right ByteBuffer.
    • findCommonPrefix

      public static int findCommonPrefix(ByteBuffer left, int leftOffset, int leftLength, byte[] right, int rightOffset, int rightLength)
      Deprecated.
      Find length of common prefix in two arrays.
      Parameters:
      left - ByteBuffer to be compared.
      leftOffset - Offset in left ByteBuffer.
      leftLength - Length of left ByteBuffer.
      right - Array to be compared
      rightOffset - Offset in right Array.
      rightLength - Length of right Array.
    • arePartsEqual

      public static boolean arePartsEqual(ByteBuffer buffer, int offsetLeft, int lengthLeft, int offsetRight, int lengthRight)
      Deprecated.
      Check whether two parts in the same buffer are equal.
      Parameters:
      buffer - In which buffer there are parts
      offsetLeft - Beginning of first part.
      lengthLeft - Length of the first part.
      offsetRight - Beginning of the second part.
      lengthRight - Length of the second part.
      Returns:
      True if equal
    • skip

      public static void skip(ByteBuffer buffer, int length)
      Deprecated.
      Increment position in buffer.
      Parameters:
      buffer - In this buffer.
      length - By that many bytes.
    • extendLimit

      public static void extendLimit(ByteBuffer buffer, int numBytes)
      Deprecated.
    • toBytes

      public static byte[] toBytes(ByteBuffer buffer, int startPosition)
      Deprecated.
      Copy the bytes from position to limit into a new byte[] of the exact length and sets the position and limit back to their original values (though not thread safe).
      Parameters:
      buffer - copy from here
      startPosition - put buffer.get(startPosition) into byte[0]
      Returns:
      a new byte[] containing the bytes in the specified range
    • toBytes

      public static byte[] toBytes(ByteBuffer buffer, int offset, int length)
      Deprecated.
      Copy the given number of bytes from specified offset into a new byte[]
      Parameters:
      buffer - input bytebuffer to read
      offset - input offset where Bytes are
      length - the number of bytes to read
      Returns:
      a new byte[] containing the bytes in the specified range
    • equals

      public static boolean equals(ByteBuffer buf1, int o1, int l1, ByteBuffer buf2, int o2, int l2)
      Deprecated.
    • hashCode

      public static int hashCode(ByteBuffer buf, int offset, int length)
      Deprecated.
      ByteBuffer to hash offset to start from length to hash
    • compareTo

      public static int compareTo(ByteBuffer buf1, int o1, int l1, ByteBuffer buf2, int o2, int l2)
      Deprecated.
    • equals

      public static boolean equals(ByteBuffer buf1, int o1, int l1, byte[] buf2, int o2, int l2)
      Deprecated.
    • compareTo

      public static int compareTo(byte[] buf1, int o1, int l1, ByteBuffer buf2, int o2, int l2)
      Deprecated.
    • compareTo

      public static int compareTo(ByteBuffer buf1, int o1, int l1, byte[] buf2, int o2, int l2)
      Deprecated.
    • compareToUnsafe

      static int compareToUnsafe(Object obj1, long o1, int l1, Object obj2, long o2, int l2)
      Deprecated.
    • findCommonPrefixUnsafe

      static int findCommonPrefixUnsafe(Object left, long leftOffset, int leftLength, Object right, long rightOffset, int rightLength)
      Deprecated.
    • toShort

      public static short toShort(ByteBuffer buffer, int offset)
      Deprecated.
      Reads a short value at the given buffer's offset.
      Parameters:
      buffer - input byte buffer to read
      offset - input offset where short is
      Returns:
      short value at offset
    • toInt

      public static int toInt(ByteBuffer buffer)
      Deprecated.
      Reads an int value at the given buffer's current position. Also advances the buffer's position
    • toInt

      public static int toInt(ByteBuffer buffer, int offset)
      Deprecated.
      Reads an int value at the given buffer's offset.
      Parameters:
      buffer - input byte buffer to read
      offset - input offset where int is
      Returns:
      int value at offset
    • readAsInt

      public static int readAsInt(ByteBuffer buf, int offset, int length)
      Deprecated.
      Converts a ByteBuffer to an int value
      Parameters:
      buf - The ByteBuffer
      offset - Offset to int value
      length - Number of bytes used to store the int value.
      Returns:
      the int value if there's not enough bytes left in the buffer after the given offset
    • toLong

      public static long toLong(ByteBuffer buffer, int offset)
      Deprecated.
      Reads a long value at the given buffer's offset.
      Parameters:
      buffer - input byte buffer to read
      offset - input offset where Long is
      Returns:
      long value at offset
    • putInt

      public static void putInt(ByteBuffer buffer, int val)
      Deprecated.
      Put an int value out to the given ByteBuffer's current position in big-endian format. This also advances the position in buffer by int size.
      Parameters:
      buffer - the ByteBuffer to write to
      val - int to write out
    • putInt

      public static int putInt(ByteBuffer buffer, int index, int val)
      Deprecated.
    • toDouble

      public static double toDouble(ByteBuffer buffer, int offset)
      Deprecated.
      Reads a double value at the given buffer's offset.
      Parameters:
      buffer - input byte buffer to read
      offset - offset where double is
      Returns:
      double value at offset
    • toBigDecimal

      public static BigDecimal toBigDecimal(ByteBuffer buffer, int offset, int length)
      Deprecated.
      Reads a BigDecimal value at the given buffer's offset.
      Parameters:
      buffer - input bytebuffer to read
      offset - input offset
      Returns:
      BigDecimal value at offset
    • putShort

      public static void putShort(ByteBuffer buffer, short val)
      Deprecated.
      Put a short value out to the given ByteBuffer's current position in big-endian format. This also advances the position in buffer by short size.
      Parameters:
      buffer - the ByteBuffer to write to
      val - short to write out
    • putShort

      public static int putShort(ByteBuffer buffer, int index, short val)
      Deprecated.
    • putAsShort

      public static int putAsShort(ByteBuffer buf, int index, int val)
      Deprecated.
    • putLong

      public static void putLong(ByteBuffer buffer, long val)
      Deprecated.
      Put a long value out to the given ByteBuffer's current position in big-endian format. This also advances the position in buffer by long size.
      Parameters:
      buffer - the ByteBuffer to write to
      val - long to write out
    • putLong

      public static int putLong(ByteBuffer buffer, int index, long val)
      Deprecated.
    • copyFromArrayToBuffer

      public static void copyFromArrayToBuffer(ByteBuffer out, byte[] in, int inOffset, int length)
      Deprecated.
      Copies the bytes from given array's offset to length part into the given buffer. Puts the bytes to buffer's current position. This also advances the position in the 'out' buffer by 'length'
      Parameters:
      out - output bytebuffer to copy to
      in - input array to copy from
      inOffset - input offset to copy from
      length - the number of bytes to copy
    • copyFromArrayToBuffer

      public static void copyFromArrayToBuffer(ByteBuffer out, int outOffset, byte[] in, int inOffset, int length)
      Deprecated.
      Copies bytes from given array's offset to length part into the given buffer. Puts the bytes to buffer's given position. This doesn't affect the position of buffer.
      Parameters:
      out - output bytebuffer to copy to
      outOffset - output buffer offset
      in - input array to copy from
      inOffset - input offset to copy from
      length - the number of bytes to copy
    • copyFromBufferToArray

      public static void copyFromBufferToArray(byte[] out, ByteBuffer in, int sourceOffset, int destinationOffset, int length)
      Deprecated.
      Copies specified number of bytes from given offset of 'in' ByteBuffer to the array. This doesn't affect the position of buffer.
      Parameters:
      out - output array to copy input bytebuffer to
      in - input bytebuffer to copy from
      sourceOffset - offset of source bytebuffer
      destinationOffset - offset of destination array
      length - the number of bytes to copy
    • copyOfRange

      public static byte[] copyOfRange(ByteBuffer original, int from, int to)
      Deprecated.
      Parameters:
      original - the buffer from which the copy has to happen
      from - the starting index
      to - the ending index
      Returns:
      a byte[] created out of the copy
    • toStringBinary

      public static String toStringBinary(ByteBuffer b, int off, int len)
      Deprecated.
    • toStringBinary

      public static String toStringBinary(ByteBuffer b)
      Deprecated.
    • searchDelimiterIndex

      public static int searchDelimiterIndex(ByteBuffer b, int offset, int length, int delimiter)
      Deprecated.
      Find index of passed delimiter.
      Returns:
      Index of delimiter having started from start of b moving rightward.
    • searchDelimiterIndexInReverse

      public static int searchDelimiterIndexInReverse(ByteBuffer b, int offset, int length, int delimiter)
      Deprecated.
      Find index of passed delimiter walking from end of buffer backwards.
      Returns:
      Index of delimiter