/** Delete a particular tile */ public boolean delete(TileObject stObj) throws StorageException { File fh = getFileHandleTile(stObj, false); boolean ret = false; // we call fh.length() here to check wthether the file exists and its length in a single // operation cause lots of calls to exists() may raise the file system cache usage to the // ceiling. File.length() returns 0 if the file does not exist anyway final long length = fh.length(); final boolean exists = length > 0; if (exists) { if (!fh.delete()) { throw new StorageException("Unable to delete " + fh.getAbsolutePath()); } stObj.setBlobSize((int) padSize(length)); listeners.sendTileDeleted(stObj); ret = true; } else { log.trace("delete unexistant file " + fh.toString()); } // Look at the parent directory to prune it if empty File parentDir = fh.getParentFile(); // Try deleting the directory (will not do it if the directory contains files) parentDir.delete(); return ret; }
obj.setBlob(resource); obj.setCreated(resource.getLastModified()); obj.setBlobSize((int) resource.getSize());
@Override public boolean get(TileObject obj) throws StorageException { final String key = keyBuilder.forTile(obj); final S3Object object = s3Ops.getObject(key); if (object == null) { return false; } try (S3ObjectInputStream in = object.getObjectContent()) { byte[] bytes = ByteStreams.toByteArray(in); obj.setBlobSize(bytes.length); obj.setBlob(new ByteArrayResource(bytes)); obj.setCreated(object.getObjectMetadata().getLastModified().getTime()); } catch (IOException e) { throw new StorageException("Error getting " + key, e); } return true; }
@Override public boolean get(TileObject obj) throws StorageException { final String key = keyBuilder.forTile(obj); final S3Object object = s3Ops.getObject(key); if (object == null) { return false; } try (S3ObjectInputStream in = object.getObjectContent()) { byte[] bytes = ByteStreams.toByteArray(in); obj.setBlobSize(bytes.length); obj.setBlob(new ByteArrayResource(bytes)); obj.setCreated(object.getObjectMetadata().getLastModified().getTime()); } catch (IOException e) { throw new StorageException("Error getting " + key, e); } return true; }
@Override public boolean get(TileObject stObj) throws StorageException { stObj.setBlob(new FileResource(imageTile)); stObj.setCreated((new Date()).getTime()); stObj.setBlobSize(1000); return true; } });
/** Store a tile. */ public void put(TileObject stObj) throws StorageException { final File fh = getFileHandleTile(stObj, true); final long oldSize = fh.length(); final boolean existed = oldSize > 0; writeFile(fh, stObj, existed); // mark the last modification as the tile creation time if set, otherwise // we'll leave it to the writing time if (stObj.getCreated() > 0) { try { fh.setLastModified(stObj.getCreated()); } catch (Exception e) { log.debug("Failed to set the last modified time to match the tile request time", e); } } /* * This is important because listeners may be tracking tile existence */ stObj.setBlobSize((int) padSize(stObj.getBlobSize())); if (existed) { listeners.sendTileUpdated(stObj, padSize(oldSize)); } else { listeners.sendTileStored(stObj); } }
/** * Set the blob property of a TileObject. * * @param stObj the tile to load. Its setBlob() method will be called. * @return true if successful, false otherwise */ public boolean get(TileObject stObj) throws StorageException { File fh = getFileHandleTile(stObj, false); if (!fh.exists()) { stObj.setStatus(Status.MISS); return false; } else { Resource resource = readFile(fh); stObj.setBlob(resource); stObj.setCreated(resource.getLastModified()); stObj.setBlobSize((int) resource.getSize()); return true; } }
if (olData != null) { tile.setBlobSize(olData.length); mbtiles.saveTile(gtTile);
if (olData != null) { tile.setBlobSize(olData.length); mbtiles.saveTile(gtTile);
@Override public boolean delete(TileObject obj) throws StorageException { final String key = keyBuilder.forTile(obj); // don't bother for the extra call if there are no listeners if (listeners.isEmpty()) { return s3Ops.deleteObject(key); } ObjectMetadata oldObj = s3Ops.getObjectMetadata(key); if (oldObj == null) { return false; } s3Ops.deleteObject(key); obj.setBlobSize((int) oldObj.getContentLength()); listeners.sendTileDeleted(obj); return true; }
@Override public boolean delete(TileObject obj) throws StorageException { final String key = keyBuilder.forTile(obj); // don't bother for the extra call if there are no listeners if (listeners.isEmpty()) { return s3Ops.deleteObject(key); } ObjectMetadata oldObj = s3Ops.getObjectMetadata(key); if (oldObj == null) { return false; } s3Ops.deleteObject(key); obj.setBlobSize((int) oldObj.getContentLength()); listeners.sendTileDeleted(obj); return true; }
stObj.setBlob(new FileResource(imageTile)); stObj.setCreated((new Date()).getTime()); stObj.setBlobSize(1000); return true; });