Da der ZipInputStream manchmal von der überliegende Klasse automatisch geschlossen wird, habe ich einen entsprechenden Wrapper drumrum geschrieben, der von ZipInputStream erbt. Leider wird nun gar nichts mehr geschrieben(Größe der Datei ist "0"). Ich verstehe nicht, warum es sich nicht identisch zu ZipInputStream verhält!? Das Problem habe ich bereits soweit eingeengt, dass klar ist, dass "in.getNextEntry()" nulll zurückgibt, also keine ZipEntrys gefunden werden...
Anbei die entsprechende Testklasse:
Anbei die entsprechende Testklasse:
Code:
public class Start {
public static void main(String[] args) {
Start start = new Start();
start.begin();
}
private void begin() {
InnerInputStream in = null;
ZipOutputStream out = null;
try {
in = new InnerInputStream(new ZipInputStream(new FileInputStream(new File("in.odt"))));
out = new ZipOutputStream(new FileOutputStream(new File("out.odt")));
ZipEntry zipEntry = null;
int counter = 0;
while((zipEntry = in.getNextEntry())!=null) {
counter++;
out.putNextEntry(zipEntry);
int i = 0;
while((i=in.read())!=-1) {
out.write(i);
}
in.closeEntry();
out.closeEntry();
}
System.out.println("done " + counter + " entries.");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if(in!=null) {
try {
in.forceClose();
} catch (IOException ignore) {System.err.println("warn: "+ignore.getMessage());}
}
if(out!=null) {
try {
out.close();
} catch (IOException ignore) {System.err.println("warn: "+ignore.getMessage());}
}
}
}
private class InnerInputStream extends ZipInputStream {
public InnerInputStream(ZipInputStream inputStream) {
super(inputStream);
}
public void close() throws IOException {
//forced: do nothing!
}
/**
* Really closes the underlying ZipInputStream
* @throws IOException
*/
protected void forceClose() throws IOException {
super.close();
}
}
}