String virtualPathOfModifiedImage = getVirtualPathOfModifiedImage(widthOfModifiedImage, heightOfModifiedImage, extension, mainApp);
  private int createAndStoreImage(IWContext iwc) throws Exception {        // get image encoder    ImageEncoder imageEncoder = getImageEncoder(iwc);        // get mime type    ImageEntity imageEntity = getImageEntity(iwc);    String mimeType = imageEntity.getMimeType();        // is it necessary to convert the image?      if (! checkAndCalculateNewWidthAndHeight(iwc))      // okay: the desired width and height is the same as the original image      // check if the image would be converted to another type      if (imageEncoder.isInputTypeEqualToResultType(mimeType))        // do nothing, use the original image        return -1;      else  {        // convert the original image using the same size        heightOfModifiedImage = getHeightOfOriginalImage(iwc);        widthOfModifiedImage = getWidthOfOriginalImage(iwc);        }               // look up the file extension of the result file the image encoder returns     // for this mime type    String extension = imageEncoder.getResultFileExtensionForInputMimeType(mimeType);    if (ImageEncoder.INVALID_FILE_EXTENSION.equals(extension))      throw new IOException("ImageEncoder do not known this mime type:"+mimeType);         String nameOfModifiedImage = getNameOfModifiedImageWithExtension(widthOfModifiedImage, heightOfModifiedImage ,extension);             // Does the image already exist? Then there is nothing to do.      int imageID = getImageIDByName(nameOfModifiedImage);      if ( imageID > -1)      	return imageID;            // get real path and virtual path to modified image      // (this does not mean that the modified image already exists)      IWMainApplication mainApp = iwc.getApplication();                  String virtualPathOfModifiedImage =         getVirtualPathOfModifiedImage(widthOfModifiedImage, heightOfModifiedImage, extension, mainApp);            String pathOfModifiedImage =         mainApp.getApplicationRealPath() + virtualPathOfModifiedImage;            // now create the new image...              // get input        // get fileFileValue() causes End-Of-File Exception when JAI tries to read the file fully         // InputStream input = imageEntity.getFileValue();      FileInputStream input = new FileInputStream(getRealPathToImage(iwc));           // get output      OutputStream output = new FileOutputStream(pathOfModifiedImage);      // encode         try {        imageEncoder.encode(mimeType, input ,output,widthOfModifiedImage, heightOfModifiedImage);    }    catch (Exception ex)  {      // delete the created file (you can not use the result)      output.close();      input.close();      (new File(pathOfModifiedImage)).delete();      throw ex;    }    output.close();    input.close();    FileInputStream inputStream = new FileInputStream(pathOfModifiedImage);      String name = getNameOfModifiedImageWithExtension(widthOfModifiedImage, heightOfModifiedImage, extension);        ImageEntity motherImage = getImageEntity(iwc);    ImageProvider imageProvider = getImageProvider(iwc);    int modifiedImageId = imageProvider.uploadImage(inputStream, mimeType, name, widthOfModifiedImage, heightOfModifiedImage ,motherImage);    inputStream.close();    return modifiedImageId;  }