Package com.esotericsoftware.kryo.io

Examples of com.esotericsoftware.kryo.io.Input


    public Object deserialize(Object o) throws IOException {
        byte[] bytes = new byte[inputStream.readInt()];
        inputStream.readFully( bytes );

        return kryo.readObject(new Input(bytes), klass);
    }
View Full Code Here


    private Object decode(ByteBuffer bytes) {
        Kryo kryo = null;
        try {
            kryo = kryoPool.get();
            return kryo.readClassAndObject(new Input(new ByteArrayInputStream(bytes.array(), bytes
                    .arrayOffset() + bytes.position(), bytes.limit())));
        } catch (Exception e) {
            if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            }
View Full Code Here

    for (int i = 0; i < 100; i++) {
      write.writeBoolean(true);
      write.writeBoolean(false);
    }

    Input read = new Input(write.toBytes());
    for (int i = 0; i < 100; i++) {
      assertEquals(true, read.readBoolean());
      assertEquals(false, read.readBoolean());
    }
  }
View Full Code Here

    write.writeChar((char)8192);
    write.writeChar((char)16384);
    write.writeChar((char)32767);
    write.writeChar((char)65535);

    Input read = new Input(write.toBytes());
    assertEquals(0, read.readChar());
    assertEquals(63, read.readChar());
    assertEquals(64, read.readChar());
    assertEquals(127, read.readChar());
    assertEquals(128, read.readChar());
    assertEquals(8192, read.readChar());
    assertEquals(16384, read.readChar());
    assertEquals(32767, read.readChar());
    assertEquals(65535, read.readChar());
  }
View Full Code Here

    assertEquals(65535, read.readChar());
  }

  public void testInputWithOffset () throws Exception {
    final byte[] buf = new byte[30];
    final Input in = new Input(buf, 10, 10);
    assertEquals(10, in.available());
  }
View Full Code Here

    testOutput.flush();

    ByteBufferInputStream testInputs = new ByteBufferInputStream();
    buf.flip();
    testInputs.setByteBuffer(buf);
    Input input = new Input(testInputs, 512);
    byte[] toRead = new byte[512];
    input.readBytes(toRead);

    input.readBytes(toRead);
  }
View Full Code Here

    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);
      fail("Should have failed because F is not registered.");
    } catch (KryoException ignored) {
    }
  }
View Full Code Here

      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());
      assertEquals(test.value, result);
   }
View Full Code Here

      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);
      assertEquals(result.get(1), test2);
   }
View Full Code Here

    assertEquals(4, write.writeLong(-134217728, false));
    assertEquals(9, write.writeLong(-134217728, true));
    assertEquals(5, write.writeLong(-134217729, false));
    assertEquals(9, write.writeLong(-134217729, true));

    Input read = new Input(write.toBytes());
    assertEquals(0, read.readLong());
    assertEquals(63, read.readLong());
    assertEquals(64, read.readLong());
    assertEquals(127, read.readLong());
    assertEquals(128, read.readLong());
    assertEquals(8192, read.readLong());
    assertEquals(16384, read.readLong());
    assertEquals(2097151, read.readLong());
    assertEquals(1048575, read.readLong());
    assertEquals(134217727, read.readLong());
    assertEquals(268435455, read.readLong());
    assertEquals(134217728, read.readLong());
    assertEquals(268435456, read.readLong());
    assertEquals(-2097151, read.readLong());
    assertEquals(-1048575, read.readLong());
    assertEquals(-134217727, read.readLong());
    assertEquals(-268435455, read.readLong());
    assertEquals(-134217728, read.readLong());
    assertEquals(-268435456, read.readLong());
    assertEquals(0, read.readLong(true));
    assertEquals(0, read.readLong(false));
    assertEquals(63, read.readLong(true));
    assertEquals(63, read.readLong(false));
    assertEquals(64, read.readLong(true));
    assertEquals(64, read.readLong(false));
    assertEquals(127, read.readLong(true));
    assertEquals(127, read.readLong(false));
    assertEquals(128, read.readLong(true));
    assertEquals(128, read.readLong(false));
    assertEquals(8191, read.readLong(true));
    assertEquals(8191, read.readLong(false));
    assertEquals(8192, read.readLong(true));
    assertEquals(8192, read.readLong(false));
    assertEquals(16383, read.readLong(true));
    assertEquals(16383, read.readLong(false));
    assertEquals(16384, read.readLong(true));
    assertEquals(16384, read.readLong(false));
    assertEquals(2097151, read.readLong(true));
    assertEquals(2097151, read.readLong(false));
    assertEquals(1048575, read.readLong(true));
    assertEquals(1048575, read.readLong(false));
    assertEquals(134217727, read.readLong(true));
    assertEquals(134217727, read.readLong(false));
    assertEquals(268435455, read.readLong(true));
    assertEquals(268435455, read.readLong(false));
    assertEquals(134217728, read.readLong(true));
    assertEquals(134217728, read.readLong(false));
    assertEquals(268435456, read.readLong(true));
    assertEquals(268435456, read.readLong(false));
    assertEquals(-64, read.readLong(false));
    assertEquals(-64, read.readLong(true));
    assertEquals(-65, read.readLong(false));
    assertEquals(-65, read.readLong(true));
    assertEquals(-8192, read.readLong(false));
    assertEquals(-8192, read.readLong(true));
    assertEquals(-1048576, read.readLong(false));
    assertEquals(-1048576, read.readLong(true));
    assertEquals(-134217728, read.readLong(false));
    assertEquals(-134217728, read.readLong(true));
    assertEquals(-134217729, read.readLong(false));
    assertEquals(-134217729, read.readLong(true));

    Random random = new Random();
    for (int i = 0; i < 10000; i++) {
      long value = random.nextLong();
      write.clear();
      write.writeLong(value);
      write.writeLong(value, true);
      write.writeLong(value, false);
      read.setBuffer(write.toBytes());
      assertEquals(value, read.readLong());
      assertEquals(value, read.readLong(true));
      assertEquals(value, read.readLong(false));
    }
  }
View Full Code Here

TOP

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

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.