Class WriterBySection

java.lang.Object
com.compomics.util.io.compression.SectionGzWriter.WriterBySection
All Implemented Interfaces:
AutoCloseable

public class WriterBySection extends Object implements AutoCloseable
This writer writes the different sections of a file in temp files and bundles them together upon completion.
Author:
Marc Vaudel
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The size of the char buffer to use when copying files.
    final boolean
    If true, temp files are deleted upon completion.
    final boolean
    If true, temp files are gzipped.
  • Constructor Summary

    Constructors
    Constructor
    Description
    WriterBySection(File destinationFile, File tempFolder, boolean deleteTempFiles, boolean gzipTemp, boolean gzipDestination)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
    newLine(String sectionName)
    Appends a new line to the given section.
    void
    registerSection(String sectionName)
    Registers a new section.
    void
    sectionCompleted(String sectionName)
    Registers a section as completed and transfers its content to the main file.
    void
    write(String sectionName, char[] buffer, int offset, int length)
    Writes content to the given section.
    void
    write(String sectionName, String content)
    Writes content to the given section.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • CHAR_BUFFER_SIZE

      public static final int CHAR_BUFFER_SIZE
      The size of the char buffer to use when copying files.
      See Also:
    • deleteTempFiles

      public final boolean deleteTempFiles
      If true, temp files are deleted upon completion.
    • gzipTemp

      public final boolean gzipTemp
      If true, temp files are gzipped.
  • Constructor Details

    • WriterBySection

      public WriterBySection(File destinationFile, File tempFolder, boolean deleteTempFiles, boolean gzipTemp, boolean gzipDestination) throws FileNotFoundException, IOException
      Constructor.
      Parameters:
      destinationFile - The destination file.
      tempFolder - The folder to write intermediate files to.
      deleteTempFiles - If true, temp files are deleted upon completion.
      gzipTemp - If true, temp files are gzipped.
      gzipDestination - If true, the destination file is gzipped.
      Throws:
      FileNotFoundException - Exception thrown if a file is not found.
      IOException - Exception thrown if an error occurred while reading or writing a file.
  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • registerSection

      public void registerSection(String sectionName) throws FileNotFoundException, IOException
      Registers a new section. The section name should not contain special characters forbidden in file names.
      Parameters:
      sectionName - The name of the section.
      Throws:
      FileNotFoundException - Exception thrown if the temp folder does not exist or is not writable.
      IOException - Exception thrown if an error occurred while writing the temp file.
    • sectionCompleted

      public void sectionCompleted(String sectionName)
      Registers a section as completed and transfers its content to the main file.
      Parameters:
      sectionName - The name of the section.
    • newLine

      public void newLine(String sectionName)
      Appends a new line to the given section.
      Parameters:
      sectionName - The name of the section.
    • write

      public void write(String sectionName, String content)
      Writes content to the given section.
      Parameters:
      sectionName - The name of the section.
      content - The content to write.
    • write

      public void write(String sectionName, char[] buffer, int offset, int length)
      Writes content to the given section.
      Parameters:
      sectionName - The name of the section.
      buffer - The buffer to write.
      offset - The offset from which to start reading characters.
      length - The maximal number of characters to write