@@ -95,9 +95,16 @@ public void seek(long position) throws IOException
9595 @ Override
9696 public void skip (int length ) throws IOException
9797 {
98- for (int i =0 ; i < length ;i ++)
98+ byte [] skipBuffer = new byte [Math .min (length , BUFFER_SIZE )];
99+ int remaining = length ;
100+ while (remaining > 0 )
99101 {
100- read ();
102+ int bytesRead = read (skipBuffer , 0 , Math .min (remaining , skipBuffer .length ));
103+ if (bytesRead == -1 )
104+ {
105+ break ;
106+ }
107+ remaining -= bytesRead ;
101108 }
102109 }
103110
@@ -138,6 +145,20 @@ public int read() throws IOException
138145 public int read (byte [] b , int offset , int length ) throws IOException
139146 {
140147 checkClosed ();
148+ // Parameter validation as defined in InputStream.read(byte[], int, int)
149+ if (b == null )
150+ {
151+ throw new NullPointerException ("buffer is null" );
152+ }
153+ if (offset < 0 || length < 0 || offset + length > b .length )
154+ {
155+ throw new IndexOutOfBoundsException ("buffer length=" + b .length + " offset=" + offset
156+ + " length=" + length );
157+ }
158+ if (length == 0 )
159+ {
160+ return 0 ;
161+ }
141162 if (isEOF ())
142163 {
143164 return -1 ;
@@ -162,7 +183,7 @@ else if (!fetch())
162183 break ;
163184 }
164185 }
165- return numberOfBytesRead ;
186+ return numberOfBytesRead > 0 ? numberOfBytesRead : - 1 ;
166187 }
167188
168189 @ Override
@@ -233,7 +254,7 @@ private boolean fetch() throws IOException
233254 catch (IOException exception )
234255 {
235256 // some data could be read -> don't throw an exception
236- LOG .warn ("FlateFilter: premature end of stream due to a DataFormatException" );
257+ LOG .warn ("premature end of stream, some data could be read " , exception );
237258 isEOF = true ;
238259 throw exception ;
239260 }
@@ -248,7 +269,8 @@ private boolean fetch() throws IOException
248269 public int available () throws IOException
249270 {
250271 checkClosed ();
251- return is .available ();
272+ int buffered = Math .max (0 , bufferBytes [CURRENT ] - currentBufferPointer );
273+ return buffered + is .available ();
252274 }
253275
254276 /**
@@ -258,7 +280,7 @@ public int available() throws IOException
258280 public long length () throws IOException
259281 {
260282 checkClosed ();
261- return size ;
283+ return size + is . available () ;
262284 }
263285
264286 @ Override
@@ -269,8 +291,9 @@ public void rewind(int bytes) throws IOException
269291 {
270292 currentBufferPointer -= bytes ;
271293 position -= bytes ;
294+ isEOF = false ;
272295 }
273- else if (bufferBytes [LAST ] > 0 )
296+ else if (bufferBytes [LAST ] > 0 && ( bytes - currentBufferPointer ) <= bufferBytes [ LAST ] )
274297 {
275298 // there is a former buffer
276299 int remainingBytesToRewind = bytes - currentBufferPointer ;
0 commit comments