private ImageInputStream getOrCreateImageInputStream(Band band, File file) throws IOException {
   ImageInputStream inputStream = getImageInputStream(band);
   if (inputStream == null) {
     try {
       inputStream = new FileImageInputStream(file);
     } catch (IOException e) {
       SystemUtils.LOG.log(
           Level.WARNING,
           "DimapProductReader: Unable to read file '"
               + file
               + "' referenced by '"
               + band.getName()
               + "'.",
           e);
     }
     if (inputStream == null) {
       return null;
     }
     if (bandInputStreams == null) {
       bandInputStreams = new Hashtable<Band, ImageInputStream>();
     }
     bandInputStreams.put(band, inputStream);
   }
   return inputStream;
 }
  private static int getGeoKeyAsInt(final int key, final GeoTiffIIOMetadataDecoder metadata) {

    try {
      return Integer.parseInt(metadata.getGeoKey(key));
    } catch (NumberFormatException ne) {
      SystemUtils.LOG.log(Level.FINE, ne.getMessage(), ne);
      return GeoTiffConstants.UNDEFINED;
    }
  }
 public static void configurePreferredTileSize(Product product) {
   Dimension newSize =
       getConfiguredTileSize(
           product,
           Config.instance().preferences().get(SYSPROP_READER_TILE_WIDTH, null),
           Config.instance().preferences().get(SYSPROP_READER_TILE_HEIGHT, null));
   if (newSize != null) {
     Dimension oldSize = product.getPreferredTileSize();
     if (oldSize == null) {
       product.setPreferredTileSize(newSize);
       SystemUtils.LOG.fine(
           String.format(
               "Product '%s': tile size set to %d x %d pixels",
               product.getName(), newSize.width, newSize.height));
     } else if (!oldSize.equals(newSize)) {
       product.setPreferredTileSize(newSize);
       SystemUtils.LOG.fine(
           String.format(
               "Product '%s': tile size set to %d x %d pixels, was %d x %d pixels",
               product.getName(), newSize.width, newSize.height, oldSize.width, oldSize.height));
     }
   }
 }
 private void bindBandsToFiles(Document dom) {
   bandDataFiles = DimapProductHelpers.getBandDataFiles(dom, product, getInputDir());
   final Band[] bands = product.getBands();
   for (final Band band : bands) {
     if (band instanceof VirtualBand || band instanceof FilterBand) {
       continue;
     }
     final File dataFile = bandDataFiles.get(band);
     if (dataFile == null || !dataFile.canRead()) {
       SystemUtils.LOG.warning(
           "DimapProductReader: Unable to read file '"
               + dataFile
               + "' referenced by '"
               + band.getName()
               + "'.");
       SystemUtils.LOG.warning(
           "DimapProductReader: Removed band '"
               + band.getName()
               + "' from product '"
               + product.getFileLocation()
               + "'.");
     }
   }
 }
 private static boolean loadHdf5Lib() {
   try {
     Class.forName(H5_CLASS_NAME);
     return true;
   } catch (ClassNotFoundException ignored) {
     // no logging here, H5 class may not be provided by intention
     return false;
   } catch (LinkageError e) {
     // warning here, because H5 class exists, but native libs couldn't be loaded
     SystemUtils.LOG.warning(
         MessageFormat.format(
             "{0}: HDF-5 library not available: {1}: {2}",
             Hdf5ProductWriterPlugIn.class, e.getClass(), e.getMessage()));
     return false;
   }
 }
  private void addVectorDataToProduct(File vectorFile, final CoordinateReferenceSystem modelCrs)
      throws IOException {
    FileReader reader = null;
    try {
      reader = new FileReader(vectorFile);
      FeatureUtils.FeatureCrsProvider crsProvider =
          new FeatureUtils.FeatureCrsProvider() {
            @Override
            public CoordinateReferenceSystem getFeatureCrs(Product product) {
              return modelCrs;
            }

            @Override
            public boolean clipToProductBounds() {
              return false;
            }
          };
      OptimalPlacemarkDescriptorProvider descriptorProvider =
          new OptimalPlacemarkDescriptorProvider();
      VectorDataNode vectorDataNode =
          VectorDataNodeReader.read(
              vectorFile.getName(),
              reader,
              product,
              crsProvider,
              descriptorProvider,
              modelCrs,
              VectorDataNodeIO.DEFAULT_DELIMITER_CHAR,
              ProgressMonitor.NULL);
      if (vectorDataNode != null) {
        final ProductNodeGroup<VectorDataNode> vectorDataGroup = product.getVectorDataGroup();
        final VectorDataNode existing = vectorDataGroup.get(vectorDataNode.getName());
        if (existing != null) {
          vectorDataGroup.remove(existing);
        }
        vectorDataGroup.add(vectorDataNode);
      }
    } catch (IOException e) {
      SystemUtils.LOG.log(Level.SEVERE, "Error reading '" + vectorFile + "'", e);
    } finally {
      if (reader != null) {
        reader.close();
      }
    }
  }
 /**
  * Reads the nodes of a data product and returns an in-memory representation of it.
  *
  * <p>The given subset info can be used to specify spatial and spectral portions of the original
  * proudct. If the subset is omitted, the complete product is read in.
  *
  * <p>Whether the band data - the actual pixel values - is read in immediately or later when
  * pixels are requested, is up to the implementation.
  *
  * @param input an object representing a valid output for this product reader, might be a <code>
  *     ImageInputStream</code> or other <code>Object</code> to use for future decoding.
  * @param subsetDef a spectral or spatial subset (or both) of the product. If <code>null</code>,
  *     the entire product is read in
  * @throws IllegalArgumentException if input type is not supported (see {@link
  *     ProductReaderPlugIn#getInputTypes()}).
  * @throws IOException if an I/O error occurs
  * @throws IllegalFileFormatException if the file format is unknown.
  */
 public Product readProductNodes(Object input, ProductSubsetDef subsetDef) throws IOException {
   // (nf, 26.09.2007) removed (input == null) check, null inputs (= no sources) shall be allowed
   if (input != null && !isInstanceOfValidInputType(input)) {
     throw new IllegalArgumentException("invalid input source: " + input);
   }
   final long startTime = System.currentTimeMillis();
   setInput(input);
   setSubsetDef(subsetDef);
   final Product product = readProductNodesImpl();
   configurePreferredTileSize(product);
   product.setModified(false);
   if (product.getProductReader() == null) {
     product.setProductReader(this);
   }
   final long endTime = System.currentTimeMillis();
   String msg = String.format("Read product nodes (took %d ms)", (endTime - startTime));
   SystemUtils.LOG.fine(msg);
   return product;
 }
 public static S2GranuleDirFilename create(String fileName) {
   final Matcher matcher = PATTERN.matcher(fileName);
   if (matcher.matches()) {
     return new S2L1BGranuleDirFilename(
         fileName,
         matcher.group(1),
         matcher.group(2),
         matcher.group(3),
         matcher.group(4),
         matcher.group(5),
         matcher.group(6),
         matcher.group(7),
         matcher.group(8),
         matcher.group(9));
   } else {
     SystemUtils.LOG.warning(
         String.format(
             "%s S2L1BGranuleDirFilename didn't match regexp %s", fileName, PATTERN.toString()));
     return null;
   }
 }