| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -144,7 +144,7 @@ public boolean matches(String fileName) { | |||
| 144 | 144 | public ReadableByteChannel createDecompressingChannel(ReadableByteChannel channel) | |
| 145 | 145 | throws IOException { | |
| 146 | 146 | return Channels.newChannel( | |
| 147 | - new BZip2CompressorInputStream(Channels.newInputStream(channel))); | ||
| 147 | + new BZip2CompressorInputStream(Channels.newInputStream(channel), true)); | ||
| 148 | 148 | } | |
| 149 | 149 | }; | |
| 150 | 150 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,6 @@ | |||
| 18 | 18 | ||
| 19 | 19 | import static com.google.cloud.dataflow.sdk.transforms.display.DisplayDataMatchers.hasDisplayItem; | |
| 20 | 20 | import static com.google.cloud.dataflow.sdk.transforms.display.DisplayDataMatchers.includesDisplayDataFrom; | |
| 21 | - | ||
| 22 | 21 | import static org.hamcrest.Matchers.containsString; | |
| 23 | 22 | import static org.hamcrest.Matchers.instanceOf; | |
| 24 | 23 | import static org.hamcrest.Matchers.not; | |
@@ -203,6 +202,38 @@ public void testReadConcatenatedGzip() throws IOException { | |||
| 203 | 202 | p.run(); | |
| 204 | 203 | } | |
| 205 | 204 | ||
| 205 | + /** | ||
| 206 | + * Test a bzip2 file containing multiple streams is correctly decompressed. | ||
| 207 | + * | ||
| 208 | + * <p>A bzip2 file may contain multiple streams and should decompress as the concatenation of | ||
| 209 | + * those streams. | ||
| 210 | + */ | ||
| 211 | + @Test | ||
| 212 | + public void testReadMultiStreamBzip2() throws IOException { | ||
| 213 | + CompressionMode mode = CompressionMode.BZIP2; | ||
| 214 | + byte[] input1 = generateInput(5, 587973); | ||
| 215 | + byte[] input2 = generateInput(5, 387374); | ||
| 216 | + | ||
| 217 | + ByteArrayOutputStream stream1 = new ByteArrayOutputStream(); | ||
| 218 | + try (OutputStream os = getOutputStreamForMode(mode, stream1)) { | ||
| 219 | + os.write(input1); | ||
| 220 | + } | ||
| 221 | + | ||
| 222 | + ByteArrayOutputStream stream2 = new ByteArrayOutputStream(); | ||
| 223 | + try (OutputStream os = getOutputStreamForMode(mode, stream2)) { | ||
| 224 | + os.write(input2); | ||
| 225 | + } | ||
| 226 | + | ||
| 227 | + File tmpFile = tmpFolder.newFile(); | ||
| 228 | + try (OutputStream os = new FileOutputStream(tmpFile)) { | ||
| 229 | + os.write(stream1.toByteArray()); | ||
| 230 | + os.write(stream2.toByteArray()); | ||
| 231 | + } | ||
| 232 | + | ||
| 233 | + byte[] output = Bytes.concat(input1, input2); | ||
| 234 | + verifyReadContents(output, tmpFile, mode); | ||
| 235 | + } | ||
| 236 | + | ||
| 206 | 237 | /** | |
| 207 | 238 | * Test reading empty input with bzip2. | |
| 208 | 239 | */ | |
@@ -416,7 +447,14 @@ public void populateDisplayData(DisplayData.Builder builder) { | |||
| 416 | 447 | */ | |
| 417 | 448 | private byte[] generateInput(int size) { | |
| 418 | 449 | // Arbitrary but fixed seed | |
| 419 | - Random random = new Random(285930); | ||
| 450 | + return generateInput(size, 285930); | ||
| 451 | + } | ||
| 452 | + | ||
| 453 | + /** | ||
| 454 | + * Generate byte array of given size. | ||
| 455 | + */ | ||
| 456 | + private byte[] generateInput(int size, int seed) { | ||
| 457 | + Random random = new Random(seed); | ||
| 420 | 458 | byte[] buff = new byte[size]; | |
| 421 | 459 | random.nextBytes(buff); | |
| 422 | 460 | return buff; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments