private static void copyImage(String paramString) throws ReporterException {
   File localFile = new File(paramString);
   if (!localFile.exists()) {
     return;
   }
   FileImageInputStream localFileImageInputStream = null;
   FileImageOutputStream localFileImageOutputStream = null;
   try {
     localFileImageInputStream = new FileImageInputStream(new File(paramString));
     localFileImageOutputStream =
         new FileImageOutputStream(new File(IMGDir + SEP + localFile.getName()));
     int i = 0;
     while ((i = localFileImageInputStream.read()) >= 0) {
       localFileImageOutputStream.write(i);
     }
     localFileImageOutputStream.close();
     return;
   } catch (Exception localException2) {
   } finally {
     try {
       localFileImageInputStream.close();
       localFileImageOutputStream.close();
       localFile = null;
     } catch (Exception localException4) {
       localFileImageInputStream = null;
       localFileImageOutputStream = null;
       localFile = null;
     }
   }
 }
Exemple #2
0
 public static IIOMetadata getImageMetadata(File image) throws IOException {
   Iterator readers =
       ImageIO.getImageReadersBySuffix(StringHelper.getFileExtension(image.getName()));
   if (StringHelper.isImage(image.getName())) {
     if (!readers.hasNext()) {
       return null;
     } else {
       ImageReader imageReader = (ImageReader) readers.next();
       FileImageInputStream in = new FileImageInputStream(image);
       try {
         imageReader.setInput(in);
         return imageReader.getImageMetadata(0);
       } finally {
         if (in != null) {
           try {
             in.close();
           } catch (Exception e) {
             e.printStackTrace();
           }
         }
       }
     }
   } else {
     return null;
   }
 }
 private void readTiePointGrids(Document jDomDocument) throws IOException {
   final String[] tiePointGridNames = product.getTiePointGridNames();
   for (String tiePointGridName : tiePointGridNames) {
     final TiePointGrid tiePointGrid = product.getTiePointGrid(tiePointGridName);
     String dataFile =
         DimapProductHelpers.getTiePointDataFile(jDomDocument, tiePointGrid.getName());
     final int dataType =
         DimapProductHelpers.getTiePointDataType(
             jDomDocument.getRootElement(), tiePointGrid.getName());
     dataFile = FileUtils.exchangeExtension(dataFile, DimapProductConstants.IMAGE_FILE_EXTENSION);
     FileImageInputStream inputStream = null;
     try {
       inputStream = new FileImageInputStream(new File(inputDir, dataFile));
       final float[] data = ((float[]) tiePointGrid.getData().getElems());
       inputStream.seek(0);
       if (dataType == ProductData.TYPE_FLOAT32) {
         inputStream.readFully(data, 0, data.length);
       } else {
         final double[] doubles = new double[data.length];
         inputStream.readFully(doubles, 0, doubles.length);
         int i = 0;
         for (double d : doubles) {
           data[i++] = (float) d;
         }
       }
       inputStream.close();
       inputStream = null;
       // See if we have a -180...+180 or a 0...360 degree discontinuity
       if (tiePointGrid.getDiscontinuity() != TiePointGrid.DISCONT_NONE) {
         tiePointGrid.setDiscontinuity(TiePointGrid.getDiscontinuity(data));
       }
     } catch (Exception e) {
       throw new IOException(
           MessageFormat.format(
               "I/O error while reading tie-point grid ''{0}''.", tiePointGridName),
           e);
     } finally {
       if (inputStream != null) {
         inputStream.close();
       }
     }
   }
 }
  /**
   * Standard constructor: needs a PictureFileDataPolicy.
   *
   * @param file The files which data are to be handled by this instance.
   * @param root The root directory, to calculate the relative dir (see {@link #getRelativeDir()}.
   * @param uploadPolicy The current upload policy
   * @throws JUploadIOException Encapsulation of the IOException, if any would occurs.
   */
  public PictureFileData(File file, File root, PictureUploadPolicy uploadPolicy)
      throws JUploadIOException {
    super(file, root, uploadPolicy);
    // EGR Should be useless
    // this.uploadPolicy = (PictureUploadPolicy) super.uploadPolicy;
    this.storeBufferedImage = uploadPolicy.hasToStoreBufferedImage();

    String fileExtension = getFileExtension();

    // Is it a picture?
    Iterator<ImageReader> iter = ImageIO.getImageReadersByFormatName(fileExtension);
    if (iter.hasNext()) {
      // It's a picture: we store its original width and height, for
      // further calculation (rescaling and rotation).
      this.isPicture = true;
      try {
        FileImageInputStream fiis = new FileImageInputStream(getFile());
        ImageReader ir = iter.next();
        ir.setInput(fiis);
        this.originalHeight = ir.getHeight(0);
        this.originalWidth = ir.getWidth(0);
        ir.dispose();
        fiis.close();
      } catch (IOException e) {
        throw new JUploadIOException("PictureFileData()", e);
      }
    } else {
      this.isPicture = false;
    }
    // Let's log the test result
    uploadPolicy.displayDebug(
        "isPicture=" + this.isPicture + " (" + file.getName() + "), extension=" + fileExtension,
        75);

    // If it's a picture, we override the default mime type:
    if (this.isPicture) {
      setMimeTypeByExtension(fileExtension);
    }
  }