net.coobird.thumbnailator.tasks.io
Class FileImageSink

java.lang.Object
  extended by net.coobird.thumbnailator.tasks.io.AbstractImageSink<File>
      extended by net.coobird.thumbnailator.tasks.io.FileImageSink
All Implemented Interfaces:
ImageSink<File>

public class FileImageSink
extends AbstractImageSink<File>

An ImageSink which writes the resulting thumbnail to a file.

Under certain circumstances, the destination file can change in the course of processing.

This can occur in cases where the file extension does not match the output format set by the AbstractImageSink.setOutputFormatName(String) method. In this case, the file name will have a file extension corresponding to the output format set in the above method to be appended to the file name originally provided when instantiating the FileImageSink object.

Author:
coobird

Constructor Summary
FileImageSink(File destinationFile)
          Instantiates a FileImageSink with the file to which the thumbnail should be written to.
FileImageSink(File destinationFile, boolean allowOverwrite)
          Instantiates a FileImageSink with the file to which the thumbnail should be written to.
FileImageSink(String destinationFilePath)
          Instantiates a FileImageSink with the file to which the thumbnail should be written to.
FileImageSink(String destinationFilePath, boolean allowOverwrite)
          Instantiates a FileImageSink with the file to which the thumbnail should be written to.
 
Method Summary
 File getSink()
          Returns the detination file of the thumbnail image.
 String preferredOutputFormatName()
          Returns the output format to use from information provided for the output image.
 void write(BufferedImage img)
          Writes the resulting image to a file.
 
Methods inherited from class net.coobird.thumbnailator.tasks.io.AbstractImageSink
setOutputFormatName, setThumbnailParameter
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileImageSink

public FileImageSink(File destinationFile)
Instantiates a FileImageSink with the file to which the thumbnail should be written to.

The output format to use will be determined from the file extension. If another format should be used, then the AbstractImageSink.setOutputFormatName(String) should be called with the desired output format name.

When the destination file exists, then this FileImageSink will overwrite the existing file.

Parameters:
destinationFile - The destination file.
Throws:
NullPointerException - If the specified file is null.

FileImageSink

public FileImageSink(File destinationFile,
                     boolean allowOverwrite)
Instantiates a FileImageSink with the file to which the thumbnail should be written to.

The output format to use will be determined from the file extension. If another format should be used, then the AbstractImageSink.setOutputFormatName(String) should be called with the desired output format name.

Parameters:
destinationFile - The destination file.
allowOverwrite - Whether or not the FileImageSink should overwrite the destination file if it already exists.
Throws:
NullPointerException - If the specified file is null.

FileImageSink

public FileImageSink(String destinationFilePath)
Instantiates a FileImageSink with the file to which the thumbnail should be written to.

The output format to use will be determined from the file extension. If another format should be used, then the AbstractImageSink.setOutputFormatName(String) should be called with the desired output format name.

When the destination file exists, then this FileImageSink will overwrite the existing file.

Parameters:
destinationFilePath - The destination file path.
Throws:
NullPointerException - If the specified file path is null.

FileImageSink

public FileImageSink(String destinationFilePath,
                     boolean allowOverwrite)
Instantiates a FileImageSink with the file to which the thumbnail should be written to.

The output format to use will be determined from the file extension. If another format should be used, then the AbstractImageSink.setOutputFormatName(String) should be called with the desired output format name.

Parameters:
destinationFilePath - The destination file path.
allowOverwrite - Whether or not the FileImageSink should overwrite the destination file if it already exists.
Throws:
NullPointerException - If the specified file path is null.
Method Detail

preferredOutputFormatName

public String preferredOutputFormatName()
Description copied from interface: ImageSink
Returns the output format to use from information provided for the output image.

If the output format cannot be determined, then ThumbnailParameter.ORIGINAL_FORMAT should be returned.

Specified by:
preferredOutputFormatName in interface ImageSink<File>
Overrides:
preferredOutputFormatName in class AbstractImageSink<File>

write

public void write(BufferedImage img)
           throws IOException
Writes the resulting image to a file.

Specified by:
write in interface ImageSink<File>
Overrides:
write in class AbstractImageSink<File>
Parameters:
img - The image to write.
Throws:
UnsupportedFormatException - When an unsupported format has been specified by the AbstractImageSink.setOutputFormatName(String) method, or if the output format has not been set and cannot be determined from the file name.
IOException - When a problem occurs while writing the image.
NullPointerException - If the image is null.
IllegalArgumentException - If this FileImageSink does not permit overwriting the destination file and the destination file already exists.

getSink

public File getSink()
Returns the detination file of the thumbnail image.

If the final destination of the thumbnail changes in the course of writing the thumbnail. (For example, if the file extension for the given destination did not match the destination file format, then the correct file extension could be appended.)

Returns:
the destinationFile


Copyright © 2014. All rights reserved.