Class StringSerializer

  • All Implemented Interfaces:
    Serializer<java.lang.String>

    public class StringSerializer
    extends java.lang.Object
    implements Serializer<java.lang.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.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String MIME_TYPE  
      static java.lang.String TEXT_EXTENSION  
    • 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 given Charset.
      void writeObject​(java.lang.String text, java.io.OutputStream outputStream)
      Writes plain text data to an output stream, encoded in the given Charset.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • StringSerializer

        public StringSerializer()
      • StringSerializer

        public StringSerializer​(java.nio.charset.Charset charset)
    • 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 given Charset.
        Specified by:
        readObject in interface Serializer<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 given Charset.
        Specified by:
        writeObject in interface Serializer<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 interface Serializer<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. If null, the base MIME type is returned.
        Returns:
        The MIME type of the current data.