public Resource getBlob() { return stObj.getBlob(); }
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)); } }
@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()); }
public void putTransient(TileObject tile) { String key = TransientCache.computeTransientKey(tile); synchronized (transientCache) { transientCache.put(key, tile.getBlob()); } }
stObj.getBlob().transferTo(channel); } catch (IOException ioe) { throw new StorageException(ioe.getMessage() + " for " + target.getAbsolutePath());
@Override public void setValue(TileObject tile) { String key = TransientCache.computeTransientKey(tile); synchronized (transientCache) { transientCache.put(key, tile.getBlob()); } } }));
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]); try (InputStream is = to.getBlob().getInputStream()) { BufferedImage image = ImageIO.read(is);
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")); }
@Test public void testSeedJpegPngMetaTiled() throws Exception { checkJpegPng( "image/vnd.jpeg-png", () -> { TileObject to = (TileObject) EasyMock.getCurrentArguments()[0]; assertEquals("image/vnd.jpeg-png", to.getBlobFormat()); assertNotNull(to.getBlob()); assertTrue(to.getBlob().getSize() > 0); String format = ImageMime.jpegPng.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); } return true; }, new RGBASourceHelper()); }
InputStream is = to.getBlob().getInputStream(); InputStream is2 = to2.getBlob().getInputStream(); checkInputStreams(is, is2); is = to.getBlob().getInputStream(); InputStream is3 = to3.getBlob().getInputStream(); checkInputStreams(is, is3); is = to.getBlob().getInputStream(); InputStream is4 = to4.getBlob().getInputStream(); checkInputStreams(is, is4);
@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()); }
@Test public void testGetTileNoUnzip() throws Exception { MbtilesInfo configuration = getDefaultConfiguration(); configuration.setGzipVector(false); MbtilesBlobStore store = new MbtilesBlobStore(configuration); addStoresToClean(store); TileObject tile = TileObject.createQueryTileObject( layer, new long[] {0, 0, 0}, "EPSG:900913", ApplicationMime.mapboxVector.getFormat(), null); assertThat(store.get(tile), is(true)); try (InputStream is = MBTilesFileVectorTileTest.class.getResourceAsStream("tile_data.pbf.gz")) { assertTrue(IOUtils.contentEquals(tile.getBlob().getInputStream(), is)); } }
@Test public void testGetTileDefaultUnzip() throws Exception { MbtilesInfo configuration = getDefaultConfiguration(); MbtilesBlobStore store = new MbtilesBlobStore(configuration); addStoresToClean(store); TileObject tile = TileObject.createQueryTileObject( layer, new long[] {0, 0, 0}, "EPSG:900913", ApplicationMime.mapboxVector.getFormat(), null); assertThat(store.get(tile), is(true)); try (InputStream is = MBTilesFileVectorTileTest.class.getResourceAsStream("tile_data.pbf.gz")) { assertTrue(IOUtils.contentEquals(tile.getBlob().getInputStream(), is)); } }
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)); }
@Test public void testGetTileDoUnzip() throws Exception { MbtilesInfo configuration = getDefaultConfiguration(); configuration.setGzipVector(true); MbtilesBlobStore store = new MbtilesBlobStore(configuration); addStoresToClean(store); TileObject tile = TileObject.createQueryTileObject( layer, new long[] {0, 0, 0}, "EPSG:900913", ApplicationMime.mapboxVector.getFormat(), null); assertThat(store.get(tile), is(true)); try (InputStream is = MBTilesFileVectorTileTest.class.getResourceAsStream("tile_data.pbf")) { assertTrue(IOUtils.contentEquals(tile.getBlob().getInputStream(), is)); } }
@Test public void testPutGet() throws MimeException, StorageException { byte[] bytes = new byte[1024]; Arrays.fill(bytes, (byte) 0xaf); TileObject tile = queryTile(20, 30, 12); tile.setBlob(new ByteArrayResource(bytes)); blobStore.put(tile); TileObject queryTile = queryTile(20, 30, 12); boolean found = blobStore.get(queryTile); assertTrue(found); Resource resource = queryTile.getBlob(); assertNotNull(resource); assertEquals(bytes.length, resource.getSize()); }
InputStream is = to2.getBlob().getInputStream(); InputStream is2 = bytes.getInputStream(); checkInputStreams(is, is2);