Package org.apache.pivot.wtk.text
Class PlainTextSerializer
- java.lang.Object
-
- org.apache.pivot.wtk.text.PlainTextSerializer
-
- All Implemented Interfaces:
Serializer<Document>
public class PlainTextSerializer extends java.lang.Object implements Serializer<Document>
Implementation of theSerializer
interface that reads and writes a plain text document.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
MIME_TYPE
-
Constructor Summary
Constructors Constructor Description PlainTextSerializer()
PlainTextSerializer(java.lang.String charsetName)
PlainTextSerializer(java.nio.charset.Charset charset)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getBufferSize()
boolean
getExpandTabs()
java.lang.String
getMIMEType(Document document)
Returns the MIME type of the data read and written by this serializer.int
getTabWidth()
Document
readObject(java.io.InputStream inputStream)
Reads an object from an input stream.Document
readObject(java.io.Reader reader)
void
setBufferSize(int bufferSize)
Sets the buffer size used internally for reading and writing.void
setExpandTabs(boolean expandTabs)
Sets whether tab characters (\t
) are expanded to an appropriate number of spaces while reading the text.void
setTabWidth(int tabWidth)
void
writeObject(Document document, java.io.OutputStream outputStream)
Writes an object to an output stream.void
writeObject(Document document, java.io.Writer writer)
-
-
-
Field Detail
-
MIME_TYPE
public static final java.lang.String MIME_TYPE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getTabWidth
public int getTabWidth()
-
setTabWidth
public void setTabWidth(int tabWidth)
-
getExpandTabs
public boolean getExpandTabs()
-
setExpandTabs
public void setExpandTabs(boolean expandTabs)
Sets whether tab characters (\t
) are expanded to an appropriate number of spaces while reading the text.- Parameters:
expandTabs
-true
to replace tab characters with space characters (depending on the setting of thegetTabWidth()
value) orfalse
to leave tabs alone.
-
getBufferSize
public int getBufferSize()
-
setBufferSize
public void setBufferSize(int bufferSize)
Sets the buffer size used internally for reading and writing. The default value isConstants.BUFFER_SIZE
. A value of0
will use the default value in theBufferedReader
andBufferedWriter
classes (probably 8192).- Parameters:
bufferSize
- The new buffer size to use (or 0 to use the system default).
-
readObject
public Document readObject(java.io.InputStream inputStream) throws java.io.IOException
Description copied from interface:Serializer
Reads an object from an input stream.- Specified by:
readObject
in interfaceSerializer<Document>
- Parameters:
inputStream
- The data stream from which the object will be read.- Returns:
- The deserialized object.
- Throws:
java.io.IOException
- for any errors accessing or reading the object.
-
readObject
public Document readObject(java.io.Reader reader) throws java.io.IOException
- Throws:
java.io.IOException
-
writeObject
public void writeObject(Document document, java.io.OutputStream outputStream) throws java.io.IOException
Description copied from interface:Serializer
Writes an object to an output stream.- Specified by:
writeObject
in interfaceSerializer<Document>
- Parameters:
document
- The object to serialize.outputStream
- The data stream to which the object will be written.- Throws:
java.io.IOException
- for any errors accessing or reading the object.
-
writeObject
public void writeObject(Document document, java.io.Writer writer) throws java.io.IOException
- Throws:
java.io.IOException
-
getMIMEType
public java.lang.String getMIMEType(Document document)
Description copied from interface:Serializer
Returns the MIME type of the data read and written by this serializer.- Specified by:
getMIMEType
in interfaceSerializer<Document>
- Parameters:
document
- 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.
-
-