I something similiar to the post(s) about ZIP compression and I would like to know how to convert the snippet to stream binary files to a zip file.
Dano
dan_kryzer@hotmail.com
What's your major malfunction
Code:
String file = "C:\\test.zip";
String[] args = { "C:\junk.pdf" };
//FileOutputStream f = new FileOutputStream(file);
FileOutputStream f = new FileOutputStream(file);
CheckedOutputStream csum =
new CheckedOutputStream(f, new Adler32());
ZipOutputStream out =
new ZipOutputStream(
[i]Do I convert this to a FileOutputStream of the file, that being a PDF?[/i]
[b]new BufferedOutputStream(csum)[/b]);
for (int i = 0; i < args.length; i++) {
BufferedReader in = new BufferedReader(new FileReader(args[i]));
out.putNextEntry(new ZipEntry(args[i]));
int c;
while ((c = in.read()) != -1)
out.write(c);
in.close();
}
out.close();
// Checksum valid only after the file
// has been closed!
System.out.println("Checksum: " + csum.getChecksum().getValue());
// Now extract the files:
System.out.println("Reading file");
FileInputStream fi = new FileInputStream(file);
CheckedInputStream csumi =
new CheckedInputStream(fi, new Adler32());
ZipInputStream in2 =
new ZipInputStream(new BufferedInputStream(csumi));
ZipEntry ze;
while ((ze = in2.getNextEntry()) != null) {
int x;
while ((x = in2.read()) != -1)
System.out.write(x);
}
System.out.println("Checksum: " + csumi.getChecksum().getValue());
in2.close();
// Alternative way to open and read
// zip files:
ZipFile zf = new ZipFile(file);
Enumeration e = zf.entries();
while (e.hasMoreElements()) {
ZipEntry ze2 = (ZipEntry) e.nextElement();
System.out.println("File: " + ze2);
// ... and extract the data as before
}
Dano
dan_kryzer@hotmail.com
What's your major malfunction