This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes zip / pipedinputstream / pipedoutputstream problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "zip / pipedinputstream / pipedoutputstream problem" Watch "zip / pipedinputstream / pipedoutputstream problem" New topic

zip / pipedinputstream / pipedoutputstream problem

Gary Altura

Joined: Jun 08, 2003
Posts: 3
Good Day people,

I am having problems with the following method
when processing multiple files.
Situation is this...
when the 3rd zip entry (3rd file of files param) is about to closed (targetStream.closeEntry() pls. see below), program hangs.

Would this be a due to a prob with my use of the Piped classes? Would this be a thread issue? A nasty overlooked bug on my code?

Many Thanks in Advance!

public static void zipArchive(String zipFilename, File[] files){">> start zipArchive");
// return if there are no file(s).
if (files.length<=0){

//FileOutputStream pos = null;
//OutputStream pos;
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream();
//ZipInputStream zis = new ZipInputStream(pis);
try {
} catch (IOException e1) {
// TODO Auto-generated catch block
ZipOutputStream targetStream = new ZipOutputStream(pos);

//BufferedInputStream sourceStream = null;">> start adding files.");
for (int index=0; index<files.length; index++){
//">> start zipArchive - start - " + files[index].getName());
//FileInputStream fis = null;
FileInputStream sourceStream = null;

try {
//fis = new FileInputStream( files[index].getAbsolutePath() );
sourceStream = new FileInputStream( files[index].getAbsolutePath() );
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
//sourceStream = new BufferedInputStream(fis);

// create zip entry
ZipEntry theEntry = null;
theEntry = new ZipEntry( files[index].getName() );

try {
} catch (IOException e2) {
// TODO Auto-generated catch block

byte[] data = new byte[Constants.DATA_BLOCK_SIZE];
int bCnt = 0;
try {">> " + index + ". start writing data to targetStream file=" + files[index].getName());
while ((bCnt =, 0, Constants.DATA_BLOCK_SIZE)) != -1)
targetStream.write(data, 0, bCnt);
}">> end writing data to targetStream");">> closing entry targetStream");
// ****************************
// *******problem is in here
// ****************************
targetStream.closeEntry();">> closing sourceStream");
sourceStream.close();">> deleting start the file");
// delete the file.
files[index].delete();">> deleting done the file");
} catch (IOException e3) {
// TODO Auto-generated catch block
//">> start zipArchive - end - " + files[index].getName());
}">> done adding files.");

try {
//targetStream.flush();">> start test 1");

} catch (IOException e4) {
// TODO Auto-generated catch block
I agree. Here's the link:
subject: zip / pipedinputstream / pipedoutputstream problem
Similar Threads
Waiting for input from PipedInputStream....thread yield?
Check out this I/O Ques
problem reading output of a subprocess
using javax API to send file contents to COM1
Ping a IP address in Java