org.apache.hadoop.hbase.io
Class ImmutableBytesWritable

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

@InterfaceAudience.Public
@InterfaceStability.Stable
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.


Nested Class Summary
static class ImmutableBytesWritable.Comparator
          A Comparator optimized for ImmutableBytesWritable.
 
Constructor Summary
ImmutableBytesWritable()
          Create a zero-size sequence.
ImmutableBytesWritable(byte[] bytes)
          Create a ImmutableBytesWritable using the byte array as the initial value.
ImmutableBytesWritable(byte[] bytes, int offset, int length)
          Set the value to a given byte range
ImmutableBytesWritable(ImmutableBytesWritable ibw)
          Set the new ImmutableBytesWritable to the contents of the passed ibw.
 
Method Summary
 int compareTo(byte[] that)
          Compares the bytes in this object to the specified byte array
 int compareTo(ImmutableBytesWritable that)
          Define the sort order of the BytesWritable.
 byte[] copyBytes()
          Returns a copy of the bytes referred to by this writable
 boolean equals(Object right_obj)
           
 byte[] get()
          Get the data from the BytesWritable.
 int getLength()
           
 int getOffset()
           
 int getSize()
          Deprecated. use getLength() instead
 int hashCode()
           
 void readFields(DataInput in)
           
 void set(byte[] b)
           
 void set(byte[] b, int offset, int length)
           
static byte[][] toArray(List<byte[]> array)
           
 String toString()
           
 void write(DataOutput out)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ImmutableBytesWritable

public 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

public ImmutableBytesWritable(ImmutableBytesWritable ibw)
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 Detail

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)
Parameters:
b - Use passed bytes as backing array for this instance.

set

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

getSize

@Deprecated
public int getSize()
Deprecated. use getLength() instead

Returns:
the number of valid bytes in the buffer

getLength

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

getOffset

public int getOffset()
Returns:
offset

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

Parameters:
that -
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
See Also:
Object.equals(java.lang.Object)

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()

toArray

public static byte[][] toArray(List<byte[]> array)
Parameters:
array - List of byte [].
Returns:
Array of byte [].

copyBytes

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



Copyright © 2007-2015 The Apache Software Foundation. All Rights Reserved.