Package com.esotericsoftware.kryo.io

Examples of com.esotericsoftware.kryo.io.Input


  public void testSimpleVarInt() {
      final int value = 39117;
      final Output out = new UnsafeOutput(1024);
      out.writeVarInt(value, true);
      out.flush();
      final Input in = new UnsafeInput(out.toBytes());
      final int actualValue = in.readVarInt(true);
      assertEquals(value, actualValue);
  }
View Full Code Here


    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

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

      public Input createInput(InputStream os, int size) {
        return new Input(os, size);
      }

      public Input createInput(byte[] buffer) {
        return new Input(buffer);
      }
    });
  }
View Full Code Here

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

    input = new Input(output.toBytes());
    HasGenerics test2 = (HasGenerics)kryo.readClassAndObject(input);
    assertEquals(test.map.get("moo"), test2.map.get("moo"));
  }
View Full Code Here

    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

    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

    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

  }

  public void testCanReadInt () throws IOException {
    UnsafeOutput write = new UnsafeOutput(new ByteArrayOutputStream());

    Input read = new UnsafeInput(write.toBytes());
    assertEquals(false, read.canReadInt());

    write.writeVarInt(400, true);

    read = new UnsafeInput(write.toBytes());
    assertEquals(true, read.canReadInt());
    read.setLimit(read.limit() - 1);
    assertEquals(false, read.canReadInt());
  }
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.