org.apache.oozie.util
Class WritableUtils

java.lang.Object
  extended by org.apache.oozie.util.WritableUtils

public class WritableUtils
extends Object

Utility class to write/read Hadoop writables to/from a byte array.


Constructor Summary
WritableUtils()
           
 
Method Summary
static
<T extends org.apache.hadoop.io.Writable>
T
fromByteArray(byte[] array, Class<T> clazz)
          Read a writable from a byte array.
static String readStr(DataInput dataInput)
          Read a string from a data input supporting null values.
static byte[] toByteArray(org.apache.hadoop.io.Writable writable)
          Write a writable to a byte array.
static void writeStr(DataOutput dataOutput, String str)
          Write a string to a data output supporting null values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WritableUtils

public WritableUtils()
Method Detail

toByteArray

public static byte[] toByteArray(org.apache.hadoop.io.Writable writable)
Write a writable to a byte array.

Parameters:
writable - writable to write.
Returns:
array containing the serialized writable.

fromByteArray

public static <T extends org.apache.hadoop.io.Writable> T fromByteArray(byte[] array,
                                                                        Class<T> clazz)
Read a writable from a byte array.

Parameters:
array - byte array with the serialized writable.
clazz - writable class.
Returns:
writable deserialized from the byte array.

writeStr

public static void writeStr(DataOutput dataOutput,
                            String str)
                     throws IOException
Write a string to a data output supporting null values.

It uses the '||' token to represent null.

Parameters:
dataOutput - data output.
str - string to write.
Throws:
IOException - thrown if the string could not be written.

readStr

public static String readStr(DataInput dataInput)
                      throws IOException
Read a string from a data input supporting null values.

It uses the '||' token to represent null.

Parameters:
dataInput - data input.
Returns:
read string, null if the '||' token was read.
Throws:
IOException - thrown if the string could not be read.


Copyright © 2013 Apache Software Foundation. All Rights Reserved.