org.apache.hadoop.record
Class Buffer

java.lang.Object
  extended by org.apache.hadoop.record.Buffer
All Implemented Interfaces:
Cloneable, Comparable

public class Buffer
extends Object
implements Comparable, Cloneable

A byte sequence that is used as a Java native type for buffer. It is resizable and distinguishes between the count of the seqeunce and the current capacity.


Constructor Summary
Buffer()
          Create a zero-count sequence.
Buffer(byte[] bytes)
          Create a Buffer using the byte array as the initial value.
Buffer(byte[] bytes, int offset, int length)
          Create a Buffer using the byte range as the initial value.
 
Method Summary
 void append(byte[] bytes)
          Append specified bytes to the buffer
 void append(byte[] bytes, int offset, int length)
          Append specified bytes to the buffer.
 Object clone()
           
 int compareTo(Object other)
          Define the sort order of the Buffer.
 void copy(byte[] bytes, int offset, int length)
          Copy the specified byte array to the Buffer.
 boolean equals(Object other)
           
 byte[] get()
          Get the data from the Buffer.
 int getCapacity()
          Get the capacity, which is the maximum count that could handled without resizing the backing storage.
 int getCount()
          Get the current count of the buffer.
 int hashCode()
           
 void reset()
          Reset the buffer to 0 size
 void set(byte[] bytes)
          Use the specified bytes array as underlying sequence.
 void setCapacity(int newCapacity)
          Change the capacity of the backing storage.
 String toString()
           
 String toString(String charsetName)
          Convert the byte buffer to a string an specific character encoding
 void truncate()
          Change the capacity of the backing store to be the same as the current count of buffer.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Buffer

public Buffer()
Create a zero-count sequence.


Buffer

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

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

Buffer

public Buffer(byte[] bytes,
              int offset,
              int length)
Create a Buffer using the byte range as the initial value.

Parameters:
bytes - Copy of this array becomes the backing storage for the object.
offset - offset into byte array
length - length of data
Method Detail

set

public void set(byte[] bytes)
Use the specified bytes array as underlying sequence.

Parameters:
bytes - byte sequence

copy

public final void copy(byte[] bytes,
                       int offset,
                       int length)
Copy the specified byte array to the Buffer. Replaces the current buffer.

Parameters:
bytes - byte array to be assigned
offset - offset into byte array
length - length of data

get

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

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

getCount

public int getCount()
Get the current count of the buffer.


getCapacity

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

Returns:
The number of bytes

setCapacity

public void setCapacity(int newCapacity)
Change the capacity of the backing storage. The data is preserved if newCapacity >= getCount().

Parameters:
newCapacity - The new capacity in bytes.

reset

public void reset()
Reset the buffer to 0 size


truncate

public void truncate()
Change the capacity of the backing store to be the same as the current count of buffer.


append

public void append(byte[] bytes,
                   int offset,
                   int length)
Append specified bytes to the buffer.

Parameters:
bytes - byte array to be appended
offset - offset into byte array
length - length of data

append

public void append(byte[] bytes)
Append specified bytes to the buffer

Parameters:
bytes - byte array to be appended

hashCode

public int hashCode()
Overrides:
hashCode in class Object

compareTo

public int compareTo(Object other)
Define the sort order of the Buffer.

Specified by:
compareTo in interface Comparable
Parameters:
other - The other buffer
Returns:
Positive if this is bigger than other, 0 if they are equal, and negative if this is smaller than other.

equals

public boolean equals(Object other)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

toString

public String toString(String charsetName)
                throws UnsupportedEncodingException
Convert the byte buffer to a string an specific character encoding

Parameters:
charsetName - Valid Java Character Set Name
Throws:
UnsupportedEncodingException

clone

public Object clone()
             throws CloneNotSupportedException
Overrides:
clone in class Object
Throws:
CloneNotSupportedException


Copyright © 2009 The Apache Software Foundation