@Test
  public void testBinary() throws IOException {
    Binary bytes =
        Binary.wrap(new byte[] {0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1});
    // test writing and reading bytes.
    writer.writeBinary(bytes);

    BinaryReader reader = getReader();

    Binary read = reader.expectBinary(bytes.length());

    assertEquals(bytes, read);
  }
  @Test
  public void testBadBinary() throws IOException {
    Binary bytes =
        Binary.wrap(new byte[] {0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1});
    // test writing and reading bytes.
    writer.writeBinary(bytes);

    BinaryReader reader = getReader();

    try {
      reader.expectBinary(bytes.length() + 1);
      fail("No exception on bad binary data");
    } catch (IOException e) {
      assertEquals("Not enough data available on stream: 20 < 21", e.getMessage());
    }
  }