Skip to content

Commit

Permalink
Merge pull request #25 from umjammer/1.1.7
Browse files Browse the repository at this point in the history
1.1.7
  • Loading branch information
umjammer authored Nov 22, 2024
2 parents 4b75f6c + bbc2bca commit ac51bc5
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 14 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extract all archive types in the same way!</br>
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 |
|----------|-----------|------|--------|---------|-------------------------------------------------------------------------|
Expand Down Expand Up @@ -40,6 +40,10 @@ and [vavi-net-fuse](https://github.com/umjammer/vavi-apps-fuse/tree/master/vavi-

<sub>* chosen as spi</sub>

## Install

* [maven](https://jitpack.io/#umjammer/vavi-util-archive)

## Usage

### archive extraction
Expand All @@ -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
Expand All @@ -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~~
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<groupId>vavi</groupId>
<artifactId>vavi-util-archive</artifactId>
<version>1.1.6</version>
<version>1.1.7</version>

<name>Vavi Archiving SPI</name>
<url>https://github.com/umjammer/vavi-util-archive</url>
Expand Down
23 changes: 14 additions & 9 deletions src/main/java/vavi/util/archive/Archives.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/vavi/util/archive/tar/TarInputStreamSpi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/vavi/util/archive/ArchivesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
1 change: 1 addition & 0 deletions src/test/resources/logging.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ac51bc5

Please sign in to comment.