private Resource makeProtoResource(final ProtoSerializable field, final String name) { // We automatically get the correct adapter for whatever type 'field' happens to be final ProtoAdapter adapter = field.getProtoAdapter(); // The adapter handles all the actual serialization using the protobuf classes. Easy! final byte[] byteContents = adapter.serialize(field); final ByteArrayResource resource = new ByteArrayResource(byteContents.length) .withName(name); try (BufferedOutputStream out = new BufferedOutputStream(resource.write())) { out.write(byteContents); } catch (final Exception e) { throw new CoreException("Could not convert {} to a readable resource.", field, e); } return resource; }
final ByteArrayResource resource = new ByteArrayResource(count).withName(name); logger.trace("Saving field {}", resource.getName()); if (field == null)
@Test public void testSize() { final PackedAtlas atlas = new PackedAtlasTest().getAtlas(); final ByteArrayResource zipped = new ByteArrayResource(8192).withName("zippedByteArray"); zipped.setCompressor(Compressor.GZIP); atlas.save(zipped); logger.info("Zipped Size: {}", zipped.length()); }
private Atlas deserialized() { final Atlas atlas = new PackedAtlasTest().getAtlas(); final ByteArrayResource resource = new ByteArrayResource(524288) .withName("testSerializationByteArray"); atlas.save(resource); return PackedAtlas.load(resource); }
public void testSizes() throws Exception { final long size = 100000; final ByteArrayResource javaOutput = new ByteArrayResource().withName("Java"); final ByteArrayResource zippedOutput = new ByteArrayResource().withName("Zipped"); javaOutput.setCompressor(Compressor.GZIP); zippedOutput.setCompressor(Compressor.GZIP); final TwoStringObject object = new TwoStringObject(size); final Resource oneResource = new StringResource(object.getOne()).withName("one"); final Resource twoResource = new StringResource(object.getTwo()).withName("two"); final ObjectOutputStream out = new ObjectOutputStream(javaOutput.write()); out.writeObject(object); Streams.close(out); new ZipWritableResource(zippedOutput).writeAndClose(oneResource, twoResource); System.out.println(javaOutput.getName() + " " + javaOutput.length()); System.out.println(zippedOutput.getName() + " " + zippedOutput.length()); }
@Test public void testAtlasFileExtensionFilter() { final PackedAtlasBuilder builder = new PackedAtlasBuilder(); builder.addPoint(1, new Location(Latitude.degrees(0), Longitude.degrees(0)), Maps.hashMap()); final Atlas atlas = builder.get(); final ByteArrayResource atlasResource = new ByteArrayResource() .withName("iDoNotHaveAnAtlasExt.txt"); atlas.save(atlasResource); Assert.assertNull(new AtlasResourceLoader().load(atlasResource)); Assert.assertNotNull(new AtlasResourceLoader().withAtlasFileExtensionFilterSetTo(false) .load(atlasResource)); }