Class DefaultStringifier<T>

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

@Public @Stable 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 Details

  • Method Details

    • 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 AutoCloseable
      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.