my dog learned polymorphism*
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
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "zip / pipedinputstream / pipedoutputstream problem" Watch "zip / pipedinputstream / pipedoutputstream problem" New topic
Author

zip / pipedinputstream / pipedoutputstream problem

Gary Altura
Greenhorn

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){
batchCompressLogger.info(">> start zipArchive");
// return if there are no file(s).
if (files.length<=0){
return;
}

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

//BufferedInputStream sourceStream = null;
batchCompressLogger.info(">> start adding files.");
for (int index=0; index<files.length; index++){
//batchCompressLogger.info(">> 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
e.printStackTrace();
}
//sourceStream = new BufferedInputStream(fis);

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

try {
targetStream.putNextEntry(theEntry);
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}

byte[] data = new byte[Constants.DATA_BLOCK_SIZE];
int bCnt = 0;
try {
batchCompressLogger.info(">> " + index + ". start writing data to targetStream file=" + files[index].getName());
while ((bCnt = sourceStream.read(data, 0, Constants.DATA_BLOCK_SIZE)) != -1)
{
targetStream.write(data, 0, bCnt);
}
batchCompressLogger.info(">> end writing data to targetStream");

batchCompressLogger.info(">> closing entry targetStream");
// ****************************
// *******problem is in here
// ****************************
targetStream.closeEntry();
batchCompressLogger.info(">> closing sourceStream");
sourceStream.close();

batchCompressLogger.info(">> deleting start the file");
// delete the file.
files[index].delete();
batchCompressLogger.info(">> deleting done the file");
} catch (IOException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
//batchCompressLogger.info(">> start zipArchive - end - " + files[index].getName());
}

batchCompressLogger.info(">> done adding files.");

try {
//targetStream.flush();

batchCompressLogger.info(">> start test 1");
//pos.flush();
targetStream.finish();
targetStream.close();
pos.close();



} catch (IOException e4) {
// TODO Auto-generated catch block
e4.printStackTrace();
}
}
 
wood burning stoves
 
subject: zip / pipedinputstream / pipedoutputstream problem