2.17.2: 2011-06-17

net.sf.basedb.util.bfs
Class AbstractDataWriterFactory<T>

java.lang.Object
  extended by 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: 2010-01-12 14:21:49 +0100 (Tue, 12 Jan 2010) $

Field Summary
private  FilenameGenerator<T> filenameGenerator
           
private  Set<String> usedFiles
           
 
Constructor Summary
protected AbstractDataWriterFactory(FilenameGenerator<T> filenameGenerator)
          Create a new factory that uses the given file name generator.
 
Method Summary
 DataWriter createDataWriter(T owner, String suggestedFilename)
          Create a data writer for writing data that belongs to the given owner.
protected abstract  OutputStream getOutputStream(String filename)
          Create an output stream for writing to a file with the given filename.
protected  boolean isUnique(String filename)
          Checks if the suggested file name has already been used by this data writer factory or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

usedFiles

private Set<String> usedFiles

filenameGenerator

private FilenameGenerator<T> filenameGenerator
Constructor Detail

AbstractDataWriterFactory

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

Method Detail

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

2.17.2: 2011-06-17