private static Slice decompressGzip(Slice input, int uncompressedSize) throws IOException { if (uncompressedSize == 0) { return EMPTY_SLICE; } DynamicSliceOutput sliceOutput = new DynamicSliceOutput(uncompressedSize); byte[] buffer = new byte[uncompressedSize]; try (InputStream gzipInputStream = new GZIPInputStream(input.getInput(), GZIP_BUFFER_SIZE)) { int bytesRead; while ((bytesRead = gzipInputStream.read(buffer)) != -1) { sliceOutput.write(buffer, 0, bytesRead); } return sliceOutput.getUnderlyingSlice(); } }
private static void writeGeometryCollection(Geometry collection, DynamicSliceOutput output) { output.appendByte(GeometrySerializationType.GEOMETRY_COLLECTION.code()); for (int geometryIndex = 0; geometryIndex < collection.getNumGeometries(); geometryIndex++) { Geometry geometry = collection.getGeometryN(geometryIndex); int startPosition = output.size(); // leave 4 bytes for the shape length output.appendInt(0); writeGeometry(geometry, output); int endPosition = output.size(); int length = endPosition - startPosition - Integer.BYTES; output.getUnderlyingSlice().setInt(startPosition, length); } }
private static void writeGeometryCollection(DynamicSliceOutput output, OGCGeometryCollection collection) { output.appendByte(GeometrySerializationType.GEOMETRY_COLLECTION.code()); for (int geometryIndex = 0; geometryIndex < collection.numGeometries(); geometryIndex++) { OGCGeometry geometry = collection.geometryN(geometryIndex); int startPosition = output.size(); // leave 4 bytes for the shape length output.appendInt(0); writeGeometry(output, geometry); int endPosition = output.size(); int length = endPosition - startPosition - Integer.BYTES; output.getUnderlyingSlice().setInt(startPosition, length); } }
byte[] base = (byte[]) slice.getUnderlyingSlice().getBase(); RequestBody body = RequestBody.create(mediaType, base, 0, slice.size());
private static Slice decompressGzip(Slice input, int uncompressedSize) throws IOException { if (uncompressedSize == 0) { return EMPTY_SLICE; } DynamicSliceOutput sliceOutput = new DynamicSliceOutput(uncompressedSize); byte[] buffer = new byte[uncompressedSize]; try (InputStream gzipInputStream = new GZIPInputStream(input.getInput(), GZIP_BUFFER_SIZE)) { int bytesRead; while ((bytesRead = gzipInputStream.read(buffer)) != -1) { sliceOutput.write(buffer, 0, bytesRead); } return sliceOutput.getUnderlyingSlice(); } }
private static Slice decompressGzip(Slice input, int uncompressedSize) throws IOException { if (uncompressedSize == 0) { return EMPTY_SLICE; } DynamicSliceOutput sliceOutput = new DynamicSliceOutput(uncompressedSize); byte[] buffer = new byte[uncompressedSize]; try (InputStream gzipInputStream = new GZIPInputStream(input.getInput(), GZIP_BUFFER_SIZE)) { int bytesRead; while ((bytesRead = gzipInputStream.read(buffer)) != -1) { sliceOutput.write(buffer, 0, bytesRead); } return sliceOutput.getUnderlyingSlice(); } }
@Test public void testRetainedSize() throws Exception { int sliceOutputInstanceSize = ClassLayout.parseClass(DynamicSliceOutput.class).instanceSize(); DynamicSliceOutput output = new DynamicSliceOutput(10); long originalRetainedSize = output.getRetainedSize(); assertEquals(originalRetainedSize, sliceOutputInstanceSize + output.getUnderlyingSlice().getRetainedSize()); assertEquals(output.size(), 0); output.appendLong(0); output.appendShort(0); assertEquals(output.getRetainedSize(), originalRetainedSize); assertEquals(output.size(), 10); }
@Test public void testRetainedSize() throws Exception { int sliceOutputInstanceSize = ClassLayout.parseClass(DynamicSliceOutput.class).instanceSize(); DynamicSliceOutput output = new DynamicSliceOutput(10); long originalRetainedSize = output.getRetainedSize(); assertEquals(originalRetainedSize, sliceOutputInstanceSize + output.getUnderlyingSlice().getRetainedSize()); assertEquals(output.size(), 0); output.appendLong(0); output.appendShort(0); assertEquals(output.getRetainedSize(), originalRetainedSize); assertEquals(output.size(), 10); }
private static void writeGeometryCollection(DynamicSliceOutput output, OGCGeometryCollection collection) { output.appendByte(GeometrySerializationType.GEOMETRY_COLLECTION.code()); for (int geometryIndex = 0; geometryIndex < collection.numGeometries(); geometryIndex++) { OGCGeometry geometry = collection.geometryN(geometryIndex); int startPosition = output.size(); // leave 4 bytes for the shape length output.appendInt(0); writeGeometry(output, geometry); int endPosition = output.size(); int length = endPosition - startPosition - Integer.BYTES; output.getUnderlyingSlice().setInt(startPosition, length); } }
private static void writeGeometryCollection(DynamicSliceOutput output, OGCGeometryCollection collection) { output.appendByte(GeometrySerializationType.GEOMETRY_COLLECTION.code()); for (int geometryIndex = 0; geometryIndex < collection.numGeometries(); geometryIndex++) { OGCGeometry geometry = collection.geometryN(geometryIndex); int startPosition = output.size(); // leave 4 bytes for the shape length output.appendInt(0); writeGeometry(output, geometry); int endPosition = output.size(); int length = endPosition - startPosition - Integer.BYTES; output.getUnderlyingSlice().setInt(startPosition, length); } }
private static void writeGeometryCollection(Geometry collection, DynamicSliceOutput output) { output.appendByte(GeometrySerializationType.GEOMETRY_COLLECTION.code()); for (int geometryIndex = 0; geometryIndex < collection.getNumGeometries(); geometryIndex++) { Geometry geometry = collection.getGeometryN(geometryIndex); int startPosition = output.size(); // leave 4 bytes for the shape length output.appendInt(0); writeGeometry(geometry, output); int endPosition = output.size(); int length = endPosition - startPosition - Integer.BYTES; output.getUnderlyingSlice().setInt(startPosition, length); } }
private static void writeGeometryCollection(Geometry collection, DynamicSliceOutput output) { output.appendByte(GeometrySerializationType.GEOMETRY_COLLECTION.code()); for (int geometryIndex = 0; geometryIndex < collection.getNumGeometries(); geometryIndex++) { Geometry geometry = collection.getGeometryN(geometryIndex); int startPosition = output.size(); // leave 4 bytes for the shape length output.appendInt(0); writeGeometry(geometry, output); int endPosition = output.size(); int length = endPosition - startPosition - Integer.BYTES; output.getUnderlyingSlice().setInt(startPosition, length); } }
private static void writeGeometryCollection(DynamicSliceOutput output, OGCGeometryCollection collection) { output.appendByte(GeometrySerializationType.GEOMETRY_COLLECTION.code()); for (int geometryIndex = 0; geometryIndex < collection.numGeometries(); geometryIndex++) { OGCGeometry geometry = collection.geometryN(geometryIndex); int startPosition = output.size(); // leave 4 bytes for the shape length output.appendInt(0); writeGeometry(output, geometry); int endPosition = output.size(); int length = endPosition - startPosition - Integer.BYTES; output.getUnderlyingSlice().setInt(startPosition, length); } }
private static void writeGeometryCollection(Geometry collection, DynamicSliceOutput output) { output.appendByte(GeometrySerializationType.GEOMETRY_COLLECTION.code()); for (int geometryIndex = 0; geometryIndex < collection.getNumGeometries(); geometryIndex++) { Geometry geometry = collection.getGeometryN(geometryIndex); int startPosition = output.size(); // leave 4 bytes for the shape length output.appendInt(0); writeGeometry(geometry, output); int endPosition = output.size(); int length = endPosition - startPosition - Integer.BYTES; output.getUnderlyingSlice().setInt(startPosition, length); } }