loci.formats
Class ImageWriter

java.lang.Object
  extended by loci.formats.ImageWriter
All Implemented Interfaces:
IFormatHandler, IFormatWriter, StatusReporter

public class ImageWriter
extends Object
implements IFormatWriter

ImageWriter is the master file format writer for all supported formats. It uses one instance of each writer subclass (specified in writers.txt, or other class list source) to identify file formats and write data.

Source code:
Trac, SVN

Author:
Curtis Rueden ctrueden at wisc.edu

Field Summary
protected  String[] compressionTypes
          Compression types for all file format writers.
protected  int current
          Current form index.
protected  String currentId
          Name of current file.
protected  IFormatWriter[] writers
          List of supported file format writers.
 
Constructor Summary
ImageWriter()
          Constructs a new ImageWriter with the default list of writer classes from writers.txt.
ImageWriter(ClassList classList)
          Constructs a new ImageWriter from the given list of writer classes.
 
Method Summary
 void addStatusListener(StatusListener l)
          Adds a listener for status update events.
 boolean canDoStacks()
          Reports whether the writer can save multiple images to a single file.
 boolean canDoStacks(String id)
          Deprecated. Replaced by canDoStacks()
 void close()
          Closes currently open file(s) and frees allocated memory.
 ColorModel getColorModel()
          Gets the color model.
 String[] getCompressionTypes()
          Gets the available compression types.
 String getFormat()
          Gets the name of this file format.
 String getFormat(String id)
          Gets a string describing the file format for the given file.
 int getFramesPerSecond()
          Gets the frames per second to use when writing.
 MetadataRetrieve getMetadataRetrieve()
          Retrieves the current metadata retrieval object for this writer.
 int[] getPixelTypes()
          Gets the supported pixel types.
 int[] getPixelTypes(String id)
          Deprecated. Replaced by getPixelTypes()
 StatusListener[] getStatusListeners()
          Gets a list of all registered status update listeners.
 String[] getSuffixes()
          Gets the default file suffixes for this file format.
 IFormatWriter getWriter()
          Gets the writer used to save the current file.
 IFormatWriter getWriter(Class c)
          Gets the file format writer instance matching the given class.
 IFormatWriter getWriter(String id)
          Gets the writer used to save the given file.
 IFormatWriter[] getWriters()
          Gets all constituent file format writers.
 boolean isSupportedType(int type)
          Checks if the given pixel type is supported.
 boolean isSupportedType(String id, int type)
          Deprecated. Replaced by isSupportedType(int type)
 boolean isThisType(String name)
          Checks if the given string is a valid filename for this file format.
 boolean isThisType(String name, boolean open)
          Checks if the given string is a valid filename for this file format.
 void removeStatusListener(StatusListener l)
          Removes a listener for status update events.
 void save(String id, Image image, boolean last)
          Deprecated. Replaced by saveImage(Image, boolean)
 void saveBytes(byte[] bytes, boolean last)
          Saves the given byte array to the current file.
 void saveBytes(byte[] bytes, int series, boolean lastInSeries, boolean last)
          Saves the given byte array to the given series in the current file.
 void saveImage(Image image, boolean last)
          Saves the given image to the current file.
 void saveImage(Image image, int series, boolean lastInSeries, boolean last)
          Saves the given image to the given series in the current file.
 void setColorModel(ColorModel cm)
          Sets the color model.
 void setCompression(String compress)
          Sets the current compression type.
 void setFramesPerSecond(int rate)
          Sets the frames per second to use when writing.
 void setId(String id)
          Sets the current file name.
 void setId(String id, boolean force)
          Sets the current file name.
 void setMetadataRetrieve(MetadataRetrieve r)
          Sets the metadata retrieval object from which to retrieve standardized metadata.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

writers

protected IFormatWriter[] writers
List of supported file format writers.


compressionTypes

protected String[] compressionTypes
Compression types for all file format writers. Populated the first time getCompressionTypes() is called.


