EOFException: Unexpected end of ZLIB input stream
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   laugh_smile
Posted On:   Thursday, April 13, 2006 01:59 AM

when i decompress byte[] as the following,the Exception is raise. my jdk is sun 1.4.2. public byte[] decompress(byte[] outputData) throws IOException { &nbsp&nbspByteArrayOutputStream output = new ByteArrayOutputStream(1024); &nbsp&nbspByteArrayInputStream input = new ByteArrayInputStream(outputData); &nbsp&nbspGZIPInputStream gzinpt = new GZIPInputStream(input); &nbsp&nbspbyte[] buf = new byte[BUFFER_SIZE]; &nbsp&nbspbyte[] result = null; &nbsp&nbspint number = 0; &nbsp&nbsptry { &nbsp&nbsp&nbspwhile ((number = gzinpt.read(buf)) != -1) { &nbsp&   More>>

when i decompress byte[] as the following,the Exception is raise.

my jdk is sun 1.4.2.


public byte[] decompress(byte[] outputData) throws IOException {

&nbsp&nbspByteArrayOutputStream output = new ByteArrayOutputStream(1024);

&nbsp&nbspByteArrayInputStream input = new ByteArrayInputStream(outputData);

&nbsp&nbspGZIPInputStream gzinpt = new GZIPInputStream(input);

&nbsp&nbspbyte[] buf = new byte[BUFFER_SIZE];

&nbsp&nbspbyte[] result = null;

&nbsp&nbspint number = 0;

&nbsp&nbsptry {

&nbsp&nbsp&nbspwhile ((number = gzinpt.read(buf)) != -1) {

&nbsp&nbsp&nbsp&nbspoutput.write(buf, 0, number);

&nbsp&nbsp&nbsp&nbspif (gzinpt.available()==0)

&nbsp&nbsp&nbsp&nbsp&nbspbreak;

&nbsp&nbsp&nbsp&nbsp}

&nbsp&nbsp&nbsp} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

&nbsp&nbsp&nbsp} finally{

&nbsp&nbspoutput.flush();

&nbsp&nbspgzinpt.close();

&nbsp&nbspinput.close();

&nbsp&nbspoutput.close();

&nbsp&nbspresult = output.toByteArray();

&nbsp&nbsp}

&nbspreturn result;

}




Exception is :
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 java.util.zip.GZIPInputStream.read(GZIPInputStream.java:87)
at java.io.FilterInputStream.read(FilterInputStream.java:90)
at com.iijt.ticket.web.FileService.decompress(FileService.java:177)
at com.iijt.ticket.web.FileService.putFile(FileService.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
................

   <<Less

Re: EOFException: Unexpected end of ZLIB input stream

Posted By:   Almagest_FUTT  
Posted On:   Monday, April 17, 2006 06:24 PM

when i decompress byte[] as the following,the Exception is raise.

The data you pretend to be GZIP is not.


At any rate this isn't really surprising if you write methods that act as if everything were OK although Exceptions have occured. By that I mean you assigning the result in the finally clause. I think you shouldn't do that. If any Exception occurs during the decompresson, I think you had better throw it.


Keep in mind that you must close() a GZIPOutputStream (or call finish() on it) in order to have valid data.

About | Sitemap | Contact