Resource blob = obj.getBlob(); final ByteArrayResource finalBlob; if (obj.getBlob() instanceof ByteArrayResource) { if (LOG.isDebugEnabled()) { LOG.debug("Resource is already a Byte Array, only a copy is needed"); ByteArrayResource byteArrayResource = (ByteArrayResource) obj.getBlob(); byte[] contents = byteArrayResource.getContents(); finalBlob = new ByteArrayResource(contents); TileObject.createCompleteTileObject( obj.getLayerName(), obj.getXYZ(), obj.getGridSetId(), obj.getBlobFormat(), obj.getParameters(), finalBlob); return cached;
LOGGER.debug(String.format("Tile '%s' mapped to file '%s'.", tile, file)); initDatabaseFileIfNeeded(file, tile.getLayerName(), tile.getBlobFormat()); tile.getXYZ()[2], tile.getXYZ()[0], tile.getXYZ()[1]); bytes = gtTile.getData(); tile.setBlob(Utils.byteArrayToResource(bytes)); getTileCreateTime(file, tile.getXYZ()[2], tile.getXYZ()[0], tile.getXYZ()[1]); if (createdTime == null) { file, tile.getXYZ()[2], tile.getXYZ()[0], tile.getXYZ()[1], createdTime); tile.setCreated(createdTime); } else if (exists) { tile.setCreated(System.currentTimeMillis());
@Override public boolean get(TileObject stObj) throws StorageException { stObj.setBlob(new FileResource(imageTile)); stObj.setCreated((new Date()).getTime()); stObj.setBlobSize(1000); return true; } });
public void sendTileStored(final TileObject stObj) { final long[] xyz = stObj.getXYZ(); final String layerName = stObj.getLayerName(); final String gridSetId = stObj.getGridSetId(); final String blobFormat = stObj.getBlobFormat(); final String paramsId = stObj.getParametersId(); final int blobSize = stObj.getBlobSize(); sendTileStored( layerName, gridSetId, blobFormat, paramsId, xyz[0], xyz[1], (int) xyz[2], blobSize); }
/** Builds the complete file path associated to the provided tile. */ File getFile(TileObject tile) { if (tile.getParametersId() == null && tile.getParameters() != null) { tile.setParametersId(ParametersUtils.getId(tile.getParameters())); } return getFile( tile.getParametersId(), tile.getXYZ(), tile.getLayerName(), tile.getGridSetId(), tile.getBlobFormat(), tile.getParameters()); }
protected void persistParameterMap(TileObject stObj) { if (Objects.nonNull(stObj.getParametersId())) { putLayerMetadata( stObj.getLayerName(), "parameters." + stObj.getParametersId(), ParametersUtils.getKvp(stObj.getParameters())); } }
public void testTile() throws Exception { fbs = setup(); Resource bytes = new ByteArrayResource("1 2 3 4 5 6 test".getBytes()); long[] xyz = {1L, 2L, 3L}; Map<String, String> parameters = new HashMap<String, String>(); parameters.put("a", "x"); parameters.put("b", "ø"); TileObject to = TileObject.createCompleteTileObject( "test:123123 112", xyz, "EPSG:4326", "image/jpeg", parameters, bytes); fbs.put(to); TileObject to2 = TileObject.createQueryTileObject( "test:123123 112", xyz, "EPSG:4326", "image/jpeg", parameters); fbs.get(to2); assertEquals(to.getBlobFormat(), to2.getBlobFormat()); try (InputStream is = to.getBlob().getInputStream(); InputStream is2 = to2.getBlob().getInputStream()) { assertTrue(IOUtils.contentEquals(is, is2)); } }
public void testTileDelete() throws Exception { fbs = setup(); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("a", "x"); parameters.put("b", "ø"); Resource bytes = new ByteArrayResource("1 2 3 4 5 6 test".getBytes()); long[] xyz = {5L, 6L, 7L}; TileObject to = TileObject.createCompleteTileObject( "test:123123 112", xyz, "EPSG:4326", "image/jpeg", parameters, bytes); fbs.put(to); TileObject to2 = TileObject.createQueryTileObject( "test:123123 112", xyz, "EPSG:4326", "image/jpeg", parameters); fbs.get(to2); try (InputStream is = to2.getBlob().getInputStream(); InputStream is2 = bytes.getInputStream()) { assertTrue(IOUtils.contentEquals(is, is2)); } TileObject to3 = TileObject.createQueryTileObject( "test:123123 112", xyz, "EPSG:4326", "image/jpeg", parameters); fbs.delete(to3); TileObject to4 = TileObject.createQueryTileObject( "test:123123 112", xyz, "EPSG:4326", "image/jpeg", parameters); assertFalse(fbs.get(to4)); }
Arrays.fill(bytes, (byte) 0xaf); TileObject tile = queryTile(20, 30, 12); tile.setBlob(new ByteArrayResource(bytes)); eq(tile.getLayerName()), eq(tile.getGridSetId()), eq(tile.getBlobFormat()), anyString(), eq(20L), tile.setBlob(new ByteArrayResource(new byte[512])); eq(tile.getLayerName()), eq(tile.getGridSetId()), eq(tile.getBlobFormat()), anyString(), eq(20L),
@Override public void put(TileObject obj) throws StorageException { final Resource blob = obj.getBlob(); checkNotNull(blob); checkNotNull(obj.getBlobFormat()); objectMetadata.setContentLength(blob.getSize()); String blobFormat = obj.getBlobFormat(); String mimeType; try { s3Ops.putObject(putObjectRequest); putParametersMetadata(obj.getLayerName(), obj.getParametersId(), obj.getParameters());
@Test public void testSeedJpegPng8MetaTiled() throws Exception { checkJpegPng( "image/vnd.jpeg-png8", () -> { TileObject to = (TileObject) EasyMock.getCurrentArguments()[0]; assertEquals("image/vnd.jpeg-png8", to.getBlobFormat()); assertNotNull(to.getBlob()); assertTrue(to.getBlob().getSize() > 0); String format = ImageMime.jpegPng8.getMimeType(to.getBlob()); long[] xyz = to.getXYZ(); assertEquals(10, xyz[2]); // check the ones in the full black area are jpeg, the others png if (xyz[0] == 900 || xyz[1] == 602) { assertEquals("image/jpeg", format); } else { assertEquals("image/png", format); // verify the image has been paletted try (InputStream inputStream = to.getBlob().getInputStream(); ) { BufferedImage image = ImageIO.read(inputStream); assertThat(image.getColorModel(), instanceOf(IndexColorModel.class)); } } return true; }, new RGBASourceHelper()); }
LOGGER.debug(String.format("Tile '%s' mapped to file '%s'.", tile, file)); initDatabaseFileIfNeeded(file, tile.getLayerName(), tile.getBlobFormat()); new MBTilesTile(tile.getXYZ()[2], tile.getXYZ()[0], tile.getXYZ()[1]); try { final boolean gzipped = tileIsGzipped(tile); bytes = Utils.resourceToByteArray(tile.getBlob()); olData = mbtiles.loadTile( tile.getXYZ()[2], tile.getXYZ()[0], tile.getXYZ()[1]) .getData(); tile.getXYZ()[2], tile.getXYZ()[0], tile.getXYZ()[1], System.currentTimeMillis());
/** * * Static method for generating the {@link TileObject} cache key to use for caching. * * @param obj * @return {@link TileObject} key */ public static String generateTileKey(TileObject obj) { Map<String, String> parameters = obj.getParameters(); StringBuilder builder = new StringBuilder(obj.getLayerName()) .append(SEPARATOR) .append(obj.getGridSetId()) .append(SEPARATOR) .append(Arrays.toString(obj.getXYZ())) .append(SEPARATOR) .append(obj.getBlobFormat()); // If parameters are present they must be handled if (parameters != null && !parameters.isEmpty()) { for (String key : parameters.keySet()) { builder.append(SEPARATOR).append(key).append(SEPARATOR).append(parameters.get(key)); } } return builder.toString(); }
private void checkThatStoreContainsReplacedTiles(String relativePathA, String relativePathB) throws Exception { // instantiating the store File rootDirectory = OperationsRestWebConfig.ROOT_DIRECTORY; MbtilesInfo configuration = new MbtilesInfo(); configuration.setRootDirectory(rootDirectory.getPath()); configuration.setTemplatePath( Utils.buildPath("{grid}", "{layer}", "{format}", "{z}", "tiles-{x}-{y}.sqlite")); MbtilesBlobStore store = new MbtilesBlobStore(configuration); addStoresToClean(store); // checking that all the files are present File fileA = new File(OperationsRestWebConfig.ROOT_DIRECTORY, relativePathA); File fileB = new File(OperationsRestWebConfig.ROOT_DIRECTORY, relativePathB); assertThat(fileA.exists(), is(true)); assertThat(fileB.exists(), is(true)); // let's query the store to see if we get the replaced tiles TileObject getTile = TileObject.createQueryTileObject( "africa", new long[] {10, 50, 5}, "EPSG:4326", "image/png", null); assertThat(store.get(getTile), is(true)); assertThat(getTile.getBlob(), notNullValue()); assertThat(TestSupport.resourceToString(getTile.getBlob()), is("IMAGE-10-50-5-B")); // let's query the second tile getTile = TileObject.createQueryTileObject( "africa", new long[] {10, 5050, 15}, "EPSG:4326", "image/png", null); assertThat(store.get(getTile), is(true)); assertThat(getTile.getBlob(), notNullValue()); assertThat(TestSupport.resourceToString(getTile.getBlob()), is("IMAGE-15-5050-5-B")); }
LOG.debug("TileObject:" + obj + " found, update the input TileObject"); Resource resource = cached.getBlob(); obj.setBlob(resource); obj.setCreated(resource.getLastModified()); obj.setBlobSize((int) resource.getSize());
TileObject.createCompleteTileObject( "africa", new long[] {10, 50, 5}, TileObject.createQueryTileObject( "africa", new long[] {10, 50, 5}, "EPSG:4326", "image/png", null); assertThat(getTile.getBlob(), notNullValue()); assertThat(resourceToString(getTile.getBlob()), is("IMAGE-10-50-5")); assertThat(getTile.getCreated(), greaterThan(System.currentTimeMillis() - 60000)); TileObject.createQueryTileObject( "africa", new long[] {10, 50, 5}, "EPSG:4326", "image/png", null); assertThat(getTile.getBlob(), nullValue());
Map<String, String> params2 = Collections.singletonMap("testKey", "testValue2"); TileObject toCache1 = TileObject.createCompleteTileObject( "testLayer", new long[] {0L, 0L, 0L}, new ByteArrayResource("1,2,4,5,6 test".getBytes(StandardCharsets.UTF_8))); TileObject toCache2 = TileObject.createCompleteTileObject( "testLayer", new long[] {0L, 0L, 0L}, params2, new ByteArrayResource("7,8,9,10 test".getBytes(StandardCharsets.UTF_8))); final long size2 = toCache2.getBlobSize(); TileObject.createQueryTileObject( "testLayer", new long[] {0L, 0L, 0L}, "testGridSet", "image/png", params2);
/** * 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; } }
@Test public void testPutGetBlobIsNotByteArrayResource() throws MimeException, IOException { File tileFile = File.createTempFile("tile", ".png"); Files.write(new byte[1024], tileFile); Resource blob = new FileResource(tileFile); TileObject tile = queryTile(20, 30, 12); tile.setBlob(blob); blobStore.put(tile); TileObject queryTile = queryTile(20, 30, 12); boolean found = blobStore.get(queryTile); assertTrue(found); Resource resource = queryTile.getBlob(); assertNotNull(resource); assertEquals(1024, resource.getSize()); }
public void testPathNoParams() throws Exception { TileObject tile = TileObject.createCompleteTileObject( "states", new long[] {0, 0, 0}, "EPSG:2163", "png", null, null); File path = generator.tilePath(tile, ImageMime.png); File expected = new File(testRoot, "states/EPSG_2163_00/0_0/00_00.png"); assertEquals(expected, path); }