com.esotericsoftware.kryo.io.InputChunked Java Examples
The following examples show how to use
com.esotericsoftware.kryo.io.InputChunked.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KryoState.java From beam with Apache License 2.0 | 6 votes |
KryoState getOrCreate(KryoCoder<?> coder) { return kryoStateMap .get() .computeIfAbsent( coder.getInstanceId(), k -> { final Kryo kryo = new Kryo(); // fallback in case serialized class does not have default constructor kryo.setInstantiatorStrategy( new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy())); kryo.setReferences(coder.getOptions().getReferences()); kryo.setRegistrationRequired(coder.getOptions().getRegistrationRequired()); kryo.setClassLoader(Thread.currentThread().getContextClassLoader()); // first id of user provided class registration final int firstRegistrationId = kryo.getNextRegistrationId(); // register user provided classes for (KryoRegistrar registrar : coder.getRegistrars()) { registrar.registerClasses(kryo); } return new KryoState( kryo, firstRegistrationId, new InputChunked(coder.getOptions().getBufferSize()), new OutputChunked(coder.getOptions().getBufferSize())); }); }
Example #2
Source File: KryoState.java From beam with Apache License 2.0 | 5 votes |
private KryoState( Kryo kryo, int firstRegistrationId, InputChunked inputChunked, OutputChunked outputChunked) { this.kryo = kryo; this.firstRegistrationId = firstRegistrationId; this.inputChunked = inputChunked; this.outputChunked = outputChunked; }
Example #3
Source File: KryoCoder.java From beam with Apache License 2.0 | 5 votes |
@Override public T decode(InputStream inStream) throws IOException { final KryoState kryoState = KryoState.get(this); final InputChunked inputChunked = kryoState.getInputChunked(); inputChunked.setInputStream(inStream); try { @SuppressWarnings("unchecked") final T instance = (T) kryoState.getKryo().readClassAndObject(inputChunked); return instance; } catch (KryoException e) { throw new CoderException("Cannot decode object from input stream.", e); } }
Example #4
Source File: FeatureSerializationTest.java From geowave with Apache License 2.0 | 5 votes |
@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); }
Example #5
Source File: KryoStrategy.java From subzero with Apache License 2.0 | 4 votes |
protected KryoContext initialValue() { Kryo kryo = newKryoInstance(); OutputChunked output = new OutputChunked(BUFFER_SIZE); InputChunked input = new InputChunked(BUFFER_SIZE); return new KryoContext(kryo, input, output); }
Example #6
Source File: KryoStrategy.java From subzero with Apache License 2.0 | 4 votes |
public T read(InputStream in) { KryoContext kryoContext = KRYOS.get(); InputChunked input = kryoContext.getInputChunked(); input.setInputStream(in); return readObject(kryoContext.getKryo(), input); }
Example #7
Source File: KryoContext.java From subzero with Apache License 2.0 | 4 votes |
KryoContext(Kryo kryo, InputChunked inputChunked, OutputChunked outputChunked) { this.kryo = kryo; this.inputChunked = inputChunked; this.outputChunked = outputChunked; }
Example #8
Source File: KryoContext.java From subzero with Apache License 2.0 | 4 votes |
public InputChunked getInputChunked() { return inputChunked; }
Example #9
Source File: KryoState.java From beam with Apache License 2.0 | 2 votes |
/** * {@link KryoState#inputChunked}. * * @return input buffer */ InputChunked getInputChunked() { return inputChunked; }