diff --git a/README.md b/README.md index f87d59e..85e537b 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ extract all archive types in the same way!
archives are able to mount as fuse also using [vavi-nio-file-archive](https://github.com/umjammer/vavi-apps-fuse/tree/master/vavi-nio-file-archive) and [vavi-net-fuse](https://github.com/umjammer/vavi-apps-fuse/tree/master/vavi-net-fuse) -## Status +### Status | name | mathod | read | write | comment | library | |----------|-----------|------|--------|---------|-------------------------------------------------------------------------| @@ -40,6 +40,10 @@ and [vavi-net-fuse](https://github.com/umjammer/vavi-apps-fuse/tree/master/vavi- * chosen as spi +## Install + + * [maven](https://jitpack.io/#umjammer/vavi-util-archive) + ## Usage ### archive extraction @@ -58,8 +62,9 @@ and [vavi-net-fuse](https://github.com/umjammer/vavi-apps-fuse/tree/master/vavi- InputStream compressed = Archives.getInputStream(Paths.get("foo/bar.tar.bz").toFile()); Files.copy(compressed, Paths.get("foo/bar.tar")); ``` +## References -## License +### License * [Giant Java Tree/cpio](http://www.gjt.org/servlets/JCVSlet/list/gjt/org/gjt/archive/cpio) ... Unknown * [Giant Java Tree/rpm](http://www.gjt.org/servlets/JCVSlet/list/gjt/org/gjt/archive/rpm) ... Unknown @@ -68,7 +73,7 @@ and [vavi-net-fuse](https://github.com/umjammer/vavi-apps-fuse/tree/master/vavi- ## TODO - * registory like IIORegistory + * registry like IIORegistry * [commons-vfs](https://commons.apache.org/proper/commons-vfs/) * [truevfs](https://github.com/christian-schlichtherle/truevfs) * ~~apache commons-compress~~ diff --git a/pom.xml b/pom.xml index 908ad5e..ddb317e 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ vavi vavi-util-archive - 1.1.6 + 1.1.7 Vavi Archiving SPI https://github.com/umjammer/vavi-util-archive diff --git a/src/main/java/vavi/util/archive/Archives.java b/src/main/java/vavi/util/archive/Archives.java index 30871db..944c68d 100644 --- a/src/main/java/vavi/util/archive/Archives.java +++ b/src/main/java/vavi/util/archive/Archives.java @@ -44,29 +44,34 @@ private Archives() { /** get an archiving stream */ public static InputStream getInputStream(File file) throws IOException { - return getInputStream(Files.newInputStream(file.toPath())); + return getInputStream(new BufferedInputStream(Files.newInputStream(file.toPath()))); } /** get an archiving stream */ public static InputStream getInputStream(Path path) throws IOException { - return getInputStream(Files.newInputStream(path)); + return getInputStream(new BufferedInputStream(Files.newInputStream(path))); } - /** get an archiving stream */ + /** + * Gets an archiving stream. + * @param is mark must be supported + * @return suitable compression stream for the input or the given input stream if no suitable compression not found + */ public static InputStream getInputStream(InputStream is) throws IOException { - InputStream bis = new BufferedInputStream(is); + if (!is.markSupported()) + throw new IllegalArgumentException("argument must be supported mark"); for (InputStreamSpi inputStreamSpi : inputStreamSpis) { -logger.log(TRACE, "inputStreamSpi: " + inputStreamSpi.getClass().getSimpleName()); - if (inputStreamSpi.canExpandInput(bis)) { +logger.log(TRACE, "inputStreamSpi: " + inputStreamSpi.getClass().getSimpleName() + ", available: " + is.available()); + if (inputStreamSpi.canExpandInput(is)) { InputStream inputStream = inputStreamSpi.createInputStreamInstance(); -logger.log(DEBUG, "inputStream: " + inputStream.getClass()); +logger.log(DEBUG, "inputStream: " + inputStream.getClass() + ", available: " + is.available()); return inputStream; } } -logger.log(DEBUG, "no suitable spi found, use default stream"); - return bis; +logger.log(DEBUG, "no suitable spi found, use default stream, available: " + is.available()); + return is; } /** diff --git a/src/main/java/vavi/util/archive/tar/TarInputStreamSpi.java b/src/main/java/vavi/util/archive/tar/TarInputStreamSpi.java index 7e90657..c528360 100644 --- a/src/main/java/vavi/util/archive/tar/TarInputStreamSpi.java +++ b/src/main/java/vavi/util/archive/tar/TarInputStreamSpi.java @@ -77,7 +77,7 @@ public boolean canExpandInput(Object target) throws IOException { } is.reset(); -logger.log(Level.DEBUG, "tar magic:\n" + StringUtil.getDump(b)); +logger.log(Level.TRACE, "tar magic:\n" + StringUtil.getDump(b)); return "ustar".equals(new String(b, StandardCharsets.ISO_8859_1)) || (b[0] == 0x00 && // TODO magic 無い奴がいる b[1] == 0x00 && diff --git a/src/test/java/vavi/util/archive/ArchivesTest.java b/src/test/java/vavi/util/archive/ArchivesTest.java index 58dec70..05ce6ac 100644 --- a/src/test/java/vavi/util/archive/ArchivesTest.java +++ b/src/test/java/vavi/util/archive/ArchivesTest.java @@ -9,6 +9,7 @@ import java.util.Arrays; import java.util.stream.Stream; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -86,4 +87,16 @@ void test3() throws Exception { assertTrue(Arrays.asList(suffixes).contains("zip")); assertFalse(Arrays.asList(suffixes).contains("Z")); // TODO just check the logic, not semantics (means .Z may be included by some compression type) } + + @Test + @DisplayName("when no suitable spi is found, available should not be changed") + void test5() throws Exception { + Path file = Path.of("src/test/resources/test.gca"); + InputStream in = new BufferedInputStream(Files.newInputStream(file)); + int before = in.available(); + InputStream is = Archives.getInputStream(in); + int after = is.available(); +Debug.println("result: " + is.getClass().getName()); + assertEquals(before, after); + } } diff --git a/src/test/resources/logging.properties b/src/test/resources/logging.properties index ea10b68..0767621 100644 --- a/src/test/resources/logging.properties +++ b/src/test/resources/logging.properties @@ -5,3 +5,4 @@ java.util.logging.ConsoleHandler.formatter=vavi.util.logging.VaviFormatter #sun.net.www.protocol.http.HttpURLConnection.level=ALL #vavi.util.level=FINE +#vavi.util.archive.level=ALL