[
https://issues.apache.org/jira/browse/COMPRESS-255?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13874435#comment-13874435
]
Stefan Bodewig commented on COMPRESS-255:
-----------------------------------------
Unfortunately it is not that simple.
BZip2 is block based with block sizes of 900kB by default. You can't read a
single byte from it unless a full block has been read from the underlying
stream - and once it has been read you can read a lot of bytes from the
uncompressed block even when the underlying stream's available returns 0.
A correct implementation must take into account how many bytes are remaining
inside the uncompressed block and must return 0 as long as the current block
hasn't been filled. And once it has been filled it can give a better
estimation of how much can be requested without blocking.
> BZip2CompressorInputStream does not implement public int available() throws
> IOException
> ---------------------------------------------------------------------------------------
>
> Key: COMPRESS-255
> URL: https://issues.apache.org/jira/browse/COMPRESS-255
> Project: Commons Compress
> Issue Type: Bug
> Components: Compressors
> Affects Versions: 1.6
> Environment: Java
> Reporter: Kevin Dauch
> Labels: patch
> Original Estimate: 1h
> Remaining Estimate: 1h
>
> Here is the patch that I created:
> ---
> src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java
> (revision 1550240)
> +++
> src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java
> (working copy)
> @@ -147,6 +147,16 @@
> }
> }
>
> + @Override
> + public int available() throws IOException {
> + int avail = 0;
> + if (this.in != null) {
> + avail = this.in.available();
> + }
> + return avail;
> + }
> +
> +
> /*
> * (non-Javadoc)
> *
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)