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 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.IOException
      Create 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.IOException
      Create 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 call createOutputStreamWriter(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:
      close in interface TableWriter
      Overrides:
      close in class AbstractTableWriter