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);
    }
  }
  protected static String buildLocationPath(String property, String append, String wwDir) {
    String path = propertyToPath(property);

    if (append != null && append.length() != 0) path = WWIO.appendPathPart(path, append.trim());

    if (wwDir != null && wwDir.length() != 0) path = WWIO.appendPathPart(path, wwDir.trim());

    return path;
  }
  protected static String normalizeFileStoreName(String fileName) {
    // Convert all file separators to forward slashes, and strip any leading or trailing file
    // separators
    // from the path.
    String normalizedName = fileName.replaceAll("\\\\", "/");
    normalizedName = WWIO.stripLeadingSeparator(normalizedName);
    normalizedName = WWIO.stripTrailingSeparator(normalizedName);

    return normalizedName;
  }
 protected void saveBuffer(java.nio.ByteBuffer buffer, java.io.File outFile)
     throws java.io.IOException {
   synchronized (this.fileLock) // sychronized with read of file in RequestTask.run()
   {
     WWIO.saveBuffer(buffer, outFile);
   }
 }
  protected boolean loadTile(Tile tile, java.net.URL url) {
    if (WWIO.isFileOutOfDate(url, this.placeNameServiceSet.getExpiryTime())) {
      // The file has expired. Delete it then request download of newer.
      this.getDataFileStore().removeFile(url);
      String message = Logging.getMessage("generic.DataFileExpired", url);
      Logging.logger().fine(message);
      return false;
    }

    PlaceNameChunk tileData;
    synchronized (this.fileLock) {
      tileData = readTileData(tile, url);
    }

    if (tileData == null) {
      // Assume that something's wrong with the file and delete it.
      this.getDataFileStore().removeFile(url);
      tile.getPlaceNameService()
          .markResourceAbsent(tile.getPlaceNameService().getTileNumber(tile.row, tile.column));
      String message = Logging.getMessage("generic.DeletedCorruptDataFile", url);
      Logging.logger().fine(message);
      return false;
    }

    tile.setDataChunk(tileData);
    WorldWind.getMemoryCache(Tile.class.getName()).add(tile.getFileCachePath(), tile);
    return true;
  }
    public ComposeImageTile(Sector sector, String mimeType, Level level, int width, int height)
        throws IOException {
      super(sector, level, -1, -1); // row and column aren't used and need to signal that

      this.width = width;
      this.height = height;

      this.file =
          File.createTempFile(WWIO.DELETE_ON_EXIT_PREFIX, WWIO.makeSuffixForMimeType(mimeType));
    }
    @Override
    protected ByteBuffer handleXMLContent() throws IOException {
      // Check for an exception report
      String s = WWIO.byteBufferToString(this.getRetriever().getBuffer(), 1024, null);
      if (s.contains("<ExceptionReport>")) {
        // TODO: Parse the xml and include only the message text in the log message.

        StringBuilder sb = new StringBuilder(this.getRetriever().getName());

        sb.append("\n");
        sb.append(WWIO.byteBufferToString(this.getRetriever().getBuffer(), 2048, null));
        Logging.logger().warning(sb.toString());

        return null;
      }

      this.saveBuffer();

      return this.getRetriever().getBuffer();
    }
  /**
   * Determine if a host is reachable by attempting to resolve the host name, and then attempting to
   * open a connection.
   *
   * @param hostName Name of the host to connect to.
   * @return {@code true} if a the host is reachable, {@code false} if the host name cannot be
   *     resolved, or if opening a connection to the host fails.
   */
  protected static boolean isHostReachable(String hostName) {
    try {
      // Assume host is unreachable if we can't get its dns entry without getting an exception
      //noinspection ResultOfMethodCallIgnored
      InetAddress.getByName(hostName);
    } catch (UnknownHostException e) {
      String message = Logging.getMessage("NetworkStatus.UnreachableTestHost", hostName);
      Logging.verbose(message);
      return false;
    } catch (Exception e) {
      String message = Logging.getMessage("NetworkStatus.ExceptionTestingHost", hostName);
      Logging.verbose(message);
      return false;
    }

    // Was able to get internet address, but host still might not be reachable because the address
    // might have been
    // cached earlier when it was available. So need to try something else.

    URLConnection connection = null;
    try {
      URL url = new URL("http://" + hostName);
      Proxy proxy = WWIO.configureProxy();
      if (proxy != null) connection = url.openConnection(proxy);
      else connection = url.openConnection();

      connection.setConnectTimeout(2000);
      connection.setReadTimeout(2000);
      String ct = connection.getContentType();
      if (ct != null) return true;
    } catch (IOException e) {
      String message = Logging.getMessage("NetworkStatus.ExceptionTestingHost", hostName);
      Logging.info(message);
    } finally {
      if (connection instanceof HttpURLConnection) ((HttpURLConnection) connection).disconnect();
    }

    return false;
  }