Solved

Unexpected end of ZLIB input stream

Posted on 2004-10-07
5
846 Views
Last Modified: 2009-12-16
I'm pulling data from a SQL database. The data is compressed.

I'm using the following code to read the data:
//------------------------------------------------------------------------------------------
if (rs.next())
    {
         InputStreamReader in = new InputStreamReader(
      new InflaterInputStream(
      new ByteArrayInputStream((byte [])rs.getObject("Compressed_Data")),new Inflater(true)),"UTF-16LE");
          char[] cbuf = new char[16000];
             sb = new StringBuffer("");
          int i = 0;
          while (i > -1) {
                       i = in.read(cbuf);
                     if (i > -1){
                           sb.append(new String(cbuf).substring(0,i));
                                 // System.out.println(new String(cbuf).substring(0,i));
                         }
                     }
          System.out.println( sb.toString());
    }
//------------------------------------------------------------------------------------------

When the commented println statement is uncommented, you can see each piece of data that is decompressed. The data is XML. When it gets to the last read, I get an exception. Also, it's interesting to note that if I change "cbuf" to char[1], and I print out each read as it's being appended, I can verify that the final tag of the xml is in fact being decompressed and appended to "sb". However, java continues to try and read past the xml and is throwing the following exception:


java.io.EOFException: Unexpected end of ZLIB input stream
      at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:215)
      at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:134)
      at sun.nio.cs.StreamDecoder$CharsetSD.readBytes(StreamDecoder.java:408)
      at sun.nio.cs.StreamDecoder$CharsetSD.implRead(StreamDecoder.java:450)
      at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:182)
      at java.io.InputStreamReader.read(InputStreamReader.java:167)
      at java.io.Reader.read(Reader.java:100)
      at clsMain.GetStatement(clsMain.java:58)
      at clsMain.main(clsMain.java:28)


I need to know what I can do to correct this. Another application that was written in VB.NET can succesfully read the entire compressed XML without any problems. So, I'm sure it's not a corrupt compression. Java can read the entire compressed xml, but at the end of the stream throws the exception. Is there a bug in my code? or a bug in java? or am I missing something that would correct this?

If you need more information, please let me know and I'll see what I can provide.

Thanks,
Tony




0
Comment
Question by:mytonytiger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 12248299
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12248416
I hope you don't use JDK 1.1.x because

There is a bug in JDK 1.1.x which causes the ZipFile class to read beyond the end-of-file.
JavaSoft recommends the following workaround: Do not attempt to read more bytes than the entry contains.
Call ZipEntry.getSize() to get the actual size of the entry and use that value to keep track of the remaining number of bytes while reading the entry.
0
 
LVL 37

Accepted Solution

by:
zzynx earned 500 total points
ID: 12248541
See Bug ID 4040920 in Sun's BugParade for more details about the workaround.

There, I read also the following comments:

I have been having the same problem in 1.4.01 under HP-UX (11i). The problem is exactly as described above.
---------------------------------------------------------------------
Yup, it looks like this bug still occurs under JDK 1.4.2_02 on Mac OS X.
It's too bad that this bug is closed or else somebody might realize that it needs fixing.
Can't vote on it either. Can't fix the source and redistribute it either due to the not-really-open-source license for the JDK.
The community has clearly fixed the bug and handed it back to Sun but Sun won't integrate the fixes.

I guess I'll have to code a workaround everywhere I see this problem. Yay!
---------------------------------------------------------------------
The problem is still happening with JRE 1.3.1_13, is someone from Sun going to attend to this?
0
 
LVL 5

Author Comment

by:mytonytiger
ID: 12248884
I'm using 1.4.2_04

It seems to be a java bug.

What fun!
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12248941
Thanks for accepting

>> What fun!
;)

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Unhandled exception type Exception 18 52
ejb wildfly example 2 74
IBM TS2900 (3572) Tape Autoloader Java? 12 61
Java Inheritance super keyword use 8 37
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question