Package com.esotericsoftware.kryo.io

Examples of com.esotericsoftware.kryo.io.ByteBufferOutput


public class UnsafeMemoryInputOutputTest extends KryoTestCase {

  public void testByteBufferOutputWithPreallocatedMemory () {
    long bufAddress = UnsafeUtil.unsafe().allocateMemory(4096);
    try {
      ByteBufferOutput outputBuffer = new ByteBufferOutput(bufAddress, 4096);
      outputBuffer.writeInt(10);

      ByteBufferInput inputBuffer = new ByteBufferInput(outputBuffer.getByteBuffer());
      inputBuffer.readInt();
      inputBuffer.release();

      outputBuffer.release();
      outputBuffer = new UnsafeMemoryOutput(bufAddress, 4096);
      outputBuffer.writeInt(10);

      inputBuffer = new UnsafeMemoryInput(outputBuffer.getByteBuffer());
      inputBuffer.readInt();
      inputBuffer.release();
      outputBuffer.release();
    } catch (Throwable t) {
      System.err.println("Streams with preallocated direct memory are not supported on this JVM");
      t.printStackTrace();
    } finally {
      UnsafeUtil.unsafe().freeMemory(bufAddress);
View Full Code Here


      }
    });
   
    roundTripWithStreamFactory(length, object1, new StreamFactory() {
      public Output createOutput(OutputStream os) {
        return new ByteBufferOutput(os);
      }

      public Output createOutput(OutputStream os, int size) {
        return new ByteBufferOutput(os, size);
      }

      public Output createOutput(int size, int limit) {
        return new ByteBufferOutput(size, limit);
      }

      public Input createInput(InputStream os, int size) {
        return new ByteBufferInput(os, size);
      }
View Full Code Here

      }
    });
   
    roundTripWithStreamFactory(length, object1, new StreamFactory() {
      public Output createOutput(OutputStream os) {
        return new ByteBufferOutput(os);
      }

      public Output createOutput(OutputStream os, int size) {
        return new ByteBufferOutput(os, size);
      }

      public Output createOutput(int size, int limit) {
        return new ByteBufferOutput(size, limit);
      }

      public Input createInput(InputStream os, int size) {
        return new ByteBufferInput(os, size);
      }
View Full Code Here

    input.readBytes(toRead);
  }

  public void testVerySmallBuffers() throws Exception {
          Output out1 = new Output(4, -1);
          Output out2 = new ByteBufferOutput(4, -1);

          for (int i = 0; i < 16; i++) {
                out1.writeVarInt(92, false);
          }

          for (int i = 0; i < 16; i++) {
                out2.writeVarInt(92, false);
          }
         
          assertEquals(out1.toBytes(), out2.toBytes());
  }
View Full Code Here

 
  public void testZeroLengthOutputs() throws Exception {
    Output output = new Output(0, 10000);
    kryo.writeClassAndObject(output, "Test string");

    Output byteBufferOutput = new ByteBufferOutput(0, 10000);
    kryo.writeClassAndObject(byteBufferOutput, "Test string");
  }
View Full Code Here

  @SuppressWarnings({"rawtypes"})
  public <T extends Entry> void testSerializeAndDeserializeEntry(Class<T> entryType, T entry)
    throws Exception {
    Kryo kryo = new Kryo();
    ByteBuffer buffer = ByteBuffer.allocate(4096);
    Output output = new ByteBufferOutput(buffer);
    Input input = new ByteBufferInput(buffer);
    Class<? extends Serializer> serializer = entryType.getAnnotation(EntryType.class).serializer();
    kryo.register(entryType, serializer.newInstance(), entryType.getAnnotation(EntryType.class) .id());
    kryo.writeClassAndObject(output, entry);
    T result = (T) kryo.readClassAndObject(input);
View Full Code Here

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

    input = new ByteBufferInput();
    output = new ByteBufferOutput();
  }
View Full Code Here

TOP

Related Classes of com.esotericsoftware.kryo.io.ByteBufferOutput

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.