Class AbstractDataWriterFactory<T>

java.lang.Object
net.sf.basedb.util.bfs.AbstractDataWriterFactory<T>
All Implemented Interfaces:
DataWriterFactory<T>
Direct Known Subclasses:
GenericBaseDataWriterFactory, GenericDiskDataWriterFactory

public abstract class AbstractDataWriterFactory<T>
extends Object
implements DataWriterFactory<T>
Abstract implementation of a data writer factory. This class contains a filename generation algorithm that simply generates a sequence of filenames using a numeric counter and prefix/suffix strings.

Subclasses may override the filename generation. Subclasses must also provide an implementation that, given a filename, creates an output stream for it.

Version:
2.15
Author:
Nicklas
Last modified
$Date: 2019-05-21 13:37:09 +0200 (tis, 21 maj 2019) $
  • Field Details

  • Constructor Details

    • AbstractDataWriterFactory

      protected AbstractDataWriterFactory​(FilenameGenerator<T> filenameGenerator)
      Create a new factory that uses the given file name generator.
  • Method Details

    • createDataWriter

      public DataWriter createDataWriter​(T owner, String suggestedFilename) throws IOException
      Description copied from interface: DataWriterFactory
      Create a data writer for writing data that belongs to the given owner. The owner is typically a bioassay (serial bfs format) or a spot data field (matrix bfs format). The returned writer should usually have it's filename (DataWriter.getFilename()) and number of columns (DataWriter.getColumnCount()) set, since this is needed for the metadata generation.
      Specified by:
      createDataWriter in interface DataWriterFactory<T>
      Parameters:
      owner - The object that "owns" the data that is written to the file
      suggestedFilename - An optional suggested filename, the factory may use this string or generate a different filename
      Returns:
      A data writer object with the filename and number of colums set (unless otherwise specified)
      Throws:
      IOException
    • getOutputStream

      protected abstract OutputStream getOutputStream​(String filename) throws IOException
      Create an output stream for writing to a file with the given filename. The returned output stream will be wrapped in a writer that uses the UTF-8 character set.
      Throws:
      IOException - If there is a problem creating the file
    • isUnique

      protected boolean isUnique​(String filename)
      Checks if the suggested file name has already been used by this data writer factory or not.
      Parameters:
      filename - The filename to check
      Returns:
      TRUE if the name is unique or FALSE if it has already been used