Package com.esotericsoftware.kryo.io

Examples of com.esotericsoftware.kryo.io.Output


  }

  public void testSmallBuffers () throws Exception {
    ByteBuffer buf = ByteBuffer.allocate(1024);
    ByteBufferOutputStream byteBufferOutputStream = new ByteBufferOutputStream(buf);
    Output testOutput = new Output(byteBufferOutputStream);
    testOutput.writeBytes(new byte[512]);
    testOutput.writeBytes(new byte[512]);
    testOutput.flush();

    ByteBufferInputStream testInputs = new ByteBufferInputStream();
    buf.flip();
    testInputs.setByteBuffer(buf);
    Input input = new Input(testInputs, 512);
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

         
          assertEquals(out1.toBytes(), out2.toBytes());
  }
 
  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

   public void testReadResolve () {
      kryo.setRegistrationRequired(false);
      kryo.addDefaultSerializer(Externalizable.class, ExternalizableSerializer.class);

      ReadResolvable test = new ReadResolvable("foobar");
      Output output = new Output(1024);
      kryo.writeClassAndObject(output, test);
      output.flush();

      Input input = new Input(output.getBuffer());
      Object result = kryo.readClassAndObject(input);
      input.close();

      // ensure read resolve happened!
      assertEquals(String.class, result.getClass());
View Full Code Here

      test2.intField = 54321;

      List list = new ArrayList();
      list.add(test1);
      list.add(test2);
      Output output = new Output(1024);
      kryo.writeClassAndObject(output, list);
      output.flush();

      Input input = new Input(output.getBuffer());
      List result = (List)kryo.readClassAndObject(input);
      input.close();

      // ensure read resolve happened!
      assertEquals(result.get(0), test1.value);
View Full Code Here

    kryoWithoutF.register(B.class);
    kryoWithoutF.register(C.class);
    kryoWithoutF.register(D.class);
    kryoWithoutF.register(E.class);

    Output output = new Output(512);
    try {
      kryoWithoutF.writeClassAndObject(output, c);
      fail("Should have failed because F is not registered.");
    } catch (KryoException ignored) {
    }

    kryo.register(A.class);
    kryo.register(B.class);
    kryo.register(C.class);
    kryo.register(D.class);
    kryo.register(E.class);
    kryo.register(F.class);
    kryo.setRegistrationRequired(true);

    output.clear();
    kryo.writeClassAndObject(output, c);
    output.flush();
    assertEquals(14, output.total());

    Input input = new Input(output.getBuffer());
    kryo.readClassAndObject(input);

    try {
      input.setPosition(0);
      kryoWithoutF.readClassAndObject(input);
View Full Code Here

 
  public void testClassSerializer() {
    kryo.register(Class.class);
    kryo.register(ArrayList.class);
    kryo.setRegistrationRequired(false);
    final Output out = new Output(1024);

    kryo.writeObject(out, String.class);
    kryo.writeObject(out, Integer.class);
    kryo.writeObject(out, Short.class);
    kryo.writeObject(out, Long.class);
    kryo.writeObject(out, Double.class);
    kryo.writeObject(out, Float.class);
    kryo.writeObject(out, Boolean.class);
    kryo.writeObject(out, Character.class);
    kryo.writeObject(out, Void.class);

    kryo.writeObject(out, int.class);
    kryo.writeObject(out, short.class);
    kryo.writeObject(out, long.class);
    kryo.writeObject(out, double.class);
    kryo.writeObject(out, float.class);
    kryo.writeObject(out, boolean.class);
    kryo.writeObject(out, char.class);
    kryo.writeObject(out, void.class);
    kryo.writeObject(out, ArrayList.class);
    kryo.writeObject(out, TestEnum.class);

    final Input in = new Input(out.getBuffer());

    assertEquals(String.class, kryo.readObject(in, Class.class));
    assertEquals(Integer.class, kryo.readObject(in, Class.class));
    assertEquals(Short.class, kryo.readObject(in, Class.class));
    assertEquals(Long.class, kryo.readObject(in, Class.class));
View Full Code Here

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

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

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

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

    kryo.register(HashMap.class);

    HasGenerics test = new HasGenerics();
    test.map.put("moo", new Integer[] {1, 2});

    output = new Output(4096);
    kryo.writeClassAndObject(output, test);
    output.flush();

    input = new Input(output.toBytes());
    HasGenerics test2 = (HasGenerics)kryo.readClassAndObject(input);
View Full Code Here

    Kryo kryo = new Kryo();
    kryo.register(HashMap.class, new MapSerializer());
    kryo.register(ConcurrentHashMap.class, new MapSerializer());

    Output output = new Output(2048, -1);
    kryo.writeClassAndObject(output, map);
    output.close();

    Input input = new Input(output.toBytes());
    Object deserialized = kryo.readClassAndObject(input);
    input.close();

    Assert.assertEquals(map, deserialized);
  }
View Full Code Here

TOP

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

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.