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 BufRange(p, len)); eq(sub, expected.substring(p, p + len)); } } }
@Override public synchronized byte get(long position) { return buf.get(position); }
@Override public synchronized void get(Range range, byte[] dest, int offset) { buf.get(range, dest, offset); }
@Override public synchronized String get(Range range) { return buf.get(range); }