Package org.apache.pivot.serialization
Class StringSerializer
- java.lang.Object
-
- org.apache.pivot.serialization.StringSerializer
-
- All Implemented Interfaces:
Serializer<java.lang.String>
public class StringSerializer extends java.lang.Object implements Serializer<java.lang.String>
Implementation of theSerializerinterface that reads data from and writes data to Java Strings. The text data is interpreted using either the defaultUTF-8Charsetor aCharsetsupplied in the constructor.Instances of this class are reusable (and thread-safe) because no mutable instance data is used in the
readObject(java.io.InputStream)andwriteObject(java.lang.String, java.io.OutputStream)methods.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringMIME_TYPEstatic java.lang.StringTEXT_EXTENSION
-
Constructor Summary
Constructors Constructor Description StringSerializer()StringSerializer(java.nio.charset.Charset charset)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.nio.charset.CharsetgetCharset()java.lang.StringgetMIMEType(java.lang.String object)Returns the MIME type of the data read and written by this serializer.java.lang.StringreadObject(java.io.InputStream inputStream)Reads plain text data from an input stream, interpreted by the givenCharset.voidwriteObject(java.lang.String text, java.io.OutputStream outputStream)Writes plain text data to an output stream, encoded in the givenCharset.
-
-
-
Field Detail
-
TEXT_EXTENSION
public static final java.lang.String TEXT_EXTENSION
- See Also:
- Constant Field Values
-
MIME_TYPE
public static final java.lang.String MIME_TYPE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getCharset
public java.nio.charset.Charset getCharset()
-
readObject
public java.lang.String readObject(java.io.InputStream inputStream) throws java.io.IOException, SerializationExceptionReads plain text data from an input stream, interpreted by the givenCharset.- Specified by:
readObjectin interfaceSerializer<java.lang.String>- Parameters:
inputStream- The input stream from which data will be read.- Returns:
- An instance of
Stringcontaining the text read from the input stream. - Throws:
java.io.IOException- for any errors accessing or reading the object.SerializationException- for any formatting errors encountered while deserializing the object.- See Also:
getCharset()
-
writeObject
public void writeObject(java.lang.String text, java.io.OutputStream outputStream) throws java.io.IOException, SerializationExceptionWrites plain text data to an output stream, encoded in the givenCharset.- Specified by:
writeObjectin interfaceSerializer<java.lang.String>- Parameters:
text- The text to be written to the output stream.outputStream- The output stream to which data will be written.- Throws:
java.io.IOException- for any errors accessing or reading the object.SerializationException- for any formatting errors encountered while deserializing the object.- See Also:
getCharset()
-
getMIMEType
public java.lang.String getMIMEType(java.lang.String object)
Description copied from interface:SerializerReturns the MIME type of the data read and written by this serializer.- Specified by:
getMIMETypein interfaceSerializer<java.lang.String>- Parameters:
object- If provided, allows the serializer to attach parameters to the returned MIME type containing more detailed information about the data. Ifnull, the base MIME type is returned.- Returns:
- The MIME type of the current data.
-
-