Merge branch '1.5.x' into 2.0.x

This commit is contained in:
Andy Wilkinson
2018-06-19 20:06:44 +01:00
2 changed files with 47 additions and 7 deletions

View File

@@ -100,4 +100,36 @@ public class ZipHeaderPeekInputStreamTests {
}
}
@Test
public void readMoreThanEntireStreamWhenStreamLengthIsLessThanZipHeaderLength()
throws IOException {
try (ZipHeaderPeekInputStream in = new ZipHeaderPeekInputStream(
new ByteArrayInputStream(new byte[] { 10 }))) {
byte[] bytes = new byte[8];
assertThat(in.read(bytes)).isEqualTo(1);
assertThat(bytes).containsExactly(10, 0, 0, 0, 0, 0, 0, 0);
}
}
@Test
public void readMoreThanEntireStreamWhenStreamLengthIsSameAsHeaderLength()
throws IOException {
try (ZipHeaderPeekInputStream in = new ZipHeaderPeekInputStream(
new ByteArrayInputStream(new byte[] { 1, 2, 3, 4 }))) {
byte[] bytes = new byte[8];
assertThat(in.read(bytes)).isEqualTo(4);
assertThat(bytes).containsExactly(1, 2, 3, 4, 0, 0, 0, 0);
}
}
@Test
public void readMoreThanEntireStreamWhenStreamLengthIsZero() throws IOException {
try (ZipHeaderPeekInputStream in = new ZipHeaderPeekInputStream(
new ByteArrayInputStream(new byte[0]))) {
byte[] bytes = new byte[8];
assertThat(in.read(bytes)).isEqualTo(-1);
assertThat(bytes).containsExactly(0, 0, 0, 0, 0, 0, 0, 0);
}
}
}