aspose file tools*
The moose likes I/O and Streams and the fly likes ZipInputStream Throws Illegalargument exception for diacritics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "ZipInputStream Throws Illegalargument exception for diacritics " Watch "ZipInputStream Throws Illegalargument exception for diacritics " New topic
Author

ZipInputStream Throws Illegalargument exception for diacritics

meghala devi
Greenhorn

Joined: Oct 07, 2010
Posts: 3
Hi



If I run the below program with the zip file which has some files with diacritic characters (e.g 1-2GF-969##JÖN.pdf) , I get IllegalArgumentException.

My application has to support all languages. So, we set encoding to UTF-8


All languages work fine. But the problem comes when reading diacritic characters.

I tried using alternatives to zip input stream, like arcmexer and apache commons compress, but it does not help.

Please help me with this.

private static void readUsingJava() {
ZipInputStream zis;
try {
zis = new ZipInputStream(new FileInputStream("C:\\Check.zip"));
ZipEntry ze;
while ((ze = zis.getNextEntry()) != null) {
System.out.println("Name of the File Is :: " + ze.getName());
}
zis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}



Stack Trace

<java.lang.IllegalArgumentException>
<at java.util.zip.ZipInputStream.getUTF8String(ZipInputStream.java:299)>
<at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:73)>
<at java.util.zip.ZipInputStream.readLOC(ZipInputStream.java:238)>
<at com.hp.gpp.massupload.util.FileHandler.getTotalNoOfFilesinZip(FileHandler.java:153)>
<at com.hp.gpp.massupload.dao.DocumentDAO.updateDocuments(DocumentDAO.java:1995)>
<at com.hp.gpp.massupload.handler.LoadProcessor.updateLoad(LoadProcessor.java:350)>
<at com.hp.gpp.massupload.action.UpdateLoadAction.execute(UpdateLoadAction.java:153)>
<at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)>
<at com.hp.bco.pl.wpa.action.WPARequestProcessor.process(WPARequestProcessor.java:200)>
<at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)>
<at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)>
<at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)>
<at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)>
<at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:225)>
<at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:127)>
<at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:266)>
<at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)>
<at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)>
<at com.hp.gpp.massupload.filter.EncodingFilter.doFilter(EncodingFilter.java:33)>
<at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)>
<at com.hp.websat.timber.transaction.TransactionLoggingFilter.doFilter(TransactionLoggingFilter.java:113)>
<at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)>
<at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3160)>
<at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)>
<at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)>
<at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:1973)>
<at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1880)>
<at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1309)>
<at weblogic.work.ExecuteThread.execute(ExecuteThread.java:207)>
<at weblogic.work.ExecuteThread.run(ExecuteThread.java:179)>
<Error.jsp :: Setting archive file to null>



Apache commons compress.


I used Apache commons compress. It supports Chinese, but gives problem with diacritics. The characters read are not displayed properly. I can see boxes instead of diacritics, like INVID J?NK?PING.zip

But Chinese characters are displayed properly
Chinese?? ???.pdf



In the web-logic server also, i have set encoding
export LC_CTYPE=en_US.utf8

Kindly help me with this

ZipArchiveInputStream zin = new ZipArchiveInputStream(objInputStream, "UTF-8", true);
ZipArchiveEntry zipArchiveEntry = null;

while((zipArchiveEntry = zin.getNextZipEntry()) != null)
{
log.debug("File name to be set is :: "+entry.getName());

}
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

Meghala, welcome to the Ranch. Asking the same question all over the net doesn't change the answer I gave you yesterday. Heck, sometimes it doesn't even change the answerers.
http://www.javaprogrammingforums.com/file-i-o-other-i-o-streams/5460-zipinputstream-throws-illegalargument-exception-diacritics.html

Are there more cross posts, other than this one I already know about?
http://www.java-forums.org/advanced-java/33189-zipinputstream-throws-illegalargument-exception-diacritics.html

In future, please BeForthrightWhenCrossPostingToOtherSites.

edit
Also answered here
http://en.allexperts.com/q/Java-1046/2010/10/ZipInputStream-Throws-Illegalargument-exception.htm

Couldn't open this page, SO seems to be having a problem
http://stackoverflow.com/questions/3869544/zipinputstream-throws-illegalargument-exception-for-diacritics


luck, db
There are no new questions, but there may be new answers.
meghala devi
Greenhorn

Joined: Oct 07, 2010
Posts: 3
Hi Darryl,

Thanks a lot for your help and sorry for posting in many sites. I needed solution urgently. So i did it. Henceforth, i will mention reference to other sites as you suggested.



This works fine with Apache commons compress and Winzip - latest version - 14.5.
I tried with evaluation version of WinZIP.


We have got license for Winzip 9 only. It does not work with Winzip 9 and apache :-)
So, I'm trying to find some alternative solutions. If you know, kindly help.


 
 
subject: ZipInputStream Throws Illegalargument exception for diacritics