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; } }
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; }
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); } }
@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(); }
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; }