public void write (Kryo kryo, Output output, Object object) { OutputChunked outputChunked = new OutputChunked(output, 256); Deflater deflater = new Deflater(compressionLevel, noHeaders); try { DeflaterOutputStream deflaterStream = new DeflaterOutputStream(outputChunked, deflater); Output deflaterOutput = new Output(deflaterStream, 256); serializer.write(kryo, deflaterOutput, object); deflaterOutput.flush(); deflaterStream.finish(); } catch (IOException ex) { throw new KryoException(ex); } finally { deflater.end(); } outputChunked.endChunks(); }
public void write (Kryo kryo, Output output, T object) { CachedField[] fields = getFields(); ObjectMap context = kryo.getGraphContext(); if (!context.containsKey(this)) { context.put(this, null); if (TRACE) trace("kryo", "Write " + fields.length + " field names."); output.writeVarInt(fields.length, true); for (int i = 0, n = fields.length; i < n; i++) output.writeString(fields[i].field.getName()); } OutputChunked outputChunked = new OutputChunked(output, 1024); for (int i = 0, n = fields.length; i < n; i++) { fields[i].write(outputChunked, object); outputChunked.endChunks(); } }
public void write(OutputStream out, T object) throws IOException { KryoContext kryoContext = KRYOS.get(); OutputChunked output = kryoContext.getOutputChunked(); output.setOutputStream(out); writeObject(kryoContext.getKryo(), output, object); output.endChunks(); output.flush(); }
public void write (Kryo kryo, Output output, Object object) { Deflater deflater = new Deflater(compressionLevel, noHeaders); OutputChunked outputChunked = new OutputChunked(output, 256); DeflaterOutputStream deflaterStream = new DeflaterOutputStream(outputChunked, deflater); Output deflaterOutput = new Output(deflaterStream, 256); kryo.writeObject(deflaterOutput, object, serializer); deflaterOutput.flush(); try { deflaterStream.finish(); } catch (IOException ex) { throw new KryoException(ex); } outputChunked.endChunks(); }
public void testChunks () { Output output = new Output(512); output.writeInt(1234); OutputChunked outputChunked = new OutputChunked(output); outputChunked.writeInt(1); outputChunked.endChunks(); outputChunked.writeInt(2); outputChunked.endChunks(); outputChunked.writeInt(3); outputChunked.endChunks(); outputChunked.writeInt(4); outputChunked.endChunks(); outputChunked.writeInt(5); outputChunked.endChunks(); output.writeInt(5678); output.close(); Input input = new Input(output.getBuffer()); assertEquals(1234, input.readInt()); InputChunked inputChunked = new InputChunked(input); assertEquals(1, inputChunked.readInt()); inputChunked.nextChunks(); inputChunked.nextChunks(); // skip 3 assertEquals(3, inputChunked.readInt()); inputChunked.nextChunks(); inputChunked.nextChunks(); // skip 4 assertEquals(5, inputChunked.readInt()); assertEquals(5678, input.readInt()); input.close(); }
protected KryoContext initialValue() { Kryo kryo = newKryoInstance(); OutputChunked output = new OutputChunked(BUFFER_SIZE); InputChunked input = new InputChunked(BUFFER_SIZE); return new KryoContext(kryo, input, output); }
KryoContext(Kryo kryo, InputChunked inputChunked, OutputChunked outputChunked) { this.kryo = kryo; this.inputChunked = inputChunked; this.outputChunked = outputChunked; }
public OutputChunked getOutputChunked() { return outputChunked; }
@Test public void test() throws SchemaException { final Kryo kryo = new Kryo(); kryo.register( SimpleFeatureImpl.class, new FeatureSerializer()); final SimpleFeatureType schema = DataUtilities.createType( "testGeo", "location:Point:srid=4326,name:String"); final List<AttributeDescriptor> descriptors = schema.getAttributeDescriptors(); final Object[] defaults = new Object[descriptors.size()]; int p = 0; for (final AttributeDescriptor descriptor : descriptors) { defaults[p++] = descriptor.getDefaultValue(); } final SimpleFeature feature = SimpleFeatureBuilder.build( schema, defaults, UUID.randomUUID().toString()); final GeometryFactory geoFactory = new GeometryFactory(); feature.setAttribute( "location", geoFactory.createPoint(new Coordinate( -45, 45))); final Output output = new OutputChunked(); kryo.getSerializer( SimpleFeatureImpl.class).write( kryo, output, feature); final Input input = new InputChunked(); input.setBuffer(output.getBuffer()); final SimpleFeature f2 = (SimpleFeature) kryo.getSerializer( SimpleFeatureImpl.class).read( kryo, input, SimpleFeatureImpl.class); assertEquals( feature, f2); }