currentId

protected String currentId
Name of current file.


current

protected int current
Current form index.

Constructor Detail

ImageWriter

public ImageWriter()
Constructs a new ImageWriter with the default list of writer classes from writers.txt.


ImageWriter

public ImageWriter(ClassList classList)
Constructs a new ImageWriter from the given list of writer classes.

Method Detail

getFormat

public String getFormat(String id)
                 throws FormatException,
                        IOException
Gets a string describing the file format for the given file.

Throws:
FormatException
IOException

getWriter

public IFormatWriter getWriter(String id)
                        throws FormatException
Gets the writer used to save the given file.

Throws:
FormatException

getWriter

public IFormatWriter getWriter()
Gets the writer used to save the current file.


getWriter

public IFormatWriter getWriter(Class c)
Gets the file format writer instance matching the given class.


getWriters

public IFormatWriter[] getWriters()
Gets all constituent file format writers.


saveBytes

public void saveBytes(byte[] bytes,
                      boolean last)
               throws FormatException,
                      IOException
Description copied from interface: IFormatWriter
Saves the given byte array to the current file. If this is the last array to be written, the last flag must be set.

Specified by:
saveBytes in interface IFormatWriter
Throws:
FormatException
IOException

saveBytes

public void saveBytes(byte[] bytes,
                      int series,
                      boolean lastInSeries,
                      boolean last)
               throws FormatException,
                      IOException
Description copied from interface: IFormatWriter
Saves the given byte array to the given series in the current file. If this is the last array in the series, the lastInSeries flag must be set. If this is the last array to be written, the last flag must be set.

Specified by:
saveBytes in interface IFormatWriter
Throws:
FormatException
IOException

saveImage

public void saveImage(Image image,
                      boolean last)
               throws FormatException,
                      IOException
Description copied from interface: IFormatWriter
Saves the given image to the current file. If this image is the last one in the file, the last flag must be set.

Specified by:
saveImage in interface IFormatWriter
Throws:
FormatException
IOException

saveImage

public void saveImage(Image image,
                      int series,
                      boolean lastInSeries,
                      boolean last)
               throws FormatException,
                      IOException
Description copied from interface: IFormatWriter
Saves the given image to the given series in the current file. If this image is the last one in the series, the lastInSeries flag must be set. If this image is the last one in the file, the last flag must be set.

Specified by:
saveImage in interface IFormatWriter
Throws:
FormatException
IOException

canDoStacks

public boolean canDoStacks()
Description copied from interface: IFormatWriter
Reports whether the writer can save multiple images to a single file.

Specified by:
canDoStacks in interface IFormatWriter

setMetadataRetrieve

public void setMetadataRetrieve(MetadataRetrieve r)
Description copied from interface: IFormatWriter
Sets the metadata retrieval object from which to retrieve standardized metadata.

Specified by:
setMetadataRetrieve in interface IFormatWriter

getMetadataRetrieve

public MetadataRetrieve getMetadataRetrieve()
Description copied from interface: IFormatWriter
Retrieves the current metadata retrieval object for this writer. You can be assured that this method will never return a null metadata retrieval object.

Specified by:
getMetadataRetrieve in interface IFormatWriter
Returns:
A metadata retrieval object.

setColorModel

public void setColorModel(ColorModel cm)
Description copied from interface: IFormatWriter
Sets the color model.

Specified by:
setColorModel in interface IFormatWriter

getColorModel

public ColorModel getColorModel()
Description copied from interface: IFormatWriter
Gets the color model.

Specified by:
getColorModel in interface IFormatWriter

setFramesPerSecond

public void setFramesPerSecond(int rate)
Description copied from interface: IFormatWriter
Sets the frames per second to use when writing.

Specified by:
setFramesPerSecond in interface IFormatWriter

getFramesPerSecond

public int getFramesPerSecond()
Description copied from interface: IFormatWriter
Gets the frames per second to use when writing.

Specified by:
getFramesPerSecond in interface IFormatWriter

getCompressionTypes

public String[] getCompressionTypes()
Description copied from interface: IFormatWriter
Gets the available compression types.

Specified by:
getCompressionTypes in interface IFormatWriter

getPixelTypes

public int[] getPixelTypes()
Description copied from interface: IFormatWriter
Gets the supported pixel types.

Specified by:
getPixelTypes in interface IFormatWriter

isSupportedType

public boolean isSupportedType(int type)
Description copied from interface: IFormatWriter
Checks if the given pixel type is supported.

Specified by:
isSupportedType in interface IFormatWriter

setCompression

public void setCompression(String compress)
                    throws FormatException
Description copied from interface: IFormatWriter
Sets the current compression type.

Specified by:
setCompression in interface IFormatWriter
Throws:
FormatException

isThisType

public boolean isThisType(String name)
Description copied from interface: IFormatHandler
Checks if the given string is a valid filename for this file format.

Specified by:
isThisType in interface IFormatHandler

isThisType

public boolean isThisType(String name,
                          boolean open)
Description copied from interface: IFormatHandler
Checks if the given string is a valid filename for this file format.

Specified by:
isThisType in interface IFormatHandler
open - If true, and the file extension is insufficient to determine the file type, the (existing) file is opened for further analysis.

getFormat

public String getFormat()
Description copied from interface: IFormatHandler
Gets the name of this file format.

Specified by:
getFormat in interface IFormatHandler

getSuffixes

public String[] getSuffixes()
Description copied from interface: IFormatHandler
Gets the default file suffixes for this file format.

Specified by:
getSuffixes in interface IFormatHandler

setId

public void setId(String id)
           throws FormatException,
                  IOException
Description copied from interface: IFormatHandler
Sets the current file name.

Specified by:
setId in interface IFormatHandler
Throws:
FormatException
IOException

setId

public void setId(String id,
                  boolean force)
           throws FormatException,
                  IOException
Description copied from interface: IFormatHandler
Sets the current file name.

Specified by:
setId in interface IFormatHandler
force - If set, the handler will be re-initialized no matter what.
Throws:
FormatException
IOException

close

public void close()
           throws IOException
Description copied from interface: IFormatHandler
Closes currently open file(s) and frees allocated memory.

Specified by:
close in interface IFormatHandler
Throws:
IOException

addStatusListener

public void addStatusListener(StatusListener l)
Description copied from interface: StatusReporter
Adds a listener for status update events.

Specified by:
addStatusListener in interface StatusReporter

removeStatusListener

public void removeStatusListener(StatusListener l)
Description copied from interface: StatusReporter
Removes a listener for status update events.

Specified by:
removeStatusListener in interface StatusReporter

getStatusListeners

public StatusListener[] getStatusListeners()
Description copied from interface: StatusReporter
Gets a list of all registered status update listeners.

Specified by:
getStatusListeners in interface StatusReporter

canDoStacks

public boolean canDoStacks(String id)
                    throws FormatException
Deprecated. Replaced by canDoStacks()

Specified by:
canDoStacks in interface IFormatWriter
Throws:
FormatException

getPixelTypes

public int[] getPixelTypes(String id)
                    throws FormatException,
                           IOException
Deprecated. Replaced by getPixelTypes()

Specified by:
getPixelTypes in interface IFormatWriter
Throws:
FormatException
IOException

isSupportedType

public boolean isSupportedType(String id,
                               int type)
                        throws FormatException,
                               IOException
Deprecated. Replaced by isSupportedType(int type)

Specified by:
isSupportedType in interface IFormatWriter
Throws:
FormatException
IOException

save

public void save(String id,
                 Image image,
                 boolean last)
          throws FormatException,
                 IOException
Deprecated. Replaced by saveImage(Image, boolean)

Specified by:
save in interface IFormatWriter
Throws:
FormatException
IOException