Exemplo n.º 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);
   }
 }
Exemplo n.º 2
0
 @Test(expected = EOFException.class)
 public void testUnpackLong_withInputStream_throws_exception_when_stream_is_empty()
     throws IOException {
   DataIO.unpackLong(new ByteArrayInputStream(new byte[0]));
   fail(
       "An EOFException should have occurred by now since there are no bytes to read from the InputStream");
 }
Exemplo n.º 3
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);
    }
  }