Package csv.impl
Class AbstractStreamTableWriter
java.lang.Object
csv.impl.AbstractTableWriter
csv.impl.AbstractStreamTableWriter
- All Implemented Interfaces:
TableWriter
- Direct Known Subclasses:
CSVWriter,ExcelWriter,HtmlWriter,XmlWriter
public abstract class AbstractStreamTableWriter extends AbstractTableWriter
An abstract implementation of TableWriter.
This implementation is dedicated for I/O streams as underlying medium.
- Author:
- RalphSchuster
-
Constructor Summary
Constructors Constructor Description AbstractStreamTableWriter()Default Constructor.AbstractStreamTableWriter(java.io.File file)Create a new instance from a file object.AbstractStreamTableWriter(java.io.OutputStream out)Create a new instance from an existing OutputStream.AbstractStreamTableWriter(java.lang.String file)Create a new instance froma file name. -
Method Summary
Modifier and Type Method Description voidclose()Closes the writer and its underlying streams.protected java.io.OutputStreamWritercreateOutputStreamWriter(java.io.OutputStream out)Creates the stream writer for the printer.protected java.io.PrintWritercreateWriter()Creates the print writer for the output.java.nio.charset.CharsetEncodergetCharsetEncoder()Returns the encoder being used for the output.java.io.OutputStreamgetOutputStream()Returns the underlying output streamjava.io.PrintWritergetWriter()Returns a writer object for convinience.voidsetCharset(java.lang.String charset)Sets the charset being used for output.voidsetCharset(java.nio.charset.Charset charset)Sets the charset being used for output.voidsetCharsetEncoder(java.nio.charset.CharsetEncoder charsetEncoder)Sets the charset encoder being used.voidsetOutputStream(java.io.OutputStream out)Sets the underlying stream.Methods inherited from class csv.impl.AbstractTableWriter
convert, convert, getRowCount, getTypeConversionHandler, incrementRowCount, init, printComment, printComment, printRow, printRow, printRow, registerTypeConversionHandler, unregisterTypeConversionHandler
-
Constructor Details
-
AbstractStreamTableWriter
public AbstractStreamTableWriter()Default Constructor. -
AbstractStreamTableWriter
public AbstractStreamTableWriter(java.io.OutputStream out)Create a new instance from an existing OutputStream.- Parameters:
out- - the stream to write to.
-
AbstractStreamTableWriter
public AbstractStreamTableWriter(java.io.File file) throws java.io.IOExceptionCreate a new instance from a file object.- Parameters:
file- - file to write data to.- Throws:
java.io.IOException- - when the file could not be created
-
AbstractStreamTableWriter
public AbstractStreamTableWriter(java.lang.String file) throws java.io.IOExceptionCreate a new instance froma file name.- Parameters:
file- - file to write data to.- Throws:
java.io.IOException- - when the file could not be created
-
-
Method Details
-
setOutputStream
public void setOutputStream(java.io.OutputStream out)Sets the underlying stream. This implementation throws an exception when the stream was already set.- Parameters:
out- the output stream to be used
-
getWriter
public java.io.PrintWriter getWriter()Returns a writer object for convinience. The writer will be created only when required.- Returns:
- the writer object
-
createWriter
protected java.io.PrintWriter createWriter()Creates the print writer for the output. The method will callcreateOutputStreamWriter(OutputStream)for the creation of the underlying writer.- Returns:
- the output writer
-
createOutputStreamWriter
protected java.io.OutputStreamWriter createOutputStreamWriter(java.io.OutputStream out)Creates the stream writer for the printer.- Parameters:
out- the underlying output stream- Returns:
- the stream writer
-
getCharsetEncoder
public java.nio.charset.CharsetEncoder getCharsetEncoder()Returns the encoder being used for the output.- Returns:
- the encoder being used.
-
setCharsetEncoder
public void setCharsetEncoder(java.nio.charset.CharsetEncoder charsetEncoder)Sets the charset encoder being used.- Parameters:
charsetEncoder- the charset encoder to set
-
setCharset
public void setCharset(java.nio.charset.Charset charset)Sets the charset being used for output.- Parameters:
charset- the charset to set
-
setCharset
public void setCharset(java.lang.String charset)Sets the charset being used for output.- Parameters:
charset- the charset to set
-
getOutputStream
public java.io.OutputStream getOutputStream()Returns the underlying output stream- Returns:
- the outputStream
-
close
public void close()Closes the writer and its underlying streams.- Specified by:
closein interfaceTableWriter- Overrides:
closein classAbstractTableWriter
-