com.esotericsoftware.kryo.io.OutputChunked Java Examples

The following examples show how to use com.esotericsoftware.kryo.io.OutputChunked. 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 vote down vote up
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: KryoStrategy.java    From subzero with Apache License 2.0 5 votes vote down vote up
public void write(OutputStream out, T object) {
    KryoContext kryoContext = KRYOS.get();
    OutputChunked output = kryoContext.getOutputChunked();
    output.setOutputStream(out);
    writeObject(kryoContext.getKryo(), output, object);
    output.endChunks();
    output.flush();
}
 
Example #3
Source File: KryoState.java    From beam with Apache License 2.0 5 votes vote down vote up
private KryoState(
    Kryo kryo, int firstRegistrationId, InputChunked inputChunked, OutputChunked outputChunked) {
  this.kryo = kryo;
  this.firstRegistrationId = firstRegistrationId;
  this.inputChunked = inputChunked;
  this.outputChunked = outputChunked;
}
 
Example #4
Source File: FeatureSerializationTest.java    From geowave with Apache License 2.0 5 votes vote down vote up
@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 vote down vote up
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: KryoContext.java    From subzero with Apache License 2.0 4 votes vote down vote up
KryoContext(Kryo kryo, InputChunked inputChunked, OutputChunked outputChunked) {
    this.kryo = kryo;
    this.inputChunked = inputChunked;
    this.outputChunked = outputChunked;
}
 
Example #7
Source File: KryoContext.java    From subzero with Apache License 2.0 4 votes vote down vote up
public OutputChunked getOutputChunked() {
    return outputChunked;
}
 
Example #8
Source File: KryoState.java    From beam with Apache License 2.0 2 votes vote down vote up
/**
 * {@link KryoState#outputChunked}.
 *
 * @return output buffer
 */
OutputChunked getOutputChunked() {
  return outputChunked;
}