Class ImmutableBytesWritable

java.lang.Object
org.apache.hadoop.hbase.io.ImmutableBytesWritable
All Implemented Interfaces:
Comparable<ImmutableBytesWritable>, org.apache.hadoop.io.Writable, org.apache.hadoop.io.WritableComparable<ImmutableBytesWritable>

@Public public class ImmutableBytesWritable extends Object implements org.apache.hadoop.io.WritableComparable<ImmutableBytesWritable>
A byte sequence that is usable as a key or value. Based on BytesWritable only this class is NOT resizable and DOES NOT distinguish between the size of the sequence and the current capacity as BytesWritable does. Hence its comparatively 'immutable'. When creating a new instance of this class, the underlying byte [] is not copied, just referenced. The backing buffer is accessed when we go to serialize.
  • Field Details

    • bytes

      private byte[] bytes
    • offset

      private int offset
    • length

      private int length
  • Constructor Details

    • ImmutableBytesWritable

      Create a zero-size sequence.
    • ImmutableBytesWritable

      public ImmutableBytesWritable(byte[] bytes)
      Create a ImmutableBytesWritable using the byte array as the initial value.
      Parameters:
      bytes - This array becomes the backing storage for the object.
    • ImmutableBytesWritable

      Set the new ImmutableBytesWritable to the contents of the passed ibw.
      Parameters:
      ibw - the value to set this ImmutableBytesWritable to.
    • ImmutableBytesWritable

      public ImmutableBytesWritable(byte[] bytes, int offset, int length)
      Set the value to a given byte range
      Parameters:
      bytes - the new byte range to set to
      offset - the offset in newData to start at
      length - the number of bytes in the range
  • Method Details

    • get

      public byte[] get()
      Get the data from the BytesWritable.
      Returns:
      The data is only valid between offset and offset+length.
    • set

      public void set(byte[] b)
      Use passed bytes as backing array for this instance.
    • set

      public void set(byte[] b, int offset, int length)
      Use passed bytes as backing array for this instance.
    • getLength

      public int getLength()
      Returns the number of valid bytes in the buffer
    • getOffset

      public int getOffset()
      Return the offset into the buffer.
    • readFields

      public void readFields(DataInput in) throws IOException
      Specified by:
      readFields in interface org.apache.hadoop.io.Writable
      Throws:
      IOException
    • write

      public void write(DataOutput out) throws IOException
      Specified by:
      write in interface org.apache.hadoop.io.Writable
      Throws:
      IOException
    • hashCode

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

      public int compareTo(ImmutableBytesWritable that)
      Define the sort order of the BytesWritable.
      Specified by:
      compareTo in interface Comparable<ImmutableBytesWritable>
      Parameters:
      that - The other bytes writable
      Returns:
      Positive if left is bigger than right, 0 if they are equal, and negative if left is smaller than right.
    • compareTo

      public int compareTo(byte[] that)
      Compares the bytes in this object to the specified byte array
      Returns:
      Positive if left is bigger than right, 0 if they are equal, and negative if left is smaller than right.
    • equals

      public boolean equals(Object right_obj)
      Overrides:
      equals in class Object
    • toString

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

      public static byte[][] toArray(List<byte[]> array)
      Convert a list of byte arrays into an array of byte arrays
      Parameters:
      array - List of byte [].
      Returns:
      Array of byte [].
    • copyBytes

      public byte[] copyBytes()
      Returns a copy of the bytes referred to by this writable