• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

zip / pipedinputstream / pipedoutputstream problem

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}
}
 
reply
    Bookmark Topic Watch Topic
  • New Topic