Пример #1
0
  /**
   * Unzips the sole entry in the specified zip file, and saves it in a temporary directory, and
   * returns a File to the temporary location.
   *
   * @param path the path to the source file.
   * @param suffix the suffix to give the temp file.
   * @return a {@link File} for the temp file.
   * @throws IllegalArgumentException if the <code>path</code> is <code>null</code> or empty.
   */
  public static File unzipAndSaveToTempFile(String path, String suffix) {
    if (WWUtil.isEmpty(path)) {
      String message = Logging.getMessage("nullValue.PathIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    InputStream stream = null;

    try {
      stream = WWIO.openStream(path);

      ByteBuffer buffer = WWIO.readStreamToBuffer(stream);
      File file = WWIO.saveBufferToTempFile(buffer, WWIO.getFilename(path));

      buffer = WWIO.readZipEntryToBuffer(file, null);
      return WWIO.saveBufferToTempFile(buffer, suffix);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      WWIO.closeStream(stream, path);
    }

    return null;
  }
  private java.nio.ByteBuffer readElevations(Object source) throws java.io.IOException {
    if (!(source instanceof java.io.File) && !(source instanceof java.net.URL)) {
      String message = Logging.getMessage("DataRaster.CannotRead", source);
      Logging.logger().severe(message);
      throw new java.io.IOException(message);
    }

    if (source instanceof java.io.File) {
      java.io.File file = (java.io.File) source;

      // handle .bil.zip, .bil16.zip, and .bil32.gz files
      if (file.getName().toLowerCase().endsWith(".zip")) {
        return WWIO.readZipEntryToBuffer(file, null);
      }
      // handle bil.gz, bil16.gz, and bil32.gz files
      else if (file.getName().toLowerCase().endsWith(".gz")) {
        return WWIO.readGZipFileToBuffer(file);
      } else if (!this.isMapLargeFiles() || (this.getLargeFileThreshold() > file.length())) {
        return WWIO.readFileToBuffer(file);
      } else {
        return WWIO.mapFile(file);
      }
    } else // (source instanceof java.net.URL)
    {
      java.net.URL url = (java.net.URL) source;
      return WWIO.readURLContentToBuffer(url);
    }
  }