for (int i = 0; i < 10; i++) {
s = s + s; // repeated 16 times
}
byte[] bytes = s.getBytes();
FastBufferOutputStream output = new FastBufferOutputStream(16);
// write it several times.
for (int i = 0; i < 4; i++) {
output.write(bytes);
}
// write it one more time by one byte
for (int i = 0; i < bytes.length; i++) {
output.write(bytes[i]);
}
FastBufferInputStream input = new FastBufferInputStream(output);
StringBuffer sb = new StringBuffer();
// use for reading unconvenient array length.
byte[] bs = new byte[ARRAY_LENGTH];
int l = 0;
while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
if (BUILD_STRING) {
sb.append(new String(bs, READ_OFF, l));
}
}
if (BUILD_STRING && OUT_STRING) {
System.out.println(sb);
System.out.println("Length=" + output.getLength());
}
}