com.esotericsoftware.kryo.io.ByteBufferOutput Java Examples

The following examples show how to use com.esotericsoftware.kryo.io.ByteBufferOutput. 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: TpchDataSource.java    From paraflow with Apache License 2.0 5 votes vote down vote up
public TpchDataSource(int sf, int part, int partCount, long minCustomerKey, long maxCustomerKey)
{
    super("tpch");
    Iterable<LineOrder> lineOrderIterable = TpchTable.LINEORDER.createGenerator(sf, part, partCount, minCustomerKey, maxCustomerKey);
    this.lineOrderIterator = lineOrderIterable.iterator();
    this.kryo = new Kryo();
    kryo.register(LineOrder.class, 10);
    kryo.register(byte[].class, 11);
    kryo.register(Object[].class, 12);
    this.output = new ByteBufferOutput(300, 2000);
}
 
Example #2
Source File: Namespace.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * Serializes given object to byte buffer using Kryo instance in pool.
 *
 * @param obj    Object to serialize
 * @param buffer to write to
 */
public void serialize(final Object obj, final ByteBuffer buffer) {
  ByteBufferOutput out = new ByteBufferOutput(buffer);
  Kryo kryo = borrow();
  try {
    kryo.writeClassAndObject(out, obj);
    out.flush();
  } finally {
    release(kryo);
  }
}
 
Example #3
Source File: Namespace.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * Serializes given object to OutputStream using Kryo instance in pool.
 *
 * @param obj        Object to serialize
 * @param stream     to write to
 * @param bufferSize size of the buffer in front of the stream
 */
public void serialize(final Object obj, final OutputStream stream, final int bufferSize) {
  ByteBufferOutput out = new ByteBufferOutput(stream, bufferSize);
  Kryo kryo = borrow();
  try {
    kryo.writeClassAndObject(out, obj);
    out.flush();
  } finally {
    release(kryo);
  }
}
 
Example #4
Source File: KryoNamespace.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Serializes given object to byte buffer using Kryo instance in pool.
 *
 * @param obj Object to serialize
 * @param buffer to write to
 */
public void serialize(final Object obj, final ByteBuffer buffer) {
    ByteBufferOutput out = new ByteBufferOutput(buffer);
    Kryo kryo = borrow();
    try {
        kryo.writeClassAndObject(out, obj);
        out.flush();
    } finally {
        release(kryo);
    }
}
 
Example #5
Source File: KryoNamespace.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Serializes given object to OutputStream using Kryo instance in pool.
 *
 * @param obj Object to serialize
 * @param stream to write to
 * @param bufferSize size of the buffer in front of the stream
 */
public void serialize(final Object obj, final OutputStream stream, final int bufferSize) {
    ByteBufferOutput out = new ByteBufferOutput(stream, bufferSize);
    Kryo kryo = borrow();
    try {
        kryo.writeClassAndObject(out, obj);
        out.flush();
    } finally {
        release(kryo);
    }
}
 
Example #6
Source File: KryoSerialization.java    From kryonet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public KryoSerialization (Kryo kryo) {
	this.kryo = kryo;

	kryo.register(RegisterTCP.class);
	kryo.register(RegisterUDP.class);
	kryo.register(KeepAlive.class);
	kryo.register(DiscoverHost.class);
	kryo.register(Ping.class);

	input = new ByteBufferInput();
	output = new ByteBufferOutput();
}
 
Example #7
Source File: TestParquetWriter.java    From paraflow with Apache License 2.0 4 votes vote down vote up
@Test
public void testParquetCompression()
{
    final Kryo kryo = new Kryo();
    kryo.register(LineOrder.class);
    kryo.register(byte[].class);
    kryo.register(Object[].class);

    final LoaderConfig config = LoaderConfig.INSTANCE();
    try {
        config.init();
    }
    catch (ConfigFileNotFoundException e) {
        e.printStackTrace();
    }
    final MetaClient metaClient = new MetaClient("127.0.0.1", 10012);
    final int capacity = 8;
    Iterable<LineOrder> lineOrderIterable = TpchTable.LINEORDER.createGenerator(1000, 1, 1500, 0, 10000000);
    Iterator<LineOrder> lineOrderIterator = lineOrderIterable.iterator();
    TpchDataTransformer transformer = new TpchDataTransformer();
    ParaflowRecord[][] content = new ParaflowRecord[1][];
    ParaflowRecord[] records = new ParaflowRecord[capacity];
    int counter = 0;
    long textSize = 0;
    Output output = new ByteBufferOutput(300, 2000);
    while (lineOrderIterator.hasNext() && counter < capacity) {
        LineOrder lineOrder = lineOrderIterator.next();
        kryo.writeObject(output, lineOrder);
        textSize += output.position();
        ParaflowRecord record = transformer.transform(output.toBytes(), 80);
        records[counter++] = record;
        output.reset();
    }
    content[0] = records;
    output.close();
    ParaflowSegment segment = new ParaflowSegment(content, new long[0], new long[0], 0.0d);
    segment.setPath("file:///Users/Jelly/Desktop/1");
    MetaProto.StringListType columnNames = metaClient.listColumns("test", "debug01");
    MetaProto.StringListType columnTypes = metaClient.listColumnsDataType("test", "debug01");
    final ParquetSegmentWriter segmentWriter = new ParquetSegmentWriter(segment, metaClient, null);
    long start = System.currentTimeMillis();
    if (segmentWriter.write(segment, columnNames, columnTypes)) {
        System.out.println("Binary size: " + (1.0 * textSize / 1024.0 / 1024.0) + " MB.");
    }
    long end = System.currentTimeMillis();
    System.out.println("Time cost: " + (end - start));
}
 
Example #8
Source File: KryoReadingSerializer.java    From kafka-serializer-example with MIT License 4 votes vote down vote up
@Override
public byte[] serialize(String s, SensorReading sensorReading) {
    ByteBufferOutput output = new ByteBufferOutput(100);
    kryos.get().writeObject(output, sensorReading);
    return output.toBytes();
}
 
Example #9
Source File: KeyValueEncoder.java    From Pistachio with Apache License 2.0 4 votes vote down vote up
@Override protected ByteBufferOutput initialValue() {
    return new ByteBufferOutput(10240);
}
 
Example #10
Source File: PistachiosTkIterator.java    From Pistachio with Apache License 2.0 4 votes vote down vote up
@Override protected ByteBufferOutput initialValue() {
    return new ByteBufferOutput(10240);
}