org.apache.pivot.serialization
Class StringSerializer
java.lang.Object
org.apache.pivot.serialization.StringSerializer
- All Implemented Interfaces:
- Serializer<String>
public class StringSerializer
- extends Object
- implements Serializer<String>
Implementation of the Serializer interface that reads data from and
writes data to Java Strings. The text data is interpreted using either the
default UTF-8 Charset or a Charset 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) and writeObject(java.lang.String, java.io.OutputStream)
methods.
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DEFAULT_CHARSET_NAME
public static final String DEFAULT_CHARSET_NAME
- See Also:
- Constant Field Values
TEXT_EXTENSION
public static final String TEXT_EXTENSION
- See Also:
- Constant Field Values
MIME_TYPE
public static final String MIME_TYPE
- See Also:
- Constant Field Values
BUFFER_SIZE
public static final int BUFFER_SIZE
- See Also:
- Constant Field Values
StringSerializer
public StringSerializer()
StringSerializer
public StringSerializer(Charset charset)
getCharset
public Charset getCharset()
readObject
public String readObject(InputStream inputStream)
throws IOException,
SerializationException
- Reads plain text data from an input stream, interpreted by the given
Charset.
- Specified by:
readObject in interface Serializer<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:
IOException
SerializationException- See Also:
getCharset()
writeObject
public void writeObject(String text,
OutputStream outputStream)
throws IOException,
SerializationException
- Writes plain text data to an output stream, encoded in the given
Charset.
- Specified by:
writeObject in interface Serializer<String>
- Parameters:
text - The text to be written to the output stream.outputStream - The output stream to which data will be written.
- Throws:
IOException
SerializationException- See Also:
getCharset()
getMIMEType
public String getMIMEType(String object)
- Description copied from interface:
Serializer
- Returns the MIME type of the data read and written by this serializer.
- Specified by:
getMIMEType in interface Serializer<String>
- Parameters:
object - If provided, allows the serializer to attach parameters to the returned
MIME type containing more detailed information about the data. If
null, the base MIME type is returned.