package com.Ostermiller.util;
import java.io.*;
class StraightStreamReaderTests {
public static void main(String args[]){
try {
StraightStreamReader in;
char[] cbuf = new char[0x1000];
int read;
int totRead;
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
for (int i=0x00; i<0x100; i++){
buffer.write(i);
}
buffer.close();
in = new StraightStreamReader(new ByteArrayInputStream(buffer.toByteArray()));
for (int i=0x00; i<0x100; i++){
read = in.read();
if (read != i){
throw new Exception("Error: " + i + " read as " + read);
}
}
in.close();
in = new StraightStreamReader(new ByteArrayInputStream(buffer.toByteArray()));
totRead = in.read(cbuf);
if (totRead != 0x100){
throw new Exception("Simple buffered read did not read the full amount: 0x" + Integer.toHexString(totRead));
}
for (int i=0x00; i<totRead; i++){
if (cbuf[i] != i){
throw new Exception("Error: 0x" + i + " read as 0x" + cbuf[i]);
}
}
in.close();
in = new StraightStreamReader(new ByteArrayInputStream(buffer.toByteArray()));
totRead = 0;
while (totRead <= 0x100 && (read = in.read(cbuf, totRead, 0x100 - totRead)) > 0){
totRead += read;
}
if (totRead != 0x100){
throw new Exception("Not enough read. Bytes read: " + Integer.toHexString(totRead));
}
for (int i=0x00; i<totRead; i++){
if (cbuf[i] != i){
throw new Exception("Error: 0x" + i + " read as 0x" + cbuf[i]);
}
}
in.close();
in = new StraightStreamReader(new ByteArrayInputStream(buffer.toByteArray()));
totRead = 0;
while (totRead <= 0x100 && (read = in.read(cbuf, totRead+0x123, 0x100 - totRead)) > 0){
totRead += read;
}
if (totRead != 0x100){
throw new Exception("Not enough read. Bytes read: " + Integer.toHexString(totRead));
}
for (int i=0x00; i<totRead; i++){
if (cbuf[i+0x123] != i){
throw new Exception("Error: 0x" + i + " read as 0x" + cbuf[i+0x123]);
}
}
in.close();
in = new StraightStreamReader(new ByteArrayInputStream(buffer.toByteArray()));
totRead = 0;
while (totRead <= 0x100 && (read = in.read(cbuf, totRead+0x123, 7)) > 0){
totRead += read;
}
if (totRead != 0x100){
throw new Exception("Not enough read. Bytes read: " + Integer.toHexString(totRead));
}
for (int i=0x00; i<totRead; i++){
if (cbuf[i+0x123] != i){
throw new Exception("Error: 0x" + i + " read as 0x" + cbuf[i+0x123]);
}
}
in.close();
} catch (Exception x){
System.err.println(x.getMessage());
System.exit(1);
}
System.exit(0);
}
}