Max has taken it up a notch now
You can use this class in replace of 'java.util.zip.ZipFile'
and it throws an error on init() that can be captured by ColdFusion if the
file is corrupt.

The downside though, is the zip is processed twice, once to verify it, and
then again for the normal processing. But compared to taking out jRun, I
think it is a small price to pay.

<!--- start ZipFileVerifier.java --->
import java.io.File;
import java.io.FileInputStream;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;

public class ZipFileVerifier extends ZipFile {

  private static Exception _EXCEPTION = null;

  public ZipFileVerifier(String filePath) throws Exception {
    super(filePath);
    if( !verifyZip(filePath) )
        throw _EXCEPTION;
  }

  private ZipFileVerifier(File file) throws Exception {
    super(file);
    if( !verifyZip(file) )
        throw _EXCEPTION;
  }

  private ZipFileVerifier(File file, int mode) throws Exception {
    super(file, mode);
    if( !verifyZip(file) )
        throw _EXCEPTION;
  }

  public static boolean verifyZip(String filePath) {
      return verifyZip(new File(filePath));
  }
  public static boolean verifyZip(File file) {
    try {
      ZipInputStream zipin = new ZipInputStream(new FileInputStream(file)) ;
      while( zipin.available() == 1 ) {
          zipin.getNextEntry();
      }
      return true;
    }
    catch( Exception e ) {
        _EXCEPTION = e;
    }
    return false;
  }

  public static Exception getException() {
      return _EXCEPTION;
  }

  public static void main(String[] args) {
    if( args.length > 0 ) {
        try {
            new ZipFileVerifier(args[0]);
        }
        catch( Exception e ) {
            System.out.println( e );
        }
    }
    else {
      System.out.println( "usage: java ZipFileVerifier <zipfile path>" );
    }
  }
}
<!--- end ZipFileVerifier.java --->


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
ColdFusion MX7 by AdobeĀ®
Dyncamically transform webcontent into Adobe PDF with new ColdFusion MX7. 
Free Trial. http://www.adobe.com/products/coldfusion?sdid=RVJV

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:278561
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to