My goal is to encode a file and pin it to a folder in java. I have to use the Apache Commons-codec library. I can encode and zip it, and it works fine, but when I decode it back to its original form, it looks like the file was not fully encoded. Some parts seem to be missing. Can someone tell me why this is happening?
I also attach part of my code for your link so you can direct me accordingly.
private void zip() {
int BUFFER_SIZE = 4096;
byte[] buffer = new byte[BUFFER_SIZE];
try {
String outFilename = "H:\\OUTPUT.zip";
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(
outFilename));
for (int i : list.getSelectedIndices()) {
System.out.println(vector.elementAt(i));
FileInputStream in = new FileInputStream(vector.elementAt(i));
File f = vector.elementAt(i);
out.putNextEntry(new ZipEntry(f.getName()));
int len;
while ((len = in.read(buffer)) > 0) {
buffer = org.apache.commons.codec.binary.Base64
.encodeBase64(buffer);
out.write(buffer, 0, len);
}
out.closeEntry();
in.close();
}
out.close();
} catch (IOException e) {
System.out.println("caught exception");
e.printStackTrace();
}
}
source
share