com.alutam.ziputils
Class ZipDecryptInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by com.alutam.ziputils.ZipDecryptInputStream
All Implemented Interfaces:
Closeable

public class ZipDecryptInputStream
extends InputStream

Input stream converting a password-protected zip to an unprotected zip.

Example usage:

Reading a password-protected zip from file:

  ZipDecryptInputStream zdis = new ZipDecryptInputStream(new FileInputStream(fileName), password);
  ZipInputStream zis = new ZipInputStream(zdis);
  ... read the zip file from zis - the standard JDK ZipInputStream ...
 

Converting a password-protected zip file to an unprotected zip file:

  ZipDecryptInputStream src = new ZipDecryptInputStream(new FileInputStream(srcFile), password);
  FileOutputStream dest = new FileOutputStream(destFile);

  // 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)

Constructor Summary
ZipDecryptInputStream(InputStream stream, char[] password)
          Safer constructor.
ZipDecryptInputStream(InputStream stream, String password)
          Creates a new instance of the stream.
 
Method Summary
 void close()
           
 int read()
           
 
Methods inherited from class java.io.InputStream
available, mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZipDecryptInputStream

public ZipDecryptInputStream(InputStream stream,
                             String password)
Creates a new instance of the stream.

Parameters:
stream - Input stream serving the password-protected zip file to be decrypted.
password - Password to be used to decrypt the password-protected zip file.

ZipDecryptInputStream

public ZipDecryptInputStream(InputStream stream,
                             char[] password)
Safer constructor. Takes password as a char array that can be nulled right after calling this constructor instead of a string that may be visible on the heap for the duration of application run time.

Parameters:
stream - Input stream serving the password-protected zip file.
password - Password to use for decrypting the zip file.
Method Detail

read

public int read()
         throws IOException
Specified by:
read in class InputStream
Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException


Copyright © 2012. All Rights Reserved.