Package org.apache.hadoop.io
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>
DefaultStringifier is the default implementation of the
DefaultStringifier offers convenience methods to store/load objects to/from the configuration.
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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this object.fromString(String str) Restores the object from its string representation.static <K> Kload(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> voidstore(Configuration conf, K item, String keyName) Stores the item in the configuration with the given keyName.static <K> voidstoreArray(Configuration conf, K[] items, String keyName) Stores the array of items in the configuration with the given keyName.Converts the object to a string representation
-
Constructor Details
-
DefaultStringifier
-
-
Method Details
-
fromString
Description copied from interface:StringifierRestores the object from its string representation.- Specified by:
fromStringin interfaceStringifier<T>- Parameters:
str- the string representation of the object- Returns:
- restored object
- Throws:
IOException- if the object cannot be restored
-
toString
Description copied from interface:StringifierConverts the object to a string representation- Specified by:
toStringin interfaceStringifier<T>- Parameters:
obj- the object to convert- Returns:
- the string representation of the object
- Throws:
IOException- if the object cannot be converted
-
close
Description copied from interface:StringifierCloses this object.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceStringifier<T>- Throws:
IOException- if an I/O error occurs
-
store
Stores the item in the configuration with the given keyName.- Type Parameters:
K- the class of the item- Parameters:
conf- the configuration to storeitem- the object to be storedkeyName- the name of the key to use- Throws:
IOException- : forwards Exceptions from the underlyingSerializationclasses.
-
load
Restores the object from the configuration.- Type Parameters:
K- the class of the item- Parameters:
conf- the configuration to usekeyName- the name of the key to useitemClass- the class of the item- Returns:
- restored object
- Throws:
IOException- : forwards Exceptions from the underlyingSerializationclasses.
-
storeArray
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 useitems- the objects to be storedkeyName- the name of the key to use- Throws:
IndexOutOfBoundsException- if the items array is emptyIOException- : forwards Exceptions from the underlyingSerializationclasses.
-
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 usekeyName- the name of the key to useitemClass- the class of the item- Returns:
- restored object
- Throws:
IOException- : forwards Exceptions from the underlyingSerializationclasses.
-