예제 #1
0
  @Test
  public void packInt() throws IOException {
    DataInputByteArray in = new DataInputByteArray(new byte[20]);
    DataOutputByteArray out = new DataOutputByteArray();
    out.buf = in.buf;
    for (int i = 0; i > 0; i = i + 1 + i / 10000) {
      in.pos = 10;
      out.pos = 10;

      DataIO.packInt((DataOutput) out, i);
      long i2 = DataIO.unpackInt(in);

      assertEquals(i, i2);
      assertEquals(in.pos, out.pos);
    }
  }
예제 #2
0
  @Test
  public void packIntCompat() throws IOException {
    DataOutputByteArray b = new DataOutputByteArray();
    b.packInt(2111);
    b.packInt(100);
    b.packInt(1111);

    DataInputByteArray b2 = new DataInputByteArray(b.buf);
    assertEquals(2111, b2.unpackInt());
    assertEquals(100, b2.unpackInt());
    assertEquals(1111, b2.unpackInt());

    DataInputByteBuffer b3 = new DataInputByteBuffer(ByteBuffer.wrap(b.buf), 0);
    assertEquals(2111, b3.unpackInt());
    assertEquals(100, b3.unpackInt());
    assertEquals(1111, b3.unpackInt());
  }