Provide accurate InputStream.available() results

Provide accurate InputStream.available() results by using the size
attribute of the ZipEntry. This helps improve performance with
CGLib and also fixes issues where libraries expect that a non-zero
result from available() indicates that read() will not return -1.
This commit is contained in:
Phillip Webb
2013-08-27 01:05:43 -07:00
parent cb7cc3991b
commit 5b7d56895b
2 changed files with 27 additions and 4 deletions

View File

@@ -115,7 +115,9 @@ public class RandomAccessJarFileTests {
public void getInputStream() throws Exception {
InputStream inputStream = this.jarFile.getInputStream(this.jarFile
.getEntry("1.dat"));
assertThat(inputStream.available(), equalTo(1));
assertThat(inputStream.read(), equalTo(1));
assertThat(inputStream.available(), equalTo(0));
assertThat(inputStream.read(), equalTo(-1));
}