Class StreamWriter


public class StreamWriter extends DataWriter
Writes records to a stream in a human-readable format.
  • Constructor Details

    • StreamWriter

      public StreamWriter(File file) throws DataException
      Creates a writer that overwrites the file, which this constructor opens immediately, and closes it when this writer is closed.
      Throws:
      DataException
    • StreamWriter

      public StreamWriter(Writer writer)
      Creates a writer that leaves the given writer open when this one is closed (see setCloseStream(boolean)).
    • StreamWriter

      public StreamWriter(OutputStream outputStream)
      Creates a writer that encodes with the default charset and leaves the stream open when this writer is closed (see setCloseStream(boolean)).
  • Method Details

    • newSystemOutWriter

      public static StreamWriter newSystemOutWriter()
      Creates a new instance of StreamWriter writing to System.out.
    • newJsonSystemOutWriter

      public static StreamWriter newJsonSystemOutWriter()
      Creates a new instance of StreamWriter writing JSON to System.out.
    • newXmlSystemOutWriter

      public static StreamWriter newXmlSystemOutWriter()
      Creates a new instance of StreamWriter writing XML to System.out.
    • newSystemErrWriter

      public static StreamWriter newSystemErrWriter()
      Creates a new instance of StreamWriter writing to System.err.
    • newSystemOutWriterWithSessionProperties

      public static StreamWriter newSystemOutWriterWithSessionProperties()
      Creates a new instance of StreamWriter writing to System.out with all session properties.
    • getFormat

      public StreamWriter.Format getFormat()
      Returns how each record is printed (defaults to StreamWriter.Format.RECORD).
    • setFormat

      public StreamWriter setFormat(StreamWriter.Format format)
      Sets how each record is printed; null means StreamWriter.Format.RECORD (the default).
    • getCloseStream

      public boolean getCloseStream()
      Indicates if the stream is closed when this writer is closed (defaults to false, or true when writing to a file).
    • setCloseStream

      public StreamWriter setCloseStream(boolean closeStream)
      Specifies if the stream should be closed when this writer is closed (default is false).
      Parameters:
      closeStream -
      Returns:
      this writer
    • open

      public void open() throws DataException
      Description copied from class: DataEndpoint
      Makes this endpoint ready for reading or writing.
      Overrides:
      open in class DataEndpoint
      Throws:
      DataException
    • close

      public void close() throws DataException
      Description copied from class: DataEndpoint
      Indicates that this endpoint has finished reading or writing.
      Overrides:
      close in class DataEndpoint
      Throws:
      DataException
    • writeImpl

      protected void writeImpl(Record record) throws Throwable
      Description copied from class: DataWriter
      Overridden by subclasses to write the specified record to this DataWriter.

      Contract for subclasses (see also docs/authoring/DataWriter.md):

      Specified by:
      writeImpl in class DataWriter
      Throws:
      Throwable