@Override public void write(RevObject o, OutputStream out) throws IOException { final int storageVersionHeader = maxFormatCode; out.write(storageVersionHeader); writer.write(o, out); }
private byte[] encode(RevObject obj) { ByteArrayOutputStream out = new ByteArrayOutputStream(); try { encoder.write(obj, out); } catch (IOException e) { throw new RuntimeException(e); } byte[] byteArray = out.toByteArray(); return byteArray; }
private byte[] encode(RevObject obj) { ByteArrayOutputStream out = new ByteArrayOutputStream(); try { encoder.write(obj, out); } catch (IOException e) { throw new RuntimeException(e); } return out.toByteArray(); }
protected void writeObject(RevObject object, OutputStream target) { try { serializer().write(object, target); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public void funnel(RevObject object) throws IOException { out.write(object.getId().getRawValue()); serializer.write(object, out); }
private byte[] serialize(RevFeature revFeature1) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); serializer.write(revFeature1, output); byte[] data = output.toByteArray(); return data; }
@Override public void funnel(RevObject object) throws IOException { OutputStream out = getCurrentTarget(); out.write(object.getId().getRawValue()); serializer.write(object, out); out.flush(); }
private byte[] write(RevObject object) { try { ByteArrayOutputStream bout = new ByteArrayOutputStream(); serializer.write(object, bout); return bout.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }
private EncodedObject encode(RevObject o) { ByteArrayOutputStream out = new ByteArrayOutputStream(); try { serializer().write(o, out); } catch (IOException e) { throw new RuntimeException(e); } return new EncodedObject(o.getId(), o.getType(), out.toByteArray()); }
@Override public void write(RevObject o, OutputStream out) throws IOException { // compress the stream LZFOutputStream deflatedOutputStream = new LZFOutputStream(out); deflatedOutputStream.setFinishBlockOnFlush(true); factory.write(o, deflatedOutputStream); deflatedOutputStream.flush(); }
@Override public void write(RevObject o, OutputStream out) throws IOException { final int blockSize = 1 << 16; LZ4Compressor compressor = lz4factory.fastCompressor(); Checksum checksum = newChecksum(); LZ4BlockOutputStream cout = new LZ4BlockOutputStream(out, blockSize, compressor, checksum, true); factory.write(o, cout); cout.finish();// same as close but not closing the wrapped stream }
private void testCommit(RevCommit commit) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); serializer.write(commit, out); RevObject read = serializer.read(commit.getId(), new ByteArrayInputStream(out.toByteArray())); assertEquals(commit, read); }
@Override public void runInternal(GeogigCLI cli) throws IOException { checkParameter(paths.size() < 2, "Only one refspec allowed"); checkParameter(!paths.isEmpty(), "A refspec must be specified"); Console console = cli.getConsole(); GeoGIG geogig = cli.getGeogig(); String path = paths.get(0); Optional<RevObject> obj; RevObjectParse cmd = geogig.command(RevObjectParse.class).setRefSpec(path); obj = cmd.call(); if (!obj.isPresent()) { obj = cmd.setSource(geogig.getContext().indexDatabase()).call(); } checkParameter(obj.isPresent(), "refspec did not resolve to any object."); if (binary) { RevObjectSerializer factory = DataStreamRevObjectSerializerV1.INSTANCE; factory.write(obj.get(), System.out); } else { CharSequence s = geogig.command(CatObject.class) .setObject(Suppliers.ofInstance(obj.get())).call(); console.println(s); } }
@Test public void testSerializerDoesntCloseStreams() throws IOException { AtomicBoolean closed = new AtomicBoolean(false); ByteArrayOutputStream out = new ByteArrayOutputStream() { public @Override void close() { closed.set(true); } }; final RevTree orig = tree1_leaves; serializer.write(orig, out); assertFalse(closed.get()); out.close(); assertTrue(closed.get()); closed.set(false); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()) { public @Override void close() throws IOException { closed.set(true); } }; final RevObject read = serializer.read(orig.getId(), in); assertFalse(closed.get()); assertEquals(orig, read); }
protected void testFeatureReadWrite(Feature feature) throws Exception { RevFeature newFeature = RevFeature.builder().build(feature); ByteArrayOutputStream output = new ByteArrayOutputStream(); serializer.write(newFeature, output); byte[] data = output.toByteArray(); assertTrue(data.length > 0); ByteArrayInputStream input = new ByteArrayInputStream(data); RevFeature feat = (RevFeature) serializer.read(newFeature.getId(), input); assertNotNull(feat); assertEquals(newFeature.getValues().size(), feat.getValues().size()); for (int i = 0; i < newFeature.getValues().size(); i++) { Object expected = newFeature.getValues().get(i).orNull(); String msg = "At index " + i + ": " + (expected == null ? null : expected.getClass().getSimpleName()); Object actual = feat.get(i).orNull(); assertEquals(msg, expected, actual); } }
@Test public void testLargeStringValue() throws Exception { SimpleFeatureType type = DataUtilities.createType("LongStringType", "clob:String"); final int length = 256 * 1024; final String largeString = Strings.repeat("a", length); Feature feature = feature(type, "fid1", largeString); RevFeature revFeature = RevFeature.builder().build(feature); ByteArrayOutputStream output = new ByteArrayOutputStream(); serializer.write(revFeature, output); byte[] data = output.toByteArray(); ByteArrayInputStream input = new ByteArrayInputStream(data); RevFeature feat = (RevFeature) serializer.read(revFeature.getId(), input); assertNotNull(feat); assertEquals(1, feat.getValues().size()); Optional<Object> value = feat.getValues().get(0); assertTrue(value.isPresent()); String deserialized = (String) value.get(); assertEquals(largeString.length(), deserialized.length()); assertEquals(largeString, deserialized); }
serializer.write(o, out); assertFalse(closed.get());
@Test public void testFeatureTypeSerializationWGS84() throws Exception { SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder(); ftb.add("geom", Polygon.class, DefaultGeographicCRS.WGS84); ftb.setName("type"); SimpleFeatureType ftype = ftb.buildFeatureType(); RevFeatureType revFeatureType = RevFeatureType.builder().type(ftype).build(); ByteArrayOutputStream output = new ByteArrayOutputStream(); serializer.write(revFeatureType, output); byte[] data = output.toByteArray(); assertTrue(data.length > 0); ByteArrayInputStream input = new ByteArrayInputStream(data); RevFeatureType rft = (RevFeatureType) serializer.read(revFeatureType.getId(), input); assertNotNull(rft); FeatureType serializedFeatureType = rft.type(); assertEquals("EPSG:4326", CRS.toSRS(serializedFeatureType.getCoordinateReferenceSystem())); }
@Test public void testFeatureTypeSerialization() throws Exception { RevFeatureType revFeatureType = RevFeatureType.builder().type(featureType).build(); ByteArrayOutputStream output = new ByteArrayOutputStream(); serializer.write(revFeatureType, output); byte[] data = output.toByteArray(); assertTrue(data.length > 0); ByteArrayInputStream input = new ByteArrayInputStream(data); RevFeatureType rft = (RevFeatureType) serializer.read(revFeatureType.getId(), input); assertNotNull(rft); SimpleFeatureType serializedFeatureType = (SimpleFeatureType) rft.type(); assertEquals(serializedFeatureType.getDescriptors().size(), featureType.getDescriptors().size()); for (int i = 0; i < featureType.getDescriptors().size(); i++) { assertEquals(featureType.getDescriptor(i), serializedFeatureType.getDescriptor(i)); } assertEquals(featureType.getGeometryDescriptor(), serializedFeatureType.getGeometryDescriptor()); assertEquals(featureType.getCoordinateReferenceSystem(), serializedFeatureType.getCoordinateReferenceSystem()); }
serializer.write(cmtIn, bout);