private void checkStream(int size, int buffer) throws IOException {
Random rand = new Random();
byte[] data = new byte[size];
rand.nextBytes(data);
Directory dir = new RAMDirectory();
OutputStream out = new IndexOutputStream(dir.createOutput("test"));
if (buffer != 0) {
out = new BufferedOutputStream(out, buffer);
}
out.write(data);
out.close();
byte[] buf = new byte[3];
int pos = 0;
IndexInput in = dir.openInput("test");
for (;;) {