org.apache.hadoop.hbase.util
Class Writables

java.lang.Object
  extended by org.apache.hadoop.hbase.util.Writables

public class Writables
extends Object

Utility class with methods for manipulating Writable objects


Constructor Summary
Writables()
           
 
Method Summary
static long cellToLong(Cell c)
           
static String cellToString(Cell c)
           
static org.apache.hadoop.io.Writable copyWritable(byte[] bytes, org.apache.hadoop.io.Writable tgt)
          Copy one Writable to another.
static org.apache.hadoop.io.Writable copyWritable(org.apache.hadoop.io.Writable src, org.apache.hadoop.io.Writable tgt)
          Copy one Writable to another.
static byte[] getBytes(org.apache.hadoop.io.Writable w)
           
static HRegionInfo getHRegionInfo(byte[] bytes)
           
static HRegionInfo getHRegionInfo(Cell cell)
           
static HRegionInfo getHRegionInfoOrNull(byte[] bytes)
           
static org.apache.hadoop.io.Writable getWritable(byte[] bytes, int offset, int length, org.apache.hadoop.io.Writable w)
          Set bytes into the passed Writable by calling its Writable.readFields(java.io.DataInput).
static org.apache.hadoop.io.Writable getWritable(byte[] bytes, org.apache.hadoop.io.Writable w)
          Set bytes into the passed Writable by calling its Writable.readFields(java.io.DataInput).
static long readVLong(DataInput stream, byte firstByte)
          Reads a zero-compressed encoded long from input stream and returns it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Writables

public Writables()
Method Detail

getBytes

public static byte[] getBytes(org.apache.hadoop.io.Writable w)
                       throws IOException
Parameters:
w -
Returns:
The bytes of w gotten by running its Writable.write(java.io.DataOutput) method.
Throws:
IOException
See Also:
getWritable(byte[], Writable)

getWritable

public static org.apache.hadoop.io.Writable getWritable(byte[] bytes,
                                                        org.apache.hadoop.io.Writable w)
                                                 throws IOException
Set bytes into the passed Writable by calling its Writable.readFields(java.io.DataInput).

Parameters:
bytes -
w - An empty Writable (usually made by calling the null-arg constructor).
Returns:
The passed Writable after its readFields has been called fed by the passed bytes array or IllegalArgumentException if passed null or an empty bytes array.
Throws:
IOException
IllegalArgumentException

getWritable

public static org.apache.hadoop.io.Writable getWritable(byte[] bytes,
                                                        int offset,
                                                        int length,
                                                        org.apache.hadoop.io.Writable w)
                                                 throws IOException
Set bytes into the passed Writable by calling its Writable.readFields(java.io.DataInput).

Parameters:
bytes -
offset -
length -
w - An empty Writable (usually made by calling the null-arg constructor).
Returns:
The passed Writable after its readFields has been called fed by the passed bytes array or IllegalArgumentException if passed null or an empty bytes array.
Throws:
IOException
IllegalArgumentException

getHRegionInfo

public static HRegionInfo getHRegionInfo(byte[] bytes)
                                  throws IOException
Parameters:
bytes -
Returns:
A HRegionInfo instance built out of passed bytes.
Throws:
IOException

getHRegionInfoOrNull

public static HRegionInfo getHRegionInfoOrNull(byte[] bytes)
                                        throws IOException
Parameters:
bytes -
Returns:
A HRegionInfo instance built out of passed bytes or null if passed bytes are null or an empty array.
Throws:
IOException

getHRegionInfo

public static HRegionInfo getHRegionInfo(Cell cell)
                                  throws IOException
Parameters:
cell - Cell object containing the serialized HRegionInfo
Returns:
A HRegionInfo instance built out of passed cell.
Throws:
IOException

copyWritable

public static org.apache.hadoop.io.Writable copyWritable(org.apache.hadoop.io.Writable src,
                                                         org.apache.hadoop.io.Writable tgt)
                                                  throws IOException
Copy one Writable to another. Copies bytes using data streams.

Parameters:
src - Source Writable
tgt - Target Writable
Returns:
The target Writable.
Throws:
IOException

copyWritable

public static org.apache.hadoop.io.Writable copyWritable(byte[] bytes,
                                                         org.apache.hadoop.io.Writable tgt)
                                                  throws IOException
Copy one Writable to another. Copies bytes using data streams.

Parameters:
bytes - Source Writable
tgt - Target Writable
Returns:
The target Writable.
Throws:
IOException

cellToString

public static String cellToString(Cell c)
Parameters:
c -
Returns:
Cell value as a UTF-8 String

cellToLong

public static long cellToLong(Cell c)
Parameters:
c -
Returns:
Cell as a long.

readVLong

public static long readVLong(DataInput stream,
                             byte firstByte)
                      throws IOException
Reads a zero-compressed encoded long from input stream and returns it. This method is a copy of WritableUtils.readVLong(java.io.DataInput) changed to allow the first byte to be provided as an argument. todo add this method to hadoop WritableUtils and refactor the base method to use it.

Parameters:
stream - Binary input stream
firstByte - the first byte of the vlong
Returns:
deserialized long from stream.
Throws:
IOException - io error


Copyright © 2010 The Apache Software Foundation