Exemple #1
0
 @Test
 public void testPackLong_WithStreams() throws IOException {
   for (long valueToPack = 0;
       valueToPack < Long.MAX_VALUE && valueToPack >= 0;
       valueToPack = random.nextInt(2) + valueToPack * 2) {
     ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
     DataIO.packLong(outputStream, valueToPack);
     DataIO.packLong(outputStream, -valueToPack);
     ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
     long unpackedLong = DataIO.unpackLong(inputStream);
     assertEquals("Packed and unpacked values do not match", valueToPack, unpackedLong);
     unpackedLong = DataIO.unpackLong(inputStream);
     assertEquals("Packed and unpacked values do not match", -valueToPack, unpackedLong);
   }
 }
Exemple #2
0
  @Test
  public void packLong() throws IOException {
    DataInputByteArray in = new DataInputByteArray(new byte[20]);
    DataOutputByteArray out = new DataOutputByteArray();
    out.buf = in.buf;
    for (long i = 0; i > 0; i = i + 1 + i / 10000) {
      in.pos = 10;
      out.pos = 10;

      DataIO.packLong((DataOutput) out, i);
      long i2 = DataIO.unpackLong(in);

      assertEquals(i, i2);
      assertEquals(in.pos, out.pos);
    }
  }