I am writing a server in JAVA
, where client requests to download multiple files and server will create a ZipOutputStream
and serve immediately. On the other hand another thread will write to ZipOutputStream
. I used piped input/output stream
.
Code
PipedInputStream in = new PipedInputStream();
PipedOutputStream out = new PipedOutputStream();
in.connect(out);
ZipOutputStream zout = new ZipOutputStream(out);
new Thread{
public void run(){
while(condition){
more logic..
zout.write(data,0,length);
zout.flush()
}
zout.close();
out.close();
}
}.start();
return in;
But when I click download button it download(finish immediately) a small file(corrupted) while my zip creating job is still running. How can I synchronize these two job?