コード例 #1
0
  protected void eq(Buf buf, String expected) {
    eq(buf.size(), expected.getBytes().length);
    eq(buf.data(), expected);

    byte[] bbytes = new byte[buf.size()];
    ByteBuffer bufy = ByteBuffer.wrap(bbytes);
    buf.writeTo(bufy);
    eq(new String(bbytes), expected);

    int size = (int) Math.ceil(expected.length() * 1.0 / buf.unitSize());
    isTrue(buf.unitCount() == size || buf.unitCount() == size + 1);

    byte[] bytes = expected.getBytes();
    synchronized (buf) {
      for (int i = 0; i < bytes.length; i++) {
        eq((char) buf.get(i), (char) bytes[i]);
      }
    }

    for (int len = 2; len < 10; len++) {
      for (int p = 0; p <= buf.size() - len; p++) {
        String sub = buf.get(new Range(p, len));
        eq(sub, expected.substring(p, p + len));
      }
    }
  }