com.alutam.ziputils
Class ZipEncryptOutputStream
java.lang.Object
java.io.OutputStream
com.alutam.ziputils.ZipEncryptOutputStream
- All Implemented Interfaces:
- Closeable, Flushable
public class ZipEncryptOutputStream
- extends OutputStream
Output stream that can be used to password-protect zip files.
Example usage:
Creating a password-protected zip file:
ZipEncryptOutputStream zeos = new ZipEncryptOutputStream(new FileOutputStream(fileName), password);
ZipOutputStream zos = new ZipOuputStream(zdis);
... create zip file using the standard JDK ZipOutputStream in zos variable ...
Converting a plain zip file to a password-protected zip file:
FileInputStream src = new FileInputStream(srcFile);
ZipEncryptOutputStream dest = new ZipEncryptOutputStream(new FileOutputStream(destFile), password);
// should wrap with try-catch-finally, do the close in finally
int b;
while ((b = src.read()) > -1) {
dest.write(b);
}
src.close();
dest.close();
- Author:
- Martin Matula (martin at alutam.com)
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ZipEncryptOutputStream
public ZipEncryptOutputStream(OutputStream delegate,
String password)
- Convenience constructor taking password as a string.
- Parameters:
delegate
- Output stream to write the password-protected zip to.password
- Password to use for protecting the zip.
ZipEncryptOutputStream
public ZipEncryptOutputStream(OutputStream delegate,
char[] password)
- Safer version of the constructor. Takes password as a char array that can
be nulled right after calling this constructor instead of a string that may
stay visible on the heap for the duration of application run time.
- Parameters:
delegate
- Output stream to write the password-protected zip to.password
- Password to use for protecting the zip.
write
public void write(int b)
throws IOException
- Specified by:
write
in class OutputStream
- Throws:
IOException
close
public void close()
throws IOException
- Specified by:
close
in interface Closeable
- Overrides:
close
in class OutputStream
- Throws:
IOException
Copyright © 2012. All Rights Reserved.