wjhk.jupload2.filedata.helper
Class ImageReaderWriterHelper

java.lang.Object
  extended by wjhk.jupload2.filedata.helper.ImageReaderWriterHelper

public class ImageReaderWriterHelper
extends java.lang.Object

This package provides low level methods, for picture management. It is used by PictureFileData to simplify its processing.

Author:
etienne_sf

Field Summary
(package private)  javax.imageio.stream.FileImageInputStream fileImageInputStream
          File input, from which the original picture should be read.
(package private)  javax.imageio.stream.FileImageOutputStream fileImageOutputStream
          File output stream for the current transformation.
(package private)  javax.imageio.ImageReader imageReader
          Current ImageReader.
(package private)  javax.imageio.ImageWriter imageWriter
          Current ImageWriter.
(package private)  javax.imageio.ImageWriteParam imageWriterParam
          Current ImageWriter.
(package private)  PictureFileData pictureFileData
          The PictureFileData that this helper will have to help.
(package private)  java.lang.String targetPictureFormat
          Contains the target picture format: GIF, JPG...
(package private)  PictureUploadPolicy uploadPolicy
          The current upload policy must be a PictureUploadPolicy
 
Constructor Summary
ImageReaderWriterHelper(PictureUploadPolicy uploadPolicy, PictureFileData pictureFileData)
          Standard constructor.
 
Method Summary
 void dispose()
          Free all reserved resource by this helper.
 javax.imageio.metadata.IIOMetadata getImageMetadata(int imageIndex)
          Load the metadata associated with one picture in the picture file.
 int getNumImages(boolean allowSearch)
          Call to imageReader.getNumImages(boolean).
 java.awt.image.BufferedImage imageIORead()
          Call to ImageIO.read(fileImageInputStream).
private  void initImageReader()
          Initialize the ImageReader for the current helper.
private  void initImageWriter()
          Initialize the ImageWriter and the ImageWriteParam for the current picture helper.
 javax.imageio.IIOImage readAll(int imageIndex)
          Read an image, from the pictureFileData.
 java.awt.image.BufferedImage readImage(int imageIndex)
          Read an image, from the pictureFileData.
 void setOutput(java.io.File file)
          Creates a FileImageOutputStream, and assign it as the output to the imageWriter.
 void write(javax.imageio.IIOImage iioImage)
          Write a picture in the output picture file.
 void writeInsert(int numIndex, javax.imageio.IIOImage iioImage, javax.imageio.ImageWriteParam iwp)
          Write a picture in the output picture file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fileImageInputStream

javax.imageio.stream.FileImageInputStream fileImageInputStream
File input, from which the original picture should be read.


fileImageOutputStream

javax.imageio.stream.FileImageOutputStream fileImageOutputStream
File output stream for the current transformation.


pictureFileData

PictureFileData pictureFileData
The PictureFileData that this helper will have to help.


imageReader

javax.imageio.ImageReader imageReader
Current ImageReader. Initialized by initImageReader()


imageWriter

javax.imageio.ImageWriter imageWriter
Current ImageWriter. Initialized by initImageWriter()


imageWriterParam

javax.imageio.ImageWriteParam imageWriterParam
Current ImageWriter. Initialized by initImageWriter()


targetPictureFormat

java.lang.String targetPictureFormat
Contains the target picture format: GIF, JPG... It is used to find an ImageWriter, and to define the target filename.


uploadPolicy

PictureUploadPolicy uploadPolicy
The current upload policy must be a PictureUploadPolicy

Constructor Detail

ImageReaderWriterHelper

public ImageReaderWriterHelper(PictureUploadPolicy uploadPolicy,
                               PictureFileData pictureFileData)
Standard constructor.

Parameters:
uploadPolicy - The current upload policy.
pictureFileData - The file data to be 'helped'.
Method Detail

setOutput

public void setOutput(java.io.File file)
               throws JUploadIOException
Creates a FileImageOutputStream, and assign it as the output to the imageWriter.

Parameters:
file - The file where the output stream must write.
Throws:
JUploadIOException - Any error...

dispose

public void dispose()
             throws JUploadIOException
Free all reserved resource by this helper. Includes closing of any input or output stream.

Throws:
JUploadIOException - Any IO Exception

getNumImages

public int getNumImages(boolean allowSearch)
                 throws JUploadIOException
Call to imageReader.getNumImages(boolean). Caution: may be long, for big files.

Parameters:
allowSearch -
Returns:
The number of image into this file.
Throws:
JUploadIOException

imageIORead

public java.awt.image.BufferedImage imageIORead()
                                         throws JUploadIOException
Call to ImageIO.read(fileImageInputStream).

Returns:
The BufferedImage read
Throws:
JUploadIOException

readImage

public java.awt.image.BufferedImage readImage(int imageIndex)
                                       throws JUploadIOException,
                                              java.lang.IndexOutOfBoundsException
Read an image, from the pictureFileData.

Parameters:
imageIndex - The index number of the picture, in the file. 0 for the first picture (only valid value for picture containing one picture)
Returns:
The image corresponding to this index, in the picture file.
Throws:
JUploadIOException
java.lang.IndexOutOfBoundsException - Occurs when the imageIndex is wrong.

readAll

public javax.imageio.IIOImage readAll(int imageIndex)
                               throws JUploadIOException,
                                      java.lang.IndexOutOfBoundsException
Read an image, from the pictureFileData.

Parameters:
imageIndex - The index number of the picture, in the file. 0 for the first picture (only valid value for picture containing one picture)
Returns:
The full image data for this index
Throws:
JUploadIOException
java.lang.IndexOutOfBoundsException - Occurs when the imageIndex is wrong.

getImageMetadata

public javax.imageio.metadata.IIOMetadata getImageMetadata(int imageIndex)
                                                    throws JUploadIOException
Load the metadata associated with one picture in the picture file.

Parameters:
imageIndex -
Returns:
The metadata loaded
Throws:
JUploadIOException - Any IOException is encapsulated in this exception

writeInsert

public void writeInsert(int numIndex,
                        javax.imageio.IIOImage iioImage,
                        javax.imageio.ImageWriteParam iwp)
                 throws JUploadIOException
Write a picture in the output picture file. Called just before an upload.

Parameters:
numIndex - The index of the image in the transformed picture file.
iioImage - The image to write.
iwp - The parameter to use to write this image.
Throws:
JUploadIOException

write

public void write(javax.imageio.IIOImage iioImage)
           throws JUploadIOException
Write a picture in the output picture file. Called just before an upload.

Parameters:
iioImage - The image to write.
Throws:
JUploadIOException

initImageWriter

private void initImageWriter()
                      throws JUploadIOException
Initialize the ImageWriter and the ImageWriteParam for the current picture helper.

Throws:
JUploadIOException

initImageReader

private void initImageReader()
                      throws JUploadIOException
Initialize the ImageReader for the current helper.

Throws:
JUploadIOException