org.apache.commons.vfs2.provider.compressed.CompressedFileFileObject Java Examples

The following examples show how to use org.apache.commons.vfs2.provider.compressed.CompressedFileFileObject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Bzip2TestCase.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
@Test
public void testBZip2() throws IOException {
    final File testResource = getTestResource("bla.txt.bz2");
    try (final FileObject bz2FileObject = VFS.getManager().resolveFile("bz2://" + testResource)) {
        Assert.assertTrue(bz2FileObject.exists());
        Assert.assertTrue(bz2FileObject.isFolder());
        try (final FileObject fileObjectDir = bz2FileObject.resolveFile("bla.txt")) {
            Assert.assertTrue(fileObjectDir.exists());
            Assert.assertTrue(bz2FileObject.isFolder());
            try (final FileObject fileObject = fileObjectDir.resolveFile("bla.txt")) {
                Assert.assertTrue(fileObject.exists());
                Assert.assertFalse(fileObject.isFolder());
                Assert.assertTrue(fileObject.isFile());
                try (final FileContent content = fileObject.getContent()) {
                    Assert.assertEquals(CompressedFileFileObject.SIZE_UNDEFINED, content.getSize());
                    // blows up, Commons Compress?
                    final String string = content.getString(StandardCharsets.UTF_8);
                    Assert.assertEquals(26, string.length());
                    Assert.assertEquals("Hallo, dies ist ein Test.\n", string);
                }
            }
        }
    }
}