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 theSerializer
interface that reads data from and writes data to Java Strings. The text data is interpreted using either the defaultUTF-8
Charset
or aCharset
supplied 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.String
MIME_TYPE
static java.lang.String
TEXT_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.Charset
getCharset()
java.lang.String
getMIMEType(java.lang.String object)
Returns the MIME type of the data read and written by this serializer.java.lang.String
readObject(java.io.InputStream inputStream)
Reads plain text data from an input stream, interpreted by the givenCharset
.void
writeObject(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, SerializationException
Reads plain text data from an input stream, interpreted by the givenCharset
.- Specified by:
readObject
in interfaceSerializer<java.lang.String>
- Parameters:
inputStream
- The input stream from which data will be read.- Returns:
- An instance of
String
containing 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, SerializationException
Writes plain text data to an output stream, encoded in the givenCharset
.- Specified by:
writeObject
in 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:Serializer
Returns the MIME type of the data read and written by this serializer.- Specified by:
getMIMEType
in 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.
-
-