Class OutputStreamImageSink
- java.lang.Object
-
- net.coobird.thumbnailator.tasks.io.AbstractImageSink<java.io.OutputStream>
-
- net.coobird.thumbnailator.tasks.io.OutputStreamImageSink
-
- All Implemented Interfaces:
ImageSink<java.io.OutputStream>
public class OutputStreamImageSink extends AbstractImageSink<java.io.OutputStream>
AnImageSinkwhich specifies anOutputStreamto which the thumbnail image should be written to.
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.OutputStreamosTheOutputStreamto which the thumbnail image is to be written to.-
Fields inherited from class net.coobird.thumbnailator.tasks.io.AbstractImageSink
outputFormat, param
-
-
Constructor Summary
Constructors Constructor Description OutputStreamImageSink(java.io.OutputStream os)Instantiates anOutputStreamImageSinkwith theOutputStreamto which the thumbnail should be written to.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.OutputStreamgetSink()Returns the destination to which the thumbnail will be stored or written.private booleanisDefaultPngWriter(javax.imageio.ImageWriter writer)private booleanisJava9OrNewer()private booleanisJpegOrBmp(java.lang.String formatName)private booleanisPng(java.lang.String formatName)private voidsetCompressionModeExplicit(javax.imageio.ImageWriteParam writeParam)Sets the compression mode to explicit, if not already.voidwrite(java.awt.image.BufferedImage img)Writes the resulting image to theOutputStream.-
Methods inherited from class net.coobird.thumbnailator.tasks.io.AbstractImageSink
preferredOutputFormatName, setOutputFormatName, setThumbnailParameter
-
-
-
-
Constructor Detail
-
OutputStreamImageSink
public OutputStreamImageSink(java.io.OutputStream os)
Instantiates anOutputStreamImageSinkwith theOutputStreamto which the thumbnail should be written to.- Parameters:
os- TheOutputStreamto write the thumbnail to.- Throws:
java.lang.NullPointerException- If theOutputStreamisnull.
-
-
Method Detail
-
write
public void write(java.awt.image.BufferedImage img) throws java.io.IOExceptionWrites the resulting image to theOutputStream.- Specified by:
writein interfaceImageSink<java.io.OutputStream>- Overrides:
writein classAbstractImageSink<java.io.OutputStream>- Parameters:
img- The image to write.- Throws:
UnsupportedFormatException- When an unsupported format has been specified by theAbstractImageSink.setOutputFormatName(String)method.java.io.IOException- When a problem occurs while writing the image.java.lang.NullPointerException- If the image isnull.java.lang.IllegalStateException- If the output format has not been set by calling theAbstractImageSink.setOutputFormatName(String)method.
-
setCompressionModeExplicit
private void setCompressionModeExplicit(javax.imageio.ImageWriteParam writeParam)
Sets the compression mode to explicit, if not already. A check exists to prevent setting the explicit mode more than once, as any previously set parameters will be discarded.- Parameters:
writeParam- Current image writer parameters.
-
isJpegOrBmp
private boolean isJpegOrBmp(java.lang.String formatName)
-
isPng
private boolean isPng(java.lang.String formatName)
-
isDefaultPngWriter
private boolean isDefaultPngWriter(javax.imageio.ImageWriter writer)
-
isJava9OrNewer
private boolean isJava9OrNewer()
-
getSink
public java.io.OutputStream getSink()
Description copied from interface:ImageSinkReturns the destination to which the thumbnail will be stored or written.- Returns:
- The destination for the thumbnail image.
-
-