org.apache.hadoop.io
Class DefaultStringifier<T>

java.lang.Object
  extended by org.apache.hadoop.io.DefaultStringifier<T>
Type Parameters:
T - the class of the objects to stringify
All Implemented Interfaces:
Closeable, Stringifier<T>

public class DefaultStringifier<T>
extends Object
implements Stringifier<T>

DefaultStringifier is the default implementation of the Stringifier interface which stringifies the objects using base64 encoding of the serialized version of the objects. The Serializer and Deserializer are obtained from the SerializationFactory.
DefaultStringifier offers convenience methods to store/load objects to/from the configuration.


Constructor Summary
DefaultStringifier(Configuration conf, Class<T> c)
           
 
Method Summary
 void close()
          Closes this object.
 T fromString(String str)
          Restores the object from its string representation.
static
<K> K
load(Configuration conf, String keyName, Class<K> itemClass)
          Restores the object from the configuration.
static
<K> K[]
loadArray(Configuration conf, String keyName, Class<K> itemClass)
          Restores the array of objects from the configuration.
static
<K> void
store(Configuration conf, K item, String keyName)
          Stores the item in the configuration with the given keyName.
static
<K> void
storeArray(Configuration conf, K[] items, String keyName)
          Stores the array of items in the configuration with the given keyName.
 String toString(T obj)
          Converts the object to a string representation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultStringifier

public DefaultStringifier(Configuration conf,
                          Class<T> c)
Method Detail

fromString

public T fromString(String str)
             throws IOException
Description copied from interface: Stringifier
Restores the object from its string representation.

Specified by:
fromString in interface Stringifier<T>
Parameters:
str - the string representation of the object
Returns:
restored object
Throws:
IOException - if the object cannot be restored

toString

public String toString(T obj)
                throws IOException
Description copied from interface: Stringifier
Converts the object to a string representation

Specified by:
toString in interface Stringifier<T>
Parameters:
obj - the object to convert
Returns:
the string representation of the object
Throws:
IOException - if the object cannot be converted

close

public void close()
           throws IOException
Description copied from interface: Stringifier
Closes this object.

Specified by:
close in interface Closeable
Specified by:
close in interface Stringifier<T>
Throws:
IOException - if an I/O error occurs

store

public static <K> void store(Configuration conf,
                             K item,
                             String keyName)
                  throws IOException
Stores the item in the configuration with the given keyName.

Type Parameters:
K - the class of the item
Parameters:
conf - the configuration to store
item - the object to be stored
keyName - the name of the key to use
Throws:
IOException - : forwards Exceptions from the underlying Serialization classes.

load

public static <K> K load(Configuration conf,
                         String keyName,
                         Class<K> itemClass)
              throws IOException
Restores the object from the configuration.

Type Parameters:
K - the class of the item
Parameters:
conf - the configuration to use
keyName - the name of the key to use
itemClass - the class of the item
Returns:
restored object
Throws:
IOException - : forwards Exceptions from the underlying Serialization classes.

storeArray

public static <K> void storeArray(Configuration conf,
                                  K[] items,
                                  String keyName)
                       throws IOException
Stores the array of items in the configuration with the given keyName.

Type Parameters:
K - the class of the item
Parameters:
conf - the configuration to use
items - the objects to be stored
keyName - the name of the key to use
Throws:
IndexOutOfBoundsException - if the items array is empty
IOException - : forwards Exceptions from the underlying Serialization classes.

loadArray

public static <K> K[] loadArray(Configuration conf,
                                String keyName,
                                Class<K> itemClass)
                     throws IOException
Restores the array of objects from the configuration.

Type Parameters:
K - the class of the item
Parameters:
conf - the configuration to use
keyName - the name of the key to use
itemClass - the class of the item
Returns:
restored object
Throws:
IOException - : forwards Exceptions from the underlying Serialization classes.


Copyright © 2009 The Apache Software Foundation