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 bytesToLong(byte[] bytes)
          Converts a byte array to a long value
static String bytesToString(byte[] bytes)
          Converts a byte array to a string in a consistent manner.
static Writable copyWritable(Writable src, Writable tgt)
          Copy one Writable to another.
static byte[] getBytes(Writable w)
           
static HRegionInfo getHRegionInfo(byte[] bytes)
           
static HRegionInfo getHRegionInfoOrNull(byte[] bytes)
           
static Writable getWritable(byte[] bytes, Writable w)
          Set bytes into the passed Writable by calling its Writable.readFields(java.io.DataInput).
static byte[] longToBytes(long val)
          Convert a long value to a byte array
static byte[] stringToBytes(String s)
          Converts a string to a byte array in a consistent manner.
 
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(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 Writable getWritable(byte[] bytes,
                                   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

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

copyWritable

public static Writable copyWritable(Writable src,
                                    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

longToBytes

public static byte[] longToBytes(long val)
                          throws IOException
Convert a long value to a byte array

Parameters:
val -
Returns:
the byte array
Throws:
IOException

bytesToLong

public static long bytesToLong(byte[] bytes)
                        throws IOException
Converts a byte array to a long value

Parameters:
bytes -
Returns:
the long value
Throws:
IOException

stringToBytes

public static byte[] stringToBytes(String s)
                            throws UnsupportedEncodingException
Converts a string to a byte array in a consistent manner.

Parameters:
s -
Returns:
the byte array
Throws:
UnsupportedEncodingException

bytesToString

public static String bytesToString(byte[] bytes)
                            throws UnsupportedEncodingException
Converts a byte array to a string in a consistent manner.

Parameters:
bytes -
Returns:
the string
Throws:
UnsupportedEncodingException


Copyright © 2006 The Apache Software Foundation