Skip to content

Commit

Permalink
Merge 371a89e into 04899e4
Browse files Browse the repository at this point in the history
  • Loading branch information
bjchambers committed Aug 1, 2017
2 parents 04899e4 + 371a89e commit 096c6e8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public boolean matches(String fileName) {
public ReadableByteChannel createDecompressingChannel(ReadableByteChannel channel)
throws IOException {
return Channels.newChannel(
new BZip2CompressorInputStream(Channels.newInputStream(channel)));
new BZip2CompressorInputStream(Channels.newInputStream(channel), true));
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,39 @@ public void testReadConcatenatedGzip() throws IOException {
p.run();
}

/**
* Test a bzip2 file containing multiple streams is correctly decompressed.
*
* <p>A bzip2 file may contain multiple streams and should decompress as the concatenation of
* those streams.
*/
@Test
@Category(NeedsRunner.class)
public void testReadMultiStreamBzip2() throws IOException {
CompressionMode mode = CompressionMode.BZIP2;
byte[] input1 = generateInput(5, 587973);
byte[] input2 = generateInput(5, 387374);

ByteArrayOutputStream stream1 = new ByteArrayOutputStream();
try (OutputStream os = getOutputStreamForMode(mode, stream1)) {
os.write(input1);
}

ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
try (OutputStream os = getOutputStreamForMode(mode, stream2)) {
os.write(input2);
}

File tmpFile = tmpFolder.newFile();
try (OutputStream os = new FileOutputStream(tmpFile)) {
os.write(stream1.toByteArray());
os.write(stream2.toByteArray());
}

byte[] output = Bytes.concat(input1, input2);
verifyReadContents(output, tmpFile, mode);
}

/**
* Test reading empty input with bzip2.
*/
Expand Down Expand Up @@ -470,7 +503,16 @@ public void populateDisplayData(DisplayData.Builder builder) {
*/
private byte[] generateInput(int size) {
// Arbitrary but fixed seed
Random random = new Random(285930);
return generateInput(size, 285930);
}


/**
* Generate byte array of given size.
*/
private byte[] generateInput(int size, int seed) {
// Arbitrary but fixed seed
Random random = new Random(seed);
byte[] buff = new byte[size];
random.nextBytes(buff);
return buff;
Expand Down

0 comments on commit 096c6e8

Please sign in to comment.