System.out.println("read " + num + " bytes");
assert num == 5 * buffer.length;
}
public void testMultipleWriters() throws Exception {
final BlockingInputStream in=new BlockingInputStream(100);
final byte[] buffer=generateBuffer(500);
final Writer[] writers=new Writer[5];
for(int i=0; i < writers.length; i++) {
writers[i]=new Writer(in, buffer, 1, false);
writers[i].setName("writer-" + (i+1));
writers[i].start();
}
new Thread() {
public void run() {
while(true) {
boolean all_done=true;
for(Writer writer: writers) {
if(writer.isAlive()) {
all_done=false;
break;
}
}
if(all_done) {
Util.close(in);
return;
}
else
Util.sleep(100);
}
}
}.start();
byte[] tmp=new byte[400];
int num=0;
while(true) {
int read=in.read(tmp, 0, tmp.length);
if(read == -1)
break;
num+=read;
}
System.out.println("read " + num + " bytes");