public ByteBuffer run(Retriever retriever) {
      if (!retriever.getState().equals(Retriever.RETRIEVER_STATE_SUCCESSFUL)) return null;

      HTTPRetriever htr = (HTTPRetriever) retriever;
      if (htr.getResponseCode() == HttpURLConnection.HTTP_NO_CONTENT) {
        // Mark tile as missing to avoid excessive attempts
        MercatorTiledImageLayer.this.levels.markResourceAbsent(tile);
        return null;
      }

      if (htr.getResponseCode() != HttpURLConnection.HTTP_OK) return null;

      URLRetriever r = (URLRetriever) retriever;
      ByteBuffer buffer = r.getBuffer();

      String suffix = WWIO.makeSuffixForMimeType(htr.getContentType());
      if (suffix == null) {
        return null; // TODO: log error
      }

      String path = tile.getPath().substring(0, tile.getPath().lastIndexOf("."));
      path += suffix;

      final File outFile = WorldWind.getDataFileStore().newFile(path);
      if (outFile == null) return null;

      try {
        WWIO.saveBuffer(buffer, outFile);
        return buffer;
      } catch (IOException e) {
        e.printStackTrace(); // TODO: log error
        return null;
      }
    }
コード例 #2
0
  protected BufferedImage getImage(Object imageSource) {
    if (imageSource instanceof String) {
      String path = (String) imageSource;

      Object streamOrException = WWIO.getFileOrResourceAsStream(path, this.getClass());
      if (streamOrException == null || streamOrException instanceof Exception) {
        Logging.logger()
            .log(
                java.util.logging.Level.SEVERE,
                "generic.ExceptionAttemptingToReadImageFile",
                streamOrException != null ? streamOrException : path);
        return null;
      }

      try {
        return ImageIO.read((InputStream) streamOrException);
      } catch (Exception e) {
        Logging.logger()
            .log(
                java.util.logging.Level.SEVERE, "generic.ExceptionAttemptingToReadImageFile", path);
        return null;
      }
    } else if (imageSource instanceof BufferedImage) {
      return (BufferedImage) imageSource;
    }

    return null;
  }
  private BufferedImage requestImage(MercatorTextureTile tile, String mimeType)
      throws URISyntaxException {
    String pathBase = tile.getPath().substring(0, tile.getPath().lastIndexOf("."));
    String suffix = WWIO.makeSuffixForMimeType(mimeType);
    String path = pathBase + suffix;
    URL url = WorldWind.getDataFileStore().findFile(path, false);

    if (url == null) // image is not local
    return null;

    if (WWIO.isFileOutOfDate(url, tile.getLevel().getExpiryTime())) {
      // The file has expired. Delete it.
      WorldWind.getDataFileStore().removeFile(url);
      String message = Logging.getMessage("generic.DataFileExpired", url);
      Logging.logger().fine(message);
    } else {
      try {
        File imageFile = new File(url.toURI());
        BufferedImage image = ImageIO.read(imageFile);
        if (image == null) {
          String message = Logging.getMessage("generic.ImageReadFailed", imageFile);
          throw new RuntimeException(message);
        }

        this.levels.unmarkResourceAbsent(tile);
        return image;
      } catch (IOException e) {
        // Assume that something's wrong with the file and delete it.
        gov.nasa.worldwind.WorldWind.getDataFileStore().removeFile(url);
        this.levels.markResourceAbsent(tile);
        String message = Logging.getMessage("generic.DeletedCorruptDataFile", url);
        Logging.logger().info(message);
      }
    }

    return null;
  }
コード例 #4
0
 /** {@inheritDoc} */
 public URL getContentURL() {
   if (this.webViewWindowPtr != 0) {
     return WWIO.makeURL(WindowsWebViewJNI.getContentURL(this.webViewWindowPtr));
   }
   return null;
 }