org.apache.hadoop.io
Class BytesWritable

java.lang.Object
  extended by org.apache.hadoop.io.BytesWritable
All Implemented Interfaces:
Comparable, Writable, WritableComparable

public class BytesWritable
extends Object
implements WritableComparable

A byte sequence that is usable as a key or value. It is resizable and distinguishes between the size of the seqeunce and the current capacity. The hash function is the front of the md5 of the buffer. The sort order is the same as memcmp.


Nested Class Summary
static class BytesWritable.Comparator
          A Comparator optimized for BytesWritable.
 
Constructor Summary
BytesWritable()
          Create a zero-size sequence.
BytesWritable(byte[] bytes)
          Create a BytesWritable using the byte array as the initial value.
 
Method Summary
 int compareTo(Object right_obj)
          Define the sort order of the BytesWritable.
 boolean equals(Object right_obj)
          Are the two byte sequences equal?
 byte[] get()
          Get the data from the BytesWritable.
 int getCapacity()
          Get the capacity, which is the maximum size that could handled without resizing the backing storage.
 int getSize()
          Get the current size of the buffer.
 int hashCode()
           
 void readFields(DataInput in)
          Deserialize the fields of this object from in.
 void set(byte[] newData, int offset, int length)
          Set the value to a copy of the given byte range
 void set(BytesWritable newData)
          Set the BytesWritable to the contents of the given newData.
 void setCapacity(int new_cap)
          Change the capacity of the backing storage.
 void setSize(int size)
          Change the size of the buffer.
 String toString()
          Generate the stream of bytes as hex pairs separated by ' '.
 void write(DataOutput out)
          Serialize the fields of this object to out.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BytesWritable

public BytesWritable()
Create a zero-size sequence.


BytesWritable

public BytesWritable(byte[] bytes)
Create a BytesWritable using the byte array as the initial value.

Parameters:
bytes - This array becomes the backing storage for the object.
Method Detail

get

public byte[] get()
Get the data from the BytesWritable.

Returns:
The data is only valid between 0 and getSize() - 1.

getSize

public int getSize()
Get the current size of the buffer.


setSize

public void setSize(int size)
Change the size of the buffer. The values in the old range are preserved and any new values are undefined. The capacity is changed if it is necessary.

Parameters:
size - The new number of bytes

getCapacity

public int getCapacity()
Get the capacity, which is the maximum size that could handled without resizing the backing storage.

Returns:
The number of bytes

setCapacity

public void setCapacity(int new_cap)
Change the capacity of the backing storage. The data is preserved.

Parameters:
new_cap - The new capacity in bytes.

set

public void set(BytesWritable newData)
Set the BytesWritable to the contents of the given newData.

Parameters:
newData - the value to set this BytesWritable to.

set

public void set(byte[] newData,
                int offset,
                int length)
Set the value to a copy of the given byte range

Parameters:
newData - the new values to copy in
offset - the offset in newData to start at
length - the number of bytes to copy

readFields

public void readFields(DataInput in)
                throws IOException
Description copied from interface: Writable
Deserialize the fields of this object from in.

For efficiency, implementations should attempt to re-use storage in the existing object where possible.

Specified by:
readFields in interface Writable
Parameters:
in - DataInput to deseriablize this object from.
Throws:
IOException

write

public void write(DataOutput out)
           throws IOException
Description copied from interface: Writable
Serialize the fields of this object to out.

Specified by:
write in interface Writable
Parameters:
out - DataOuput to serialize this object into.
Throws:
IOException

hashCode

public int hashCode()
Overrides:
hashCode in class Object

compareTo

public int compareTo(Object right_obj)
Define the sort order of the BytesWritable.

Specified by:
compareTo in interface Comparable
Parameters:
right_obj - 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.

equals

public boolean equals(Object right_obj)
Are the two byte sequences equal?

Overrides:
equals in class Object

toString

public String toString()
Generate the stream of bytes as hex pairs separated by ' '.

Overrides:
toString in class Object


Copyright © 2008 The Apache Software Foundation