List of usage examples for org.apache.commons.io IOUtils contentEquals
public static boolean contentEquals(Reader input1, Reader input2) throws IOException
From source file:org.geowebcache.sqlite.MbtilesPBFTest.java
@Test public void testGetTileDoUnzip() throws Exception { MbtilesConfiguration configuration = getDefaultConfiguration(); configuration.setGzipVector(true);/* w ww .j a va 2 s. c om*/ 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)); } }
From source file:org.geowebcache.sqlite.MbtilesPBFTest.java
@Test public void testGetTileNoUnzip() throws Exception { MbtilesConfiguration configuration = getDefaultConfiguration(); configuration.setGzipVector(false);/*from w w w. j a v a 2 s . co m*/ 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)); } }
From source file:org.geowebcache.storage.blobstore.memory.MemoryBlobStoreTest.java
/** * Checks if the streams are equals, note that this method also closes the {@link InputStream} *///from www. ja v a 2s . c o m private void checkInputStreams(InputStream is, InputStream is2) throws IOException { try { assertTrue(IOUtils.contentEquals(is, is2)); } finally { try { is.close(); } catch (IOException e) { LOG.error(e.getMessage(), e); assertTrue(false); } try { is2.close(); } catch (IOException e) { LOG.error(e.getMessage(), e); assertTrue(false); } } }
From source file:org.geowebcache.storage.BlobStoreTest.java
public void testTile() throws Exception { FileBlobStore fbs = setup();/*from w ww. j a v a2 s . c o m*/ 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()); InputStream is = to.getBlob().getInputStream(); InputStream is2 = to2.getBlob().getInputStream(); try { assertTrue(IOUtils.contentEquals(is, is2)); } finally { is.close(); is2.close(); } }
From source file:org.geowebcache.storage.BlobStoreTest.java
public void testTileDelete() throws Exception { FileBlobStore fbs = setup();//from w w w . j a v a 2 s . c o m 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); InputStream is = to2.getBlob().getInputStream(); InputStream is2 = bytes.getInputStream(); try { assertTrue(IOUtils.contentEquals(is, is2)); } finally { is.close(); is2.close(); } 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)); }
From source file:org.geowebcache.storage.BlobStoreTest.java
public void testTilRangeDelete() throws Exception { FileBlobStore fbs = setup();//from www .ja va 2 s . c om Resource bytes = new ByteArrayResource("1 2 3 4 5 6 test".getBytes()); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("a", "x"); parameters.put("b", ""); MimeType mime = ImageMime.png; SRS srs = SRS.getEPSG4326(); String layerName = "test:123123 112"; int zoomLevel = 7; int x = 25; int y = 6; // long[] origXYZ = {x,y,zoomLevel}; TileObject[] tos = new TileObject[6]; for (int i = 0; i < tos.length; i++) { long[] xyz = { x + i - 1, y, zoomLevel }; tos[i] = TileObject.createCompleteTileObject(layerName, xyz, srs.toString(), mime.getFormat(), parameters, bytes); fbs.put(tos[i]); } long[][] rangeBounds = new long[zoomLevel + 2][5]; int zoomStart = zoomLevel - 1; int zoomStop = zoomLevel + 1; long[] range = { x, y, x + tos.length - 3, y, zoomLevel }; rangeBounds[zoomLevel] = range; TileRange trObj = new TileRange(layerName, srs.toString(), zoomStart, zoomStop, rangeBounds, mime, parameters); fbs.delete(trObj); // starting x and x + tos.length should have data, the remaining should not TileObject firstTO = TileObject.createQueryTileObject(layerName, tos[0].xyz, srs.toString(), mime.getFormat(), parameters); fbs.get(firstTO); InputStream is = firstTO.getBlob().getInputStream(); InputStream is2 = bytes.getInputStream(); try { assertTrue(IOUtils.contentEquals(is, is2)); } finally { is.close(); is2.close(); } TileObject lastTO = TileObject.createQueryTileObject(layerName, tos[tos.length - 1].xyz, srs.toString(), mime.getFormat(), parameters); fbs.get(lastTO); is = lastTO.getBlob().getInputStream(); is2 = bytes.getInputStream(); try { assertTrue(IOUtils.contentEquals(is, is2)); } finally { is.close(); is2.close(); } TileObject midTO = TileObject.createQueryTileObject(layerName, tos[(tos.length - 1) / 2].xyz, srs.toString(), mime.getFormat(), parameters); fbs.get(midTO); Resource res = midTO.getBlob(); assertNull(res); }
From source file:org.geowebcache.util.FileMatchers.java
public static Matcher<Resource> resource(final Resource expected) { return new BaseMatcher<Resource>() { @Override/* ww w . ja v a 2 s . co m*/ public boolean matches(Object item) { if (item instanceof Resource) { try (InputStream itemStream = ((Resource) item).getInputStream(); InputStream expectedStream = expected.getInputStream();) { return IOUtils.contentEquals(itemStream, expectedStream); } catch (IOException e) { return false; } } else { return false; } } @Override public void describeTo(Description description) { description.appendText("Resource with content equal to that given"); } @Override public void describeMismatch(Object item, Description description) { if (item instanceof Resource) { description.appendText("did not match given Resource"); } else { description.appendText("was not a Resource"); } } }; }
From source file:org.hippoecm.frontend.plugins.gallery.imageutil.ScaleImageOperationTest.java
@Test public void scaleToOriginalDimensionsWhenBoundingBoxMatchesOriginalDimensions() throws GalleryException, IOException { InputStream data = getClass().getResourceAsStream("/test-380x428.jpg"); ScaleImageOperation scaleOp = new ScaleImageOperation(380, 428, false, ImageUtils.ScalingStrategy.SPEED); scaleOp.execute(data, "image/jpeg"); checkImageDimensions(scaleOp, "image/jpeg", 380, 428); // redo scaling to check the data itself data = getClass().getResourceAsStream("/test-380x428.jpg"); scaleOp = new ScaleImageOperation(380, 428, false, ImageUtils.ScalingStrategy.SPEED); scaleOp.execute(data, "image/jpeg"); InputStream original = getClass().getResourceAsStream("/test-380x428.jpg"); assertFalse("Original image data should not be used as-is", IOUtils.contentEquals(original, scaleOp.getScaledData())); }
From source file:org.hippoecm.frontend.plugins.gallery.imageutil.ScaleImageOperationTest.java
@Test public void unboundedBoundingBoxPreservesOriginalData() throws GalleryException, IOException { InputStream data = getClass().getResourceAsStream("/test-380x428.jpg"); ScaleImageOperation scaleOp = new ScaleImageOperation(0, 0, false, ImageUtils.ScalingStrategy.SPEED); scaleOp.execute(data, "image/jpeg"); InputStream original = getClass().getResourceAsStream("/test-380x428.jpg"); assertTrue("Original image data should be stored as-is", IOUtils.contentEquals(original, scaleOp.getScaledData())); }
From source file:org.hippoecm.frontend.plugins.gallery.imageutil.ScaleImageOperationTest.java
@Test public void scaleToOriginalDimensionsWhenScalingUpAndUpscalingIsDisabled() throws GalleryException, IOException { InputStream data = getClass().getResourceAsStream("/test-380x428.jpg"); ScaleImageOperation scaleOp = new ScaleImageOperation(500, 500, false, ImageUtils.ScalingStrategy.SPEED); scaleOp.execute(data, "image/jpeg"); checkImageDimensions(scaleOp, "image/jpeg", 380, 428); // redo scaling to check the data itself data = getClass().getResourceAsStream("/test-380x428.jpg"); scaleOp = new ScaleImageOperation(500, 500, false, ImageUtils.ScalingStrategy.SPEED); scaleOp.execute(data, "image/jpeg"); InputStream original = getClass().getResourceAsStream("/test-380x428.jpg"); assertFalse("Original image data should not be used as-is", IOUtils.contentEquals(original, scaleOp.getScaledData())); }