Class FileWriter


public class FileWriter extends DataWriter
Writes records to a binary stream that can be later read using a FileReader.
  • Constructor Details

    • FileWriter

      public FileWriter(File file, boolean append, boolean compressed)
      Parameters:
      file - the file to write or append to.
      append - Indicates if writing should start at the end of the file (if it exists).
      compressed - Indicates if the data should be compressed as it is being written (default false).
    • FileWriter

      public FileWriter(OutputStream outputStream, boolean compressed)
      Parameters:
      outputStream - the stream to write to.
      compressed - Indicates if the data should be compressed as it is being written.
    • FileWriter

      public FileWriter(File file, boolean append)
      Creates an uncompressed writer that appends to the file (if it exists) when append is true.
    • FileWriter

      public FileWriter(File file)
      Creates an uncompressed writer that replaces the file's contents.
    • FileWriter

      public FileWriter(DataOutput out)
      Creates an uncompressed writer that writes directly to the given output.
  • Method Details

    • write

      public static Record write(DataOutput out, Record record)
      Writes one record to the given output, flushing but not closing it, and returns the record.
    • addExceptionProperties

      public DataException addExceptionProperties(DataException exception)
      Description copied from class: Endpoint
      Adds this endpoint's current state to a DataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.
      Overrides:
      addExceptionProperties in class DataWriter
    • isAppend

      public boolean isAppend()
      Indicates if writing should start at the end of the file (if it exists).
    • isFlushOnWrite

      public boolean isFlushOnWrite()
      Indicates if the underlying java.io.BufferedWriter should be flushed after each record is written.
    • setFlushOnWrite

      public FileWriter setFlushOnWrite(boolean flushOnWrite)
      Indicates if the underlying java.io.BufferedWriter should be flushed after each record is written.
    • isAutoCloseWriter

      public boolean isAutoCloseWriter()
      Indicates if the underlying output stream should be closed when this stream closes (defaults to true).
    • setAutoCloseWriter

      public FileWriter setAutoCloseWriter(boolean autoCloseWriter)
      Indicates if the underlying output stream should be closed when this stream closes (defaults to true).
    • isCompressed

      public boolean isCompressed()
      Indicates if the data should be compressed as it is being written (default false).
    • close

      public void close()
      Description copied from class: DataEndpoint
      Indicates that this endpoint has finished reading or writing.
      Overrides:
      close in class DataEndpoint
    • 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