mirror of
https://github.com/corda/corda.git
synced 2025-01-06 05:04:20 +00:00
return a useful value from InflaterInputStream.available
Note the following excerpt from PNGFileFormat.java in SWT: /* * InflaterInputStream does not consume all bytes in the stream * when it is closed. This may leave unread IDAT chunks. The fix * is to read all available bytes before closing it. */ while (stream.available() > 0) stream.read(); stream.close(); This code relies on the documented behavior of InflaterInputStream.available, which must return "0 after EOF has been reached, otherwise always return 1". This is unlike InputStream.available, which is documented to return "the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream", and says nothing about how many bytes are left until the end of stream. This commit modifies InflaterInputStream.available to behave according to Sun's documentation.
This commit is contained in:
parent
fca98df55b
commit
f0f35a920f
@ -72,6 +72,10 @@ public class BufferedInputStream extends InputStream {
|
||||
return count;
|
||||
}
|
||||
|
||||
public int available() throws IOException {
|
||||
return in.available() + (limit - position);
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
in.close();
|
||||
}
|
||||
|
@ -61,6 +61,8 @@ public class InflaterInputStream extends InputStream {
|
||||
return count;
|
||||
} else if (inflater.needsDictionary()) {
|
||||
throw new IOException("missing dictionary");
|
||||
} else if (inflater.finished()) {
|
||||
return -1;
|
||||
}
|
||||
} catch (DataFormatException e) {
|
||||
throw new IOException(e);
|
||||
@ -68,6 +70,10 @@ public class InflaterInputStream extends InputStream {
|
||||
}
|
||||
}
|
||||
|
||||
public int available() throws IOException {
|
||||
return inflater.finished() ? 0 : 1;
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
in.close();
|
||||
inflater.dispose();
|
||||
|
Loading…
Reference in New Issue
Block a user