Re: java unzip :: verify file
Could some please convert the zip verifier into CFMX? I'm just not that JAVA literate and don't know how to use this in a CFMX 7 environment. I'm going to use this code to augment unzip code found at http://www.rewindlife.com/archives/41.cfm Crashing my server is bad. ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:296633 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: java unzip :: verify file
don't know how to use this in a CFMX 7 environment. I'm going to use this code to augment unzip code found at http://www.rewindlife.com/archives/41.cfm You can compile the above code into a java class. Then place the .class file (or jar) into the CF classpath and reboot. Then you can use the ZipFileVerifier class in place of java.util.zip.ZipFile in the unZipFile function. Replacing this line zipFile = createObject(java, java.util.zip.ZipFile); With zipFile = createObject(java, path.to.ZipFileVerifier); I think the rest of the function code remains the same. Another alternative would be to convert the above code into a CF function. Something like cffunction name=verifyZipFile returntype=struct output=false cfargument name=pathToFile type=string required=true cfset var Local = structNew() cfscript Local.results = structNew(); Local.results.InputFile = arguments.pathToFile; try { Local.fis = createObject(java, java.io.FileInputStream).init(arguments.pathToFile); Local.zipin = createObject(java, java.util.zip.ZipInputStream).init(Local.fis); while ( Local.zipin.available() EQ 1 ) { Local.zipin.getNextEntry(); } Local.results.wasVerified = true; Local.results.errorMessage = ; } catch (java.lang.Exception e) { Local.results.wasVerified = false; Local.results.errorMessage = e.message; } /cfscript cfreturn Local.results /cffunction cfset status = verifyZipFile(c:\path\to\yourZipFile.Zip) cfoutput wasVerified = #status.wasVerified#br errorMessage = #status.errorMessage#br InputFile = #status.InputFile#br /cfoutput ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:296634 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: java unzip :: verify file
I can't compile, reboot, etc. The server is a corprate one which I have no control over and hard to get done. I'll have to go with the CF Function. I'll package it together withthe unzip code in a CFC. Thanks for re-coding it! I'll compare what you did to the original code -- should give me a nice insight in Java vs CF. ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:296635 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: java unzip :: verify file
I'll compare what you did to the original code -- should give me a nice insight in Java vs CF. Yes. Keep in mind it is slightly different from the last example. That example extends the ZipFile class and calls the verify function inside the class's constructor. It's similar to extending a cfcomponent, then calling another function inside init(). Also the last example throws and exception if an error is encountered. The CF version does not. It catches any exceptions and returns the error message as part of the results structure. ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:296639 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: java unzip :: verify file
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
java unzip :: verify file
Hi, I have a cf script that is using java.util.zip.ZipFile to unzip - works great, except when... If the zip if corrupt it kills jRun. Does any one know if there is a way to verify / check the zip file to ensure it is not corrupt? Because it is dieing at the jRun level, I can not use cfcatch. ~| 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:278408 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
RE: java unzip :: verify file
Can't you just read the file as a file object inside a try/catch and if it fails, the file is assumed to be corrupt _ Jake Churchill CF Webtools 11204 Davenport, Ste. 200b Omaha, NE 68154 http://www.cfwebtools.com 402-408-3733 x103 -Original Message- From: AJ Mercer [mailto:[EMAIL PROTECTED] Sent: Thursday, May 17, 2007 1:32 AM To: CF-Talk Subject: java unzip :: verify file Hi, I have a cf script that is using java.util.zip.ZipFile to unzip - works great, except when... If the zip if corrupt it kills jRun. Does any one know if there is a way to verify / check the zip file to ensure it is not corrupt? Because it is dieing at the jRun level, I can not use cfcatch. ~| Macromedia ColdFusion MX7 Upgrade to MX7 experience time-saving features, more productivity. http://www.adobe.com/products/coldfusion?sdid=RVJW Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:278439 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: java unzip :: verify file
cffile does not crash when using cffile with read or readbinary On 5/17/07, Jake Churchill [EMAIL PROTECTED] wrote: Can't you just read the file as a file object inside a try/catch and if it fails, the file is assumed to be corrupt _ Jake Churchill CF Webtools 11204 Davenport, Ste. 200b Omaha, NE 68154 http://www.cfwebtools.com 402-408-3733 x103 -Original Message- From: AJ Mercer [mailto:[EMAIL PROTECTED] Sent: Thursday, May 17, 2007 1:32 AM To: CF-Talk Subject: java unzip :: verify file Hi, I have a cf script that is using java.util.zip.ZipFile to unzip - works great, except when... If the zip if corrupt it kills jRun. Does any one know if there is a way to verify / check the zip file to ensure it is not corrupt? Because it is dieing at the jRun level, I can not use cfcatch. ~| Create Web Applications With ColdFusion MX7 Flex 2. Build powerful, scalable RIAs. Free Trial http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJS Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:278544 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: java unzip :: verify file
cftry cfset zipfile=CreateObject(java, java.util.zip.ZipFile).init(zipFileName) / cfcatch type=any cfdump var=#cfcatch# / /cfcatch /cftry That should throw a ZipException (and dump it) if the Zip file is corrupt /Max On 5/18/07, AJ Mercer [EMAIL PROTECTED] wrote: cffile does not crash when using cffile with read or readbinary On 5/17/07, Jake Churchill [EMAIL PROTECTED] wrote: Can't you just read the file as a file object inside a try/catch and if it fails, the file is assumed to be corrupt _ Jake Churchill CF Webtools 11204 Davenport, Ste. 200b Omaha, NE 68154 http://www.cfwebtools.com 402-408-3733 x103 -Original Message- From: AJ Mercer [mailto:[EMAIL PROTECTED] Sent: Thursday, May 17, 2007 1:32 AM To: CF-Talk Subject: java unzip :: verify file Hi, I have a cf script that is using java.util.zip.ZipFile to unzip - works great, except when... If the zip if corrupt it kills jRun. Does any one know if there is a way to verify / check the zip file to ensure it is not corrupt? Because it is dieing at the jRun level, I can not use cfcatch. ~| Macromedia ColdFusion MX7 Upgrade to MX7 experience time-saving features, more productivity. http://www.adobe.com/products/coldfusion?sdid=RVJW Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:278545 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: java unzip :: verify file
no, it is getting past that zipFile = createObject(java,java.util.zip.ZipFile); zipFile.init(zipFilePath); //Get Entry Objects for Entries in the ZIP File entryList = zipFile.entries(); //Create List of File Names from the ZIP File while(entryList.hasMoreElements()) { entry = entryList.nextElement(); == dies here if (not entry.isDirectory()) { fileList = ListAppend(fileList,entry.getName()); } } message = invalid LOC header (bad signature) This kills jRun so I can't catch it in ColdFusion On 5/18/07, Maximilian Nyman [EMAIL PROTECTED] wrote: cftry cfset zipfile=CreateObject(java, java.util.zip.ZipFile).init(zipFileName) / cfcatch type=any cfdump var=#cfcatch# / /cfcatch /cftry That should throw a ZipException (and dump it) if the Zip file is corrupt /Max On 5/18/07, AJ Mercer [EMAIL PROTECTED] wrote: cffile does not crash when using cffile with read or readbinary On 5/17/07, Jake Churchill [EMAIL PROTECTED] wrote: Can't you just read the file as a file object inside a try/catch and if it fails, the file is assumed to be corrupt _ Jake Churchill CF Webtools 11204 Davenport, Ste. 200b Omaha, NE 68154 http://www.cfwebtools.com 402-408-3733 x103 -Original Message- From: AJ Mercer [mailto:[EMAIL PROTECTED] Sent: Thursday, May 17, 2007 1:32 AM To: CF-Talk Subject: java unzip :: verify file Hi, I have a cf script that is using java.util.zip.ZipFile to unzip - works great, except when... If the zip if corrupt it kills jRun. Does any one know if there is a way to verify / check the zip file to ensure it is not corrupt? Because it is dieing at the jRun level, I can not use cfcatch. ~| Upgrade to Adobe ColdFusion MX7 The most significant release in over 10 years. Upgrade see new features. http://www.adobe.com/products/coldfusion?sdid=RVJR Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:278546 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: java unzip :: verify file
Then I would suggest find/writing a small Java ZipVerifier that will do this verification for you. I created a quick example of a verifier and it seems to do the job. !--- Start ZipVerifier.java --- import java.util.zip.ZipFile; import java.util.zip.ZipException; import java.io.IOException; public class ZipVerifier { public static String EXCEPTION_STR = ; public static boolean verifyZip(String filePath) { try { ZipFile zipFile = new ZipFile(filePath); return true; } catch( ZipException ze ) { EXCEPTION_STR = ze.getMessage(); } catch( IOException ioe ) { EXCEPTION_STR = ioe.getMessage(); } catch( SecurityException se ) { EXCEPTION_STR = se.getMessage(); } return false; } public static void main(String[] args) { if( args.length 0 ) { System.out.println( Valid Zip file?: + ZipVerifier.verifyZip(args[0]) ); System.out.println( EXCEPTION_STR ); } else { System.out.println( usage: java ZipVerifier zipfile path ); } } } !--- End ZipVerifier.java --- On 5/18/07, AJ Mercer [EMAIL PROTECTED] wrote: no, it is getting past that zipFile = createObject(java,java.util.zip.ZipFile); zipFile.init(zipFilePath); //Get Entry Objects for Entries in the ZIP File entryList = zipFile.entries(); //Create List of File Names from the ZIP File while(entryList.hasMoreElements()) { entry = entryList.nextElement(); == dies here if (not entry.isDirectory()) { fileList = ListAppend(fileList,entry.getName()); } } message = invalid LOC header (bad signature) This kills jRun so I can't catch it in ColdFusion On 5/18/07, Maximilian Nyman [EMAIL PROTECTED] wrote: cftry cfset zipfile=CreateObject(java, java.util.zip.ZipFile).init(zipFileName) / cfcatch type=any cfdump var=#cfcatch# / /cfcatch /cftry That should throw a ZipException (and dump it) if the Zip file is corrupt /Max On 5/18/07, AJ Mercer [EMAIL PROTECTED] wrote: cffile does not crash when using cffile with read or readbinary On 5/17/07, Jake Churchill [EMAIL PROTECTED] wrote: Can't you just read the file as a file object inside a try/catch and if it fails, the file is assumed to be corrupt _ Jake Churchill CF Webtools 11204 Davenport, Ste. 200b Omaha, NE 68154 http://www.cfwebtools.com 402-408-3733 x103 -Original Message- From: AJ Mercer [mailto:[EMAIL PROTECTED] Sent: Thursday, May 17, 2007 1:32 AM To: CF-Talk Subject: java unzip :: verify file Hi, I have a cf script that is using java.util.zip.ZipFile to unzip - works great, except when... If the zip if corrupt it kills jRun. Does any one know if there is a way to verify / check the zip file to ensure it is not corrupt? Because it is dieing at the jRun level, I can not use cfcatch. ~| Macromedia ColdFusion MX7 Upgrade to MX7 experience time-saving features, more productivity. http://www.adobe.com/products/coldfusion?sdid=RVJW Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:278548 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: java unzip :: verify file
wow - that is impressive! Would you be able to compile it for me? On 5/18/07, Maximilian Nyman [EMAIL PROTECTED] wrote: Then I would suggest find/writing a small Java ZipVerifier that will do this verification for you. I created a quick example of a verifier and it seems to do the job. !--- Start ZipVerifier.java --- import java.util.zip.ZipFile; import java.util.zip.ZipException; import java.io.IOException; public class ZipVerifier { public static String EXCEPTION_STR = ; public static boolean verifyZip(String filePath) { try { ZipFile zipFile = new ZipFile(filePath); return true; } catch( ZipException ze ) { EXCEPTION_STR = ze.getMessage(); } catch( IOException ioe ) { EXCEPTION_STR = ioe.getMessage(); } catch( SecurityException se ) { EXCEPTION_STR = se.getMessage(); } return false; } public static void main(String[] args) { if( args.length 0 ) { System.out.println( Valid Zip file?: + ZipVerifier.verifyZip(args[0]) ); System.out.println( EXCEPTION_STR ); } else { System.out.println( usage: java ZipVerifier zipfile path ); } } } !--- End ZipVerifier.java --- On 5/18/07, AJ Mercer [EMAIL PROTECTED] wrote: no, it is getting past that zipFile = createObject(java,java.util.zip.ZipFile); zipFile.init(zipFilePath); //Get Entry Objects for Entries in the ZIP File entryList = zipFile.entries(); //Create List of File Names from the ZIP File while(entryList.hasMoreElements()) { entry = entryList.nextElement(); == dies here if (not entry.isDirectory()) { fileList = ListAppend(fileList,entry.getName()); } } message = invalid LOC header (bad signature) This kills jRun so I can't catch it in ColdFusion On 5/18/07, Maximilian Nyman [EMAIL PROTECTED] wrote: cftry cfset zipfile=CreateObject(java, java.util.zip.ZipFile).init(zipFileName) / cfcatch type=any cfdump var=#cfcatch# / /cfcatch /cftry That should throw a ZipException (and dump it) if the Zip file is corrupt /Max On 5/18/07, AJ Mercer [EMAIL PROTECTED] wrote: cffile does not crash when using cffile with read or readbinary On 5/17/07, Jake Churchill [EMAIL PROTECTED] wrote: Can't you just read the file as a file object inside a try/catch and if it fails, the file is assumed to be corrupt _ Jake Churchill CF Webtools 11204 Davenport, Ste. 200b Omaha, NE 68154 http://www.cfwebtools.com 402-408-3733 x103 -Original Message- From: AJ Mercer [mailto:[EMAIL PROTECTED] Sent: Thursday, May 17, 2007 1:32 AM To: CF-Talk Subject: java unzip :: verify file Hi, I have a cf script that is using java.util.zip.ZipFile to unzip - works great, except when... If the zip if corrupt it kills jRun. Does any one know if there is a way to verify / check the zip file to ensure it is not corrupt? Because it is dieing at the jRun level, I can not use cfcatch. ~| Create robust enterprise, web RIAs. Upgrade integrate Adobe Coldfusion MX7 with Flex 2 http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJP Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:278549 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: java unzip :: verify file
FYI for the list. It turned out that the issue AJ got was a Java bug for ZipFile. It turns out that ZipFile doesn't handle corrupt zip files very well - It throws an InternalError which will just kill JRun. :S So, I updated my ZipVerifier to use ZipInputStream instead of ZipFile, which will correctly catch the corrupt ZipFile exception. /Max !--- START ZipVerifier.java --- import java.util.*; import java.io.*; import java.util.zip.*; public class ZipVerifier { public static String EXCEPTION_STR = ; public static boolean verifyZip(String filePath) { try { ZipInputStream zipin = new ZipInputStream(new FileInputStream(filePath)) ; while( zipin.available() == 1 ) { ZipEntry zipEntry = zipin.getNextEntry(); System.out.println(zipEntry); } return true; } catch( Exception e ) { EXCEPTION_STR = e.getMessage(); } return false; } public static void main(String[] args) { if( args.length 0 ) { System.out.println( Valid Zip file?: + ZipVerifier.verifyZip(args[0]) ); System.out.println( EXCEPTION_STR ); } else { System.out.println( usage: java ZipVerifier zipfile path ); } } } !--- END ZipVerifier.java --- ~| Create robust enterprise, web RIAs. Upgrade integrate Adobe Coldfusion MX7 with Flex 2 http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJP Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:278559 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4