diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 73823f2..ee6ba29 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -30,20 +30,11 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 - with: - # We must fetch at least the immediate parents so that if this is - # a pull request then we can checkout the head. - fetch-depth: 2 - - # If this run was triggered by a pull request event, then checkout - # the head of the pull request instead of the merge commit. - - run: git checkout HEAD - if: ${{ github.event_name == 'pull_request' }} + uses: actions/checkout@v3 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v1 + uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -53,8 +44,12 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v1 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: maven # ℹ️ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -66,6 +61,8 @@ jobs: #- run: | # make bootstrap # make release + - name: Build with Maven + run: mvn -B package --file pom.xml -Dmaven.test.skip=true - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 0ed6942..ecc8078 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -1,7 +1,7 @@ # This workflow will build a Java project with Maven # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven -name: Java CI with Maven +name: Java CI on: push: @@ -15,12 +15,19 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v2 - with: - java-version: '8' - distribution: 'adopt' - cache: maven - - name: Build with Maven - run: mvn -B package --file pom.xml + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Check w/o SNAPSHOT when "bump version" + if: ${{ contains(github.event.head_commit.message, 'bump version') }} + run: grep "" pom.xml | head -1 | grep -v SNAPSHOT + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + + - name: Build with Maven + run: mvn -B package --file pom.xml diff --git a/README.md b/README.md index a82f351..b60f821 100644 --- a/README.md +++ b/README.md @@ -1,53 +1,64 @@ [![](https://jitpack.io/v/umjammer/vavi-util-archive.svg)](https://jitpack.io/#umjammer/vavi-util-archive) [![Java CI with Maven](https://github.com/umjammer/vavi-util-archive-sandbox/workflows/Java%20CI%20with%20Maven/badge.svg)](https://github.com/umjammer/vavi-util-archive-sandbox/actions) [![CodeQL](https://github.com/umjammer/vavi-util-archive/workflows/CodeQL/badge.svg)](https://github.com/umjammer/vavi-util-archive-sandbox/actions) -![Java](https://img.shields.io/badge/Java-8-b07219) +![Java](https://img.shields.io/badge/Java-17-b07219) # vavi-util-archive 🌏 Extract the world! +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 -| name | mathod | read | write | comment | library | -|----------|-----------|--------|--------|---------|-------------------------------------------------------------------------| -| binhex | archiving | ✅ | - | | [binhex](https://github.com/umjammer/JBinHex) | -| bzip2 | archiving | ✅ | - | | [commons-compress](https://commons.apache.org/proper/commons-compress/) | -| cab | archiving | ✅ | - | | [dorkbox](https://github.com/umjammer/CabParser) | -| gca | archiving | - | - | win only | native | -| gca | archiving | - | - | | shell | -| gzip | archiving | ✅ | - | | jdk | -| lha | archiving | ✅ | - | | [lha](https://github.com/umjammer/jlha) | -| rar | archiving | - | - | win only | native | -| rar | archiving | - | - | | shell | -| rar | archiving | ✅ | - | | [java-unrar](https://github.com/umjammer/java-unrar) | -| rar | archiving | ✅ | - | no rar5 | [junrar](https://github.com/junrar/junrar) | -| sevenzip | archiving | ✅ | - | 7z only | [commons-compress](https://commons.apache.org/proper/commons-compress/) | -| sevenzip | archiving | - | - | | native | -| stuffit | archiving | | - | | native | -| tar | archiving | ✅ | - | | [commons-compress](https://commons.apache.org/proper/commons-compress/) | -| tar | stream | ✅ | - | | [commons-compress](https://commons.apache.org/proper/commons-compress/) | -| zip | archiving | ✅ | - | | jdk | -| zip | archiving | ✅ | - | | [ant](https://ant.apache.org/) | -| cpio | stream | 🚧 | - | | gjt | -| lzma | stream | 🚧 | - | | [p7zip](https://p7zip.sourceforge.net/) | -| rpm | archiving | 🚧 | - | | gjt | -| apache | archiving | ✅ | - | multi | [commons-compress](https://commons.apache.org/proper/commons-compress/) | +| name | mathod | read | write | comment | library | +|----------|-----------|------|--------|---------|-------------------------------------------------------------------------| +| binhex | archiving | ✅ | - | | [binhex](https://github.com/umjammer/JBinHex) | +| bzip2 | archiving | ✅ | - | | [commons-compress](https://commons.apache.org/proper/commons-compress/) | +| cab | archiving | ✅ | - | | [dorkbox](https://github.com/umjammer/CabParser) | +| gca | archiving | - | - | win only | native | +| gca | archiving | - | - | | shell | +| gzip | archiving | ✅ | - | | jdk | +| lha | archiving | ✅ | - | | [lha](https://github.com/umjammer/jlha) | +| rar | archiving | - | - | win only | native | +| rar | archiving | - | - | | shell | +| rar | archiving | ✅* | - | | [java-unrar](https://github.com/umjammer/java-unrar) | +| rar | archiving | ✅ | - | no rar5 | [junrar](https://github.com/junrar/junrar) | +| sevenzip | archiving | ✅ | - | 7z only | [commons-compress](https://commons.apache.org/proper/commons-compress/) | +| sevenzip | archiving | - | - | | native | +| stuffit | archiving | | - | | native | +| tar | archiving | ✅ | - | | [commons-compress](https://commons.apache.org/proper/commons-compress/) | +| tar | stream | ✅ | - | | [commons-compress](https://commons.apache.org/proper/commons-compress/) | +| zip | archiving | ✅* | - | | jdk | +| zip | archiving | ✅ | - | | [ant](https://ant.apache.org/) | +| cpio | stream | 🚧 | - | | gjt | +| lzma | stream | 🚧 | - | | [p7zip](https://p7zip.sourceforge.net/) | +| rpm | archiving | 🚧 | - | | gjt | +| apache | archiving | ✅ | - | multi | [commons-compress](https://commons.apache.org/proper/commons-compress/) | + +* chosen as spi ## Usage +### archive extraction + ```java - Path inZip = Paths.get("foo/bar.zip"); + Archive archive = Archives.getArchive(Paths.get("foo/bar.rar").toFile()); Path outDir = Paths.get("foo/bar"); - Archive archive = Archives.getArchive(inZip.toFile()); for (Entry entry : archive.entries()) { Files.copy(archive.getInputStream(entry), outDir.resolve(entry.getName())); } ``` +### archive decompression + +```java + InputStream compressed = Archives.getInputStream(Paths.get("foo/bar.tar.bz").toFile()); + Files.copy(compressed, Paths.get("foo/bar.tar")); +``` + ## License * [Giant Java Tree/cpio](http://www.gjt.org/servlets/JCVSlet/list/gjt/org/gjt/archive/cpio) ... Unknown @@ -57,17 +68,22 @@ and [vavi-net-fuse](https://github.com/umjammer/vavi-apps-fuse/tree/master/vavi- ## TODO + * registory like IIORegistory * [commons-vfs](https://commons.apache.org/proper/commons-vfs/) * [truevfs](https://github.com/christian-schlichtherle/truevfs) * ~~apache commons-compress~~ * https://github.com/ZIPmagic/ZIPmagic/tree/master/StuffIt%20SDK * ~~https://github.com/cstroe/SevenZip-Java~~ (use 7zip-jbinding) * write! - * ~~jar5~~ (done by 7zip-jbinding) + * ~~rar5~~ (done by 7zip-jbinding) * ~~[@marcusvoltolim]((https://github.com/marcusvoltolim/file-processor#readme)) says [sevenzipjbinding](https://github.com/borisbrodski/sevenzipjbinding) can deal rar5 ???~~ * it's [true](https://github.com/borisbrodski/sevenzipjbinding/issues/19#issuecomment-578636772) * unar v1.10.7 ... ok * 7zip 17.04 ... ok * https://github.com/prog-ai/ArchivR (wip) * ~~https://github.com/Diab1o/java-7z-archiver ... yet another pure java 7zip implementation?~~ (done) - * where is my jna 7z implementation? (in the crashed hdd?) \ No newline at end of file + * where is my jna 7z implementation? (in the crashed hdd?) + * binary things ... gca.exe -> dll -> 64bit -> mach-O + winelib -> dylib + * https://github.com/gitGNU/objconv + * https://github.com/jakeajames/dylibify + * https://github.com/hasherezade/exe_to_dll \ No newline at end of file diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 0000000..efde7bf --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,2 @@ +jdk: + - openjdk17 diff --git a/local.properties.sample b/local.properties.sample new file mode 100644 index 0000000..00c5df8 --- /dev/null +++ b/local.properties.sample @@ -0,0 +1,2 @@ +#archive.zip.file1=/foo/bar.zip +#archive.rar.file=/foo/bar.rar diff --git a/pom.xml b/pom.xml index 0bee919..292a49f 100644 --- a/pom.xml +++ b/pom.xml @@ -8,15 +8,11 @@ vavi vavi-util-archive - 1.1.1 + 1.1.2 - Vavi Archiving API + Vavi Archiving SPI https://github.com/umjammer/vavi-util-archive - -TOOD - - jni on maven - registory like IIORegistory + Vavi Archiving SPI and implementations https://github.com/umjammer/vavi-util-archive @@ -29,11 +25,9 @@ TOOD org.apache.maven.plugins maven-compiler-plugin - 3.10.1 + 3.11.0 - 1.8 - 1.8 - UTF-8 + 17 @@ -56,7 +50,7 @@ TOOD org.apache.maven.plugins maven-surefire-plugin - 3.0.0-M7 + 3.2.2 -Djava.util.logging.config.file=src/test/resources/logging.properties false @@ -77,7 +71,7 @@ TOOD org.junit junit-bom - 5.9.0 + 5.10.1 pom import @@ -88,12 +82,12 @@ TOOD com.github.umjammer vavi-commons - 1.1.7 + 1.1.10 com.github.umjammer jlha - 0.0.9 + 0.0.10 com.github.umjammer @@ -111,15 +105,14 @@ TOOD 1.9 - - com.github.umjammer + com.github.umjammer java-unrar 1.7.1 com.github.junrar junrar - 7.5.3 + 7.5.4 com.github.umjammer @@ -129,7 +122,7 @@ TOOD org.apache.ant ant - 1.10.12 + 1.10.13 @@ -160,4 +153,36 @@ TOOD test + + + + + list + + + + + org.apache.maven.plugins + maven-antrun-plugin + 3.1.0 + + run + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/vavi/util/archive/Archives.java b/src/main/java/vavi/util/archive/Archives.java index e7b348b..7b5d055 100644 --- a/src/main/java/vavi/util/archive/Archives.java +++ b/src/main/java/vavi/util/archive/Archives.java @@ -21,7 +21,6 @@ import java.util.logging.Level; import vavi.util.Debug; -import vavi.util.StringUtil; import vavi.util.archive.spi.ArchiveSpi; import vavi.util.archive.spi.InputStreamSpi; @@ -52,7 +51,7 @@ public static InputStream getInputStream(InputStream is) throws IOException { InputStream bis = new BufferedInputStream(is); for (InputStreamSpi inputStreamSpi : inputStreamSpis) { -Debug.println(Level.FINE, "inputStreamSpi: " + StringUtil.getClassName(inputStreamSpi.getClass())); +Debug.println(Level.FINE, "inputStreamSpi: " + inputStreamSpi.getClass().getSimpleName()); if (inputStreamSpi.canExpandInput(bis)) { InputStream inputStream = inputStreamSpi.createInputStreamInstance(); Debug.println(Level.FINE, "inputStream: " + inputStream.getClass()); diff --git a/src/main/java/vavi/util/archive/ArchivesMain.java b/src/main/java/vavi/util/archive/ArchivesMain.java new file mode 100644 index 0000000..d6918e6 --- /dev/null +++ b/src/main/java/vavi/util/archive/ArchivesMain.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2022 by Naohide Sano, All rights reserved. + * + * Programmed by Naohide Sano + */ + +package vavi.util.archive; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.time.Instant; + + +/** + * ArchivesMain. + * + * @author Naohide Sano (nsano) + * @version 0.00 2022-11-29 nsano initial version
+ */ +public class ArchivesMain { + + /** + * @param args 0: archive file + */ + public static void main(String[] args) throws Exception { + Path path = Paths.get(args[0]); + Archive archive = Archives.getArchive(path.toFile()); + ArchivesMain app = new ArchivesMain(); + System.out.println(app.toHtml(archive)); + } + + String toHtml(Archive archive) { + StringBuilder sb = new StringBuilder(); + sb.append(""); + sb.append("\n"); + sb.append(""); + sb.append(""); + sb.append(""); + sb.append(""); + sb.append(""); + sb.append(""); + sb.append("\n"); + for (Entry entry : archive.entries()) { + sb.append(toHtml(entry)); + sb.append("\n"); + } + sb.append("
"); + sb.append("name"); + sb.append(""); + sb.append("lastModified"); + sb.append(""); + sb.append("size"); + sb.append(""); + sb.append("type"); + sb.append("
"); + return sb.toString(); + } + + String toHtml(Entry entry) { + StringBuilder sb = new StringBuilder(); + sb.append(""); + sb.append(""); + sb.append(entry.getName()); + sb.append(""); + sb.append(""); + sb.append(Instant.ofEpochMilli(entry.getTime())); + sb.append(""); + sb.append(""); + sb.append(entry.getSize()); + sb.append(""); + sb.append(""); + sb.append(entry.getName()); + sb.append(""); + sb.append(""); + return sb.toString(); + } +} diff --git a/src/main/java/vavi/util/archive/Entry.java b/src/main/java/vavi/util/archive/Entry.java index 2b23ca4..292763f 100644 --- a/src/main/java/vavi/util/archive/Entry.java +++ b/src/main/java/vavi/util/archive/Entry.java @@ -34,72 +34,72 @@ public interface Entry extends Cloneable { long getCompressedSize(); /** - * 圧縮解除されたエントリデータの CRC-32 チェックサムを返します。 + * Returns the CRC-32 checksum of the uncompressed entry data. */ long getCrc(); /** - * エントリの補足フィールドデータを返します。 + * Returns the extra field data for the entry. */ Object getExtra(); /** - * エントリの圧縮メソッドを返します。 + * Returns the compression method of the entry. */ int getMethod(); /** - * エントリの名前を返します。 + * Returns the name of the entry. */ String getName(); /** - * エントリデータの圧縮解除時のサイズを返します。 + * Returns the uncompressed size of the entry data. */ long getSize(); /** - * エントリの修正時間を返します。 + * Returns the last modification time of the entry. */ long getTime(); /** - * これがディレクトリエントリである場合に、true を返します。 + * Returns true if this is a directory entry. */ boolean isDirectory(); /** - * エントリに任意指定のコメント文字列を設定します。 + * Sets the optional comment string for the entry. */ void setComment(String comment); /** - * 圧縮されたエントリデータのサイズを設定します。 + * Sets the size of the compressed entry data. */ void setCompressedSize(long csize); /** - * 圧縮解除されたエントリデータの CRC-32 チェックサムを設定します。 + * Sets the CRC-32 checksum of the uncompressed entry data. */ void setCrc(long crc); /** - * エントリに任意指定の補足フィールドデータを設定します。 + * Sets the optional extra field data for the entry. */ void setExtra(Object extra); /** - * エントリの圧縮メソッドを設定します。 + * Sets the compression method for the entry. */ void setMethod(int method); /** - * エントリデータの圧縮解除時のサイズを設定します。 + * Sets the uncompressed size of the entry data. */ void setSize(long size); /** - * エントリの修正時間を設定します。 + * Sets the last modification time of the entry. */ void setTime(long time); } diff --git a/src/main/java/vavi/util/archive/InputStreamSupport.java b/src/main/java/vavi/util/archive/InputStreamSupport.java index 47419e7..23d073d 100644 --- a/src/main/java/vavi/util/archive/InputStreamSupport.java +++ b/src/main/java/vavi/util/archive/InputStreamSupport.java @@ -12,6 +12,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; +import java.util.logging.Level; import vavi.util.Debug; @@ -34,7 +35,7 @@ protected InputStreamSupport() {} protected InputStreamSupport(InputStream is) throws IOException { Path temp = Files.createTempFile("vavi.util.archive.InputStreamSupport@" + is.hashCode(), ".inputStream"); Runtime.getRuntime().addShutdownHook(new Thread(() -> { -Debug.println("shutdownHook: rm: " + temp); +Debug.println(Level.FINE, "shutdownHook: rm: " + temp); try { Files.delete(temp); } catch (IOException e) { diff --git a/src/main/java/vavi/util/archive/apache/ApacheCommonsArchive.java b/src/main/java/vavi/util/archive/apache/ApacheCommonsArchive.java index 1e93650..8962e93 100644 --- a/src/main/java/vavi/util/archive/apache/ApacheCommonsArchive.java +++ b/src/main/java/vavi/util/archive/apache/ApacheCommonsArchive.java @@ -29,7 +29,7 @@ /** - * The wrapper for Apache commons compress. + * The wrapper for apache commons-compress. * * @author Naohide Sano (umjammer) * @version 0.00 2021/11/16 umjammer initial version
diff --git a/src/main/java/vavi/util/archive/apache/ApacheCommonsArchiveSpi.java b/src/main/java/vavi/util/archive/apache/ApacheCommonsArchiveSpi.java index 788fa09..aea77dd 100644 --- a/src/main/java/vavi/util/archive/apache/ApacheCommonsArchiveSpi.java +++ b/src/main/java/vavi/util/archive/apache/ApacheCommonsArchiveSpi.java @@ -29,7 +29,7 @@ /** - * The SPI for archives using Apache commons compress. + * The service provider for archives using apache commons-compress. * * @author Naohide Sano (umjammer) * @version 0.00 2021/11/16 umjammer initial version
diff --git a/src/main/java/vavi/util/archive/apache/ApacheEntry.java b/src/main/java/vavi/util/archive/apache/ApacheEntry.java index 35775a4..a1f5cf8 100644 --- a/src/main/java/vavi/util/archive/apache/ApacheEntry.java +++ b/src/main/java/vavi/util/archive/apache/ApacheEntry.java @@ -12,7 +12,7 @@ /** - * ApacheEntry. + * ApacheEntry represents an archive entry for apache-commons. * * @author Naohide Sano (umjammer) * @version 0.00 2021/11/17 umjammer initial version
diff --git a/src/main/java/vavi/util/archive/binhex/BinhexInputStreamSpi.java b/src/main/java/vavi/util/archive/binhex/BinhexInputStreamSpi.java index f6a6f6b..932a5d3 100644 --- a/src/main/java/vavi/util/archive/binhex/BinhexInputStreamSpi.java +++ b/src/main/java/vavi/util/archive/binhex/BinhexInputStreamSpi.java @@ -35,9 +35,9 @@ public class BinhexInputStreamSpi implements InputStreamSpi { private static final int L = COMMENT.length(); /** - * checks extractable or not. * @param target currently accepts {#link InputStream} only */ + @Override public boolean canExpandInput(Object target) throws IOException { if (!(target instanceof InputStream)) { diff --git a/src/main/java/vavi/util/archive/bzip2/BZip2InputStreamSpi.java b/src/main/java/vavi/util/archive/bzip2/BZip2InputStreamSpi.java index 883546f..329645a 100644 --- a/src/main/java/vavi/util/archive/bzip2/BZip2InputStreamSpi.java +++ b/src/main/java/vavi/util/archive/bzip2/BZip2InputStreamSpi.java @@ -16,7 +16,7 @@ /** - * BZip2 アーカイブを処理するサービスプロバイダです. + * The service provider for BZip2 archive. * * @author Naohide Sano (nsano) * @version 0.00 040105 nsano initial version
@@ -27,9 +27,9 @@ public class BZip2InputStreamSpi implements InputStreamSpi { private Object target; /** - * 伸張できるかどうか調べます. - * @param target 今のところ InputStream しか受け付けません + * @param target currently accepts only InputStream */ + @Override public boolean canExpandInput(Object target) throws IOException { if (!(target instanceof InputStream)) { @@ -58,7 +58,7 @@ public boolean canExpandInput(Object target) throws IOException { b[2] == (byte) 0x68; } - /** */ + @Override public InputStream createInputStreamInstance() throws IOException { Debug.println(target); diff --git a/src/main/java/vavi/util/archive/cab/CabArchiveSpi.java b/src/main/java/vavi/util/archive/cab/CabArchiveSpi.java index 9b08750..5f51b86 100644 --- a/src/main/java/vavi/util/archive/cab/CabArchiveSpi.java +++ b/src/main/java/vavi/util/archive/cab/CabArchiveSpi.java @@ -13,7 +13,7 @@ /** - * CAB アーカイブを処理するサービスプロバイダです. + * The service provider for CAB archive. * * @author Naohide Sano (nsano) * @version 0.00 041002 nsano initial version
diff --git a/src/main/java/vavi/util/archive/cab/DorkboxCabArchive.java b/src/main/java/vavi/util/archive/cab/DorkboxCabArchive.java index 864c481..3cdfeb9 100644 --- a/src/main/java/vavi/util/archive/cab/DorkboxCabArchive.java +++ b/src/main/java/vavi/util/archive/cab/DorkboxCabArchive.java @@ -22,7 +22,7 @@ /** - * DorkboxCabArchive. + * Represents CAB archive using a library Dorkbox. * * @author Naohide Sano (nsano) * @version 0.00 040929 nsano initial version
diff --git a/src/main/java/vavi/util/archive/cab/DorkboxCabArchiveSpi.java b/src/main/java/vavi/util/archive/cab/DorkboxCabArchiveSpi.java index dd030dc..0a9cabe 100644 --- a/src/main/java/vavi/util/archive/cab/DorkboxCabArchiveSpi.java +++ b/src/main/java/vavi/util/archive/cab/DorkboxCabArchiveSpi.java @@ -17,7 +17,7 @@ /** - * CAB アーカイブを処理するサービスプロバイダです. + * The service provider for CAB archive. * * @author Naohide Sano (nsano) * @version 0.00 041002 nsano initial version
@@ -25,9 +25,9 @@ public class DorkboxCabArchiveSpi extends CabArchiveSpi { /** - * 解凍できるかどうか調べます. - * @param target 今のところ File, InputStream しか受け付けません + * @param target currently accepts File and InputStream. */ + @Override public boolean canExtractInput(Object target) throws IOException { if (!isSupported(target)) { return false; @@ -53,9 +53,9 @@ public boolean canExtractInput(Object target) throws IOException { /** * @param obj {@link File} and {@link InputStream} are supported. - * @param env * @throws IllegalArgumentException unsupported type is specified to obj. */ + @Override public Archive createArchiveInstance(Object obj, Map env) throws IOException { if (obj instanceof File) { return new DorkboxCabArchive((File) obj); diff --git a/src/main/java/vavi/util/archive/cab/DorkboxCabEntry.java b/src/main/java/vavi/util/archive/cab/DorkboxCabEntry.java index 6cc673e..182fafa 100644 --- a/src/main/java/vavi/util/archive/cab/DorkboxCabEntry.java +++ b/src/main/java/vavi/util/archive/cab/DorkboxCabEntry.java @@ -15,7 +15,7 @@ /** - * DorkboxCabEntry. + * DorkboxCabEntry represents a CAB archive entry using a library Dorkbox. * * @author Naohide Sano (nsano) * @version 0.00 120216 nsano initial version
diff --git a/src/main/java/vavi/util/archive/gca/GcaArchiveSpi.java b/src/main/java/vavi/util/archive/gca/GcaArchiveSpi.java index 7789f6e..4e64aed 100644 --- a/src/main/java/vavi/util/archive/gca/GcaArchiveSpi.java +++ b/src/main/java/vavi/util/archive/gca/GcaArchiveSpi.java @@ -18,7 +18,7 @@ /** - * GCA アーカイブを処理するサービスプロバイダです. + * The service provider for GCA archive. * * @author Naohide Sano (nsano) * @version 0.00 030128 nsano initial version
@@ -27,9 +27,9 @@ public abstract class GcaArchiveSpi implements ArchiveSpi { /** - * 解凍できるかどうか調べます. - * @param target 今のところ File しか受け付けません + * @param target currently accepts only File */ + @Override public boolean canExtractInput(Object target) throws IOException { if (!(target instanceof File)) { @@ -55,7 +55,7 @@ public boolean canExtractInput(Object target) throws IOException { b[2] == 'A'; } - /** */ + @Override public abstract Archive createArchiveInstance(Object obj, Map env) throws IOException; @Override diff --git a/src/main/java/vavi/util/archive/gca/NativeGcaArchive.java b/src/main/java/vavi/util/archive/gca/NativeGcaArchive.java index 028c058..7c61113 100644 --- a/src/main/java/vavi/util/archive/gca/NativeGcaArchive.java +++ b/src/main/java/vavi/util/archive/gca/NativeGcaArchive.java @@ -25,7 +25,7 @@ /** - * UnGCA32.dll のラッパークラスです。 + * NativeGcaArchive repesents GCA archive wrapping UnGCA32.dll. * * @author Naohide Sano (nsano) * @version 0.00 030226 nsano initial version
@@ -64,25 +64,19 @@ public NativeGcaArchive(File file) throws IOException { } } - /** - * ファイルを閉じます。 - */ + @Override public void close() throws IOException { closeArchive(); } - /** - * ファイルエントリの列挙を返します。 - */ + @Override public Entry[] entries() { Entry[] entries = new Entry[this.entries.size()]; this.entries.toArray(entries); return entries; } - /** - * 指定された名前の ZIP ファイルエントリを返します。 - */ + @Override public Entry getEntry(String name) { for (Entry entry : entries) { if (entry.getName().equals(name)) { @@ -96,10 +90,9 @@ public Entry getEntry(String name) { private static final String commandLineBase = "e \"{0}\" \"{1}\" \"{2}\""; /** - * 指定された ファイルエントリの内容を読み込むための入力ストリームを - * 返します。 * TODO password, keyfile */ + @Override public InputStream getInputStream(Entry entry) throws IOException { String commandLine = MessageFormat.format(commandLineBase, @@ -119,70 +112,66 @@ public InputStream getInputStream(Entry entry) throws IOException { } } - /** - * ファイルのパス名を返します。 - */ + @Override public String getName() { return file.getPath(); } - /** - * ファイル中のエントリの数を返します。 - */ + @Override public int size() { return entries.size(); } - // for Native method ------------------------------------------------------ + // for Native method ---- - /** インスタンス識別子 */ + /** instance id for dll */ private int instance; - /** getFileName がうまくいかんから代用 */ + /** getFileName() doesn't work well, so this is alternative */ private String currentFilename; - // インターフェース + // interface - /** コマンド文字列を与えて,各種の書庫操作を行います。 */ + /** processes each functionality by a command string */ private native void exec(String command) throws IOException; - /** バージョンを返します。 */ + /** gets version */ protected native int getVersion(); - /** 動作中か否かを得ます。 */ + /** tells is running or not */ private native boolean isRunning(); - /** 指定ファイルが書庫として正しいかどうかを返します。 */ + /** checks the archive is valid or not */ private native boolean checkArchive(String filename, int mode); - /** 指定された書庫ファイルに格納されているファイル数を得ます。 */ + /** gets entries count in an archive */ private native int getFileCount(String filename) throws IOException; - /** 書庫ファイルを開きます。 */ + /** open an archive */ private native void openArchive(String filename, int mode) throws IOException; - /** 書庫ファイルを閉じます。 */ + /** close the archive */ private native void closeArchive() throws IOException; - /** 最初の格納ファイルの情報を得ます。 */ + /** gets the first entry */ private native boolean findFirst(String key) throws IOException; - /** 2 番目以降の格納ファイルの情報を得ます。 */ + /** gets after 2nd entry */ private native boolean findNext(); - /** 格納ファイルのファイル名を得ます。 */ + /** gets the current entry filename */ private native String getCurrentFileName() throws IOException; - /** 格納ファイルの圧縮法を得ます。 */ + /** gets the current entry archive method */ private native int getCurrentMethod() throws IOException; - /** 格納ファイルのサイズを得ます。 */ + /** gets the current entry original size */ private native long getCurrentOriginalSize() throws IOException; - /** 格納ファイルの圧縮サイズを得ます。 */ + /** gets the current entry compressed size */ private native long getCurrentCompressedSize() throws IOException; - /** 格納ファイルの日付を DOS 形式で得ます。 */ + /** gets the current entry date in DOS format */ private native int getCurrentDate() throws IOException; - /** 格納ファイルの時刻を DOS 形式で得ます。 */ + /** gets the current entry time in DOS format */ private native int getCurrentTime() throws IOException; - /** 格納ファイルのチェックサムを得ます。 */ + /** gets the current entry checksum */ private native long getCurrentCRC() throws IOException; - /** 検索にマッチしたファイルのサイズの合計を得ます。 */ + /** gets a sum of selected entries size */ private native long getSelectedSize() throws IOException; - /** 検索にマッチしたファイルの圧縮サイズの合計を得ます。 */ + /** gets a sum of selected entries compressed size */ private native long getSelectedCompressedSize() throws IOException; - /** 検索にマッチしたファイルの全体の圧縮率を得ます。 */ + /** gets compression ratio of selected entries */ private native int getSelectedRatio() throws IOException; /* */ diff --git a/src/main/java/vavi/util/archive/gca/NativeGcaArchiveSpi.java b/src/main/java/vavi/util/archive/gca/NativeGcaArchiveSpi.java index c315641..1604a86 100644 --- a/src/main/java/vavi/util/archive/gca/NativeGcaArchiveSpi.java +++ b/src/main/java/vavi/util/archive/gca/NativeGcaArchiveSpi.java @@ -14,7 +14,7 @@ /** - * GCA アーカイブを処理するサービスプロバイダです. + * The service provider for GCA archive. * * @author Naohide Sano (nsano) * @version 0.00 030128 nsano initial version
@@ -22,7 +22,7 @@ */ public class NativeGcaArchiveSpi extends GcaArchiveSpi { - /* */ + @Override public Archive createArchiveInstance(Object obj, Map env) throws IOException { return new NativeGcaArchive((File) obj); } diff --git a/src/main/java/vavi/util/archive/gca/ShellGcaArchive.java b/src/main/java/vavi/util/archive/gca/ShellGcaArchive.java index 2f6c2e8..1996981 100644 --- a/src/main/java/vavi/util/archive/gca/ShellGcaArchive.java +++ b/src/main/java/vavi/util/archive/gca/ShellGcaArchive.java @@ -24,9 +24,9 @@ /** - * GCA アーカイブを処理するサービスプロバイダです. + * ShellGcaArchive represents GCA archive using shell output. * - * TODO ファイル名が長い時最初 ... になってフォーマットが崩れる + * TODO when an entry name is long, it cannot format well because of abbreviation "...". * * @author Naohide Sano (nsano) * @version 0.00 030128 nsano initial version
@@ -45,7 +45,7 @@ public ShellGcaArchive(File file) throws IOException { this.file = file; - final DateFormat sdf = + DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Process p = Runtime.getRuntime().exec(new String[] { "gcac", "l", file.toString() }); BufferedReader r = new BufferedReader( diff --git a/src/main/java/vavi/util/archive/gca/ShellGcaArchiveSpi.java b/src/main/java/vavi/util/archive/gca/ShellGcaArchiveSpi.java index 141b170..7e3e206 100644 --- a/src/main/java/vavi/util/archive/gca/ShellGcaArchiveSpi.java +++ b/src/main/java/vavi/util/archive/gca/ShellGcaArchiveSpi.java @@ -14,7 +14,7 @@ /** - * GCA アーカイブを処理するサービスプロバイダです. + * The service provider for GCA archive using shell output. * * @author Naohide Sano (nsano) * @version 0.00 030128 nsano initial version
@@ -22,7 +22,7 @@ */ public class ShellGcaArchiveSpi extends GcaArchiveSpi { - /* */ + @Override public Archive createArchiveInstance(Object obj, Map env) throws IOException { return new ShellGcaArchive((File) obj); } diff --git a/src/main/java/vavi/util/archive/gzip/GZipInputStreamSpi.java b/src/main/java/vavi/util/archive/gzip/GZipInputStreamSpi.java index 38473c6..acfaac0 100644 --- a/src/main/java/vavi/util/archive/gzip/GZipInputStreamSpi.java +++ b/src/main/java/vavi/util/archive/gzip/GZipInputStreamSpi.java @@ -14,7 +14,7 @@ /** - * GZip アーカイブを処理するサービスプロバイダです. + * The service provider for GZip archive. * * @author Naohide Sano (nsano) * @version 0.00 040106 nsano initial version
@@ -25,9 +25,9 @@ public class GZipInputStreamSpi implements InputStreamSpi { private Object target; /** - * 伸張できるかどうか調べます. - * @param target 今のところ InputStream しか受け付けません + * @param target currently accepts only InputStream */ + @Override public boolean canExpandInput(Object target) throws IOException { if (!(target instanceof InputStream)) { @@ -55,7 +55,7 @@ public boolean canExpandInput(Object target) throws IOException { b[1] == (byte) 0x8b; } - /** */ + @Override public InputStream createInputStreamInstance() throws IOException { diff --git a/src/main/java/vavi/util/archive/lha/LhaArchiveSpi.java b/src/main/java/vavi/util/archive/lha/LhaArchiveSpi.java index d2bf1f0..7c9bf86 100644 --- a/src/main/java/vavi/util/archive/lha/LhaArchiveSpi.java +++ b/src/main/java/vavi/util/archive/lha/LhaArchiveSpi.java @@ -18,7 +18,7 @@ /** - * LHA アーカイブを処理するサービスプロバイダです. + * The service provider for LHA archive. * * @author Naohide Sano (nsano) * @version 0.00 021222 nsano initial version
@@ -26,9 +26,9 @@ public class LhaArchiveSpi implements ArchiveSpi { /** - * 解凍できるかどうか調べます. * @param target {@link File} and {@link InputStream} are supported. */ + @Override public boolean canExtractInput(Object target) throws IOException { if (!isSupported(target)) { return false; @@ -71,9 +71,9 @@ public boolean canExtractInput(Object target) throws IOException { /** * @param obj {@link File} and {@link InputStream} are supported. - * @param env * @throws IllegalArgumentException unsupported type is specified to obj. */ + @Override public Archive createArchiveInstance(Object obj, Map env) throws IOException { if (obj instanceof File) { return new LhaArchive((File) obj); diff --git a/src/main/java/vavi/util/archive/lha/LhaEntry.java b/src/main/java/vavi/util/archive/lha/LhaEntry.java index bbcf219..282294d 100644 --- a/src/main/java/vavi/util/archive/lha/LhaEntry.java +++ b/src/main/java/vavi/util/archive/lha/LhaEntry.java @@ -13,7 +13,7 @@ /** - * LHA 圧縮のサービスプロバイダです. + * LhaEntry represents a LHA archive entry. * * @author Naohide Sano (nsano) * @version 0.00 021103 nsano initial version
@@ -30,126 +30,92 @@ public LhaEntry(LhaHeader header) { this.entry = header; } - /** - * エントリのコメント文字列を返します。 - */ + @Override public String getComment() { return null; } - /** - * 圧縮されたエントリデータのサイズを返します。 - */ + @Override public long getCompressedSize() { return entry.getCompressedSize(); } - /** - * 圧縮解除されたエントリデータの CRC-32 チェックサムを返します。 - */ + @Override public long getCrc() { return entry.getCRC(); } - /** - * エントリの補足フィールドデータを返します。 - */ + @Override public Object getExtra() { return null; } - /** - * エントリの圧縮メソッドを返します。 - */ + @Override public int getMethod() { return 0; } - /** - * エントリの名前を返します。 - */ + @Override public String getName() { return entry.getPath(); } - /** - * エントリデータの圧縮解除時のサイズを返します。 - */ + @Override public long getSize() { return entry.getOriginalSize(); } - /** - * エントリの修正時間を返します。 - */ + @Override public long getTime() { return entry.getLastModified().getTime(); } - /** - * これがディレクトリエントリである場合に、true を返します。 - */ + @Override public boolean isDirectory() { return CompressMethod.LHD.equals(entry.getCompressMethod()); } - /** - * エントリに任意指定のコメント文字列を設定します。 - */ + @Override public void setComment(String comment) { // TODO } - /** - * 圧縮されたエントリデータのサイズを設定します。 - */ + @Override public void setCompressedSize(long csize) { entry.setCompressedSize(csize); } - /** - * 圧縮解除されたエントリデータの CRC-32 チェックサムを設定します。 - */ + @Override public void setCrc(long crc) { entry.setCRC((int) crc); } - /** - * エントリに任意指定の補足フィールドデータを設定します。 - */ + @Override public void setExtra(Object extra) { // TODO } - /** - * エントリの圧縮メソッドを設定します。 - */ + @Override public void setMethod(int method) { // TODO } - /** - * エントリデータの圧縮解除時のサイズを設定します。 - */ + @Override public void setSize(long size) { entry.setOriginalSize(size); } - /** - * エントリの修正時間を設定します。 - */ + @Override public void setTime(long time) { // TODO } - /** - * このエントリのコピーを返します。 - */ + @Override public Object clone() { return entry.clone(); } - /** */ + @Override public LhaHeader getWrappedObject() { return entry; } diff --git a/src/main/java/vavi/util/archive/rar/JunrarRarArchive.java b/src/main/java/vavi/util/archive/rar/JunrarRarArchive.java index aa61380..cac65cd 100644 --- a/src/main/java/vavi/util/archive/rar/JunrarRarArchive.java +++ b/src/main/java/vavi/util/archive/rar/JunrarRarArchive.java @@ -23,7 +23,7 @@ /** - * Represents RAR archived file. + * JunrarRarArchive represents RAR archived file * wrapping the library 'com.github.junrar:junrar' * * @author Naohide Sano (nsano) @@ -89,7 +89,7 @@ public Entry getEntry(String name) { } @Override - public InputStream getInputStream(final Entry entry) throws IOException { + public InputStream getInputStream(Entry entry) throws IOException { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); archive.extractFile((FileHeader) ((WrappedEntry) entry).getWrappedObject(), baos); diff --git a/src/main/java/vavi/util/archive/rar/JunrarRarArchiveSpi.java b/src/main/java/vavi/util/archive/rar/JunrarRarArchiveSpi.java index 941b4b4..1541433 100644 --- a/src/main/java/vavi/util/archive/rar/JunrarRarArchiveSpi.java +++ b/src/main/java/vavi/util/archive/rar/JunrarRarArchiveSpi.java @@ -17,7 +17,8 @@ /** - * The SPI for RAR archive using the library 'com.github.junrar:junrar'. + * The service provider for RAR archive + * using the library 'com.github.junrar:junrar'. * * @author Naohide Sano (nsano) * @version 0.00 220922 nsano initial version
diff --git a/src/main/java/vavi/util/archive/rar/JunrarRarEntry.java b/src/main/java/vavi/util/archive/rar/JunrarRarEntry.java index 5f66fd0..5351f57 100644 --- a/src/main/java/vavi/util/archive/rar/JunrarRarEntry.java +++ b/src/main/java/vavi/util/archive/rar/JunrarRarEntry.java @@ -12,7 +12,7 @@ /** - * Represents RAR archived file. + * JunrarRarEntry represents RAR archived file * warring the library 'com.github.junrar:junrar' * * @author Naohide Sano (nsano) diff --git a/src/main/java/vavi/util/archive/rar/NativeRarArchive.java b/src/main/java/vavi/util/archive/rar/NativeRarArchive.java index 7046f33..bd36b05 100644 --- a/src/main/java/vavi/util/archive/rar/NativeRarArchive.java +++ b/src/main/java/vavi/util/archive/rar/NativeRarArchive.java @@ -25,7 +25,7 @@ /** - * UnRAR32.dll のラッパークラスです。 + * NativeRarArchive represents RAR archive wrappring UnRAR32.dll. * * @author Naohide Sano (nsano) * @version 0.00 071110 nsano initial version
@@ -38,7 +38,7 @@ public class NativeRarArchive implements Archive { /** */ private File file; - /** */ + /** Creates a RAR Archive instance. */ public NativeRarArchive(File file) throws IOException { this.file = file; @@ -64,25 +64,19 @@ public NativeRarArchive(File file) throws IOException { } } - /** - * ファイルを閉じます。 - */ + @Override public void close() throws IOException { closeArchive(); } - /** - * ファイルエントリの列挙を返します。 - */ + @Override public Entry[] entries() { Entry[] entries = new Entry[this.entries.size()]; this.entries.toArray(entries); return entries; } - /** - * 指定された名前の ZIP ファイルエントリを返します。 - */ + @Override public Entry getEntry(String name) { for (Entry entry : entries) { if (entry.getName().equals(name)) { @@ -96,10 +90,9 @@ public Entry getEntry(String name) { private static final String commandLineBase = "e \"{0}\" \"{1}\" \"{2}\""; /** - * 指定された ファイルエントリの内容を読み込むための入力ストリームを - * 返します。 * TODO password, keyfile */ + @Override public InputStream getInputStream(Entry entry) throws IOException { String commandLine = MessageFormat.format(commandLineBase, @@ -119,70 +112,66 @@ public InputStream getInputStream(Entry entry) throws IOException { } } - /** - * ファイルのパス名を返します。 - */ + @Override public String getName() { return file.getPath(); } - /** - * ファイル中のエントリの数を返します。 - */ + @Override public int size() { return entries.size(); } - // for Native method ------------------------------------------------------ + // for Native method ---- - /** インスタンス識別子 */ + /** instance id for dll */ private int instance; - /** getFileName がうまくいかんから代用 */ + /** getFileName() doesn't work well, so this is alternative */ private String currentFilename; - // インターフェース + // interface - /** コマンド文字列を与えて,各種の書庫操作を行います。 */ + /** processes each functionality by a command string */ private native void exec(String command) throws IOException; - /** バージョンを返します。 */ + /** gets version */ protected native int getVersion(); - /** 動作中か否かを得ます。 */ + /** tells is running or not */ private native boolean isRunning(); - /** 指定ファイルが書庫として正しいかどうかを返します。 */ + /** checks the archive is valid or not */ private native boolean checkArchive(String filename, int mode); - /** 指定された書庫ファイルに格納されているファイル数を得ます。 */ + /** gets entries count in an archive */ private native int getFileCount(String filename) throws IOException; - /** 書庫ファイルを開きます。 */ + /** open an archive */ private native void openArchive(String filename, int mode) throws IOException; - /** 書庫ファイルを閉じます。 */ + /** close the archive */ private native void closeArchive() throws IOException; - /** 最初の格納ファイルの情報を得ます。 */ + /** gets the first entry */ private native boolean findFirst(String key) throws IOException; - /** 2 番目以降の格納ファイルの情報を得ます。 */ + /** gets after 2nd entry */ private native boolean findNext(); - /** 格納ファイルのファイル名を得ます。 */ + /** gets the current entry filename */ private native String getCurrentFileName() throws IOException; - /** 格納ファイルの圧縮法を得ます。 */ + /** gets the current entry archive method */ private native int getCurrentMethod() throws IOException; - /** 格納ファイルのサイズを得ます。 */ + /** gets the current entry original size */ private native long getCurrentOriginalSize() throws IOException; - /** 格納ファイルの圧縮サイズを得ます。 */ + /** gets the current entry compressed size */ private native long getCurrentCompressedSize() throws IOException; - /** 格納ファイルの日付を DOS 形式で得ます。 */ + /** gets the current entry date in DOS format */ private native int getCurrentDate() throws IOException; - /** 格納ファイルの時刻を DOS 形式で得ます。 */ + /** gets the current entry time in DOS format */ private native int getCurrentTime() throws IOException; - /** 格納ファイルのチェックサムを得ます。 */ + /** gets the current entry checksum */ private native long getCurrentCRC() throws IOException; - /** 検索にマッチしたファイルのサイズの合計を得ます。 */ + /** gets a sum of selected entries size */ private native long getSelectedSize() throws IOException; - /** 検索にマッチしたファイルの圧縮サイズの合計を得ます。 */ + /** gets a sum of selected entries compressed size */ private native long getSelectedCompressedSize() throws IOException; - /** 検索にマッチしたファイルの全体の圧縮率を得ます。 */ + /** gets compression ratio of selected entries */ private native int getSelectedRatio() throws IOException; /* */ diff --git a/src/main/java/vavi/util/archive/rar/NativeRarArchiveSpi.java b/src/main/java/vavi/util/archive/rar/NativeRarArchiveSpi.java index 77229cf..51c2fe1 100644 --- a/src/main/java/vavi/util/archive/rar/NativeRarArchiveSpi.java +++ b/src/main/java/vavi/util/archive/rar/NativeRarArchiveSpi.java @@ -17,7 +17,7 @@ /** - * The SPI for RAR archive using a native library. + * The service provider for RAR archive using a native library. * * @author Naohide Sano (nsano) * @version 0.00 021222 nsano initial version
@@ -27,9 +27,9 @@ public class NativeRarArchiveSpi extends RarArchiveSpi { /** - * 解凍できるかどうか調べます. - * @param target 今のところ File しか受け付けません + * @param target currently accepts only File */ + @Override public boolean canExtractInput(Object target) throws IOException { if (!isSupported(target)) { return false; @@ -48,7 +48,7 @@ public boolean canExtractInput(Object target) throws IOException { return canExtractInput(is, needToClose); } - /* */ + @Override public Archive createArchiveInstance(Object obj, Map env) throws IOException { return new NativeRarArchive((File) obj); } diff --git a/src/main/java/vavi/util/archive/rar/PureJavaRarArchive.java b/src/main/java/vavi/util/archive/rar/PureJavaRarArchive.java index 52ed273..d7c6f23 100644 --- a/src/main/java/vavi/util/archive/rar/PureJavaRarArchive.java +++ b/src/main/java/vavi/util/archive/rar/PureJavaRarArchive.java @@ -23,7 +23,7 @@ /** - * Represents RAR archived file. + * PureJavaRarArchive represents RAR archived file * wrapping the library 'vavi:java-unrar' * * @author Naohide Sano (nsano) @@ -89,7 +89,7 @@ public Entry getEntry(String name) { } @Override - public InputStream getInputStream(final Entry entry) throws IOException { + public InputStream getInputStream(Entry entry) throws IOException { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); archive.extractFile((FileHeader) ((WrappedEntry) entry).getWrappedObject(), baos); diff --git a/src/main/java/vavi/util/archive/rar/PureJavaRarArchiveSpi.java b/src/main/java/vavi/util/archive/rar/PureJavaRarArchiveSpi.java index 3cb276c..315861f 100644 --- a/src/main/java/vavi/util/archive/rar/PureJavaRarArchiveSpi.java +++ b/src/main/java/vavi/util/archive/rar/PureJavaRarArchiveSpi.java @@ -17,7 +17,7 @@ /** - * The SPI for RAR archive using the library 'vavi:java-unrar'. + * The service provider for RAR archive using the library 'vavi:java-unrar'. * * @author Naohide Sano (nsano) * @version 0.00 021222 nsano initial version
diff --git a/src/main/java/vavi/util/archive/rar/PureJavaRarEntry.java b/src/main/java/vavi/util/archive/rar/PureJavaRarEntry.java index 5d7182e..ed07df9 100644 --- a/src/main/java/vavi/util/archive/rar/PureJavaRarEntry.java +++ b/src/main/java/vavi/util/archive/rar/PureJavaRarEntry.java @@ -15,7 +15,7 @@ /** - * Represents RAR archived file. + * PureJavaRarEntry represents a RAR archived file * warring the library 'vavi:java-unrar' * * @author Naohide Sano (nsano) diff --git a/src/main/java/vavi/util/archive/rar/RarArchiveSpi.java b/src/main/java/vavi/util/archive/rar/RarArchiveSpi.java index 64c3263..3ed9a3e 100644 --- a/src/main/java/vavi/util/archive/rar/RarArchiveSpi.java +++ b/src/main/java/vavi/util/archive/rar/RarArchiveSpi.java @@ -13,7 +13,7 @@ /** - * The SPI for RAR archive. + * The service provider for a RAR archive. * * @author Naohide Sano (nsano) * @version 0.00 021222 nsano initial version
diff --git a/src/main/java/vavi/util/archive/rar/ShellRarArchive.java b/src/main/java/vavi/util/archive/rar/ShellRarArchive.java index 50e7875..14c7e74 100644 --- a/src/main/java/vavi/util/archive/rar/ShellRarArchive.java +++ b/src/main/java/vavi/util/archive/rar/ShellRarArchive.java @@ -25,8 +25,7 @@ /** - * RAR アーカイブを処理するサービスプロバイダです. - * (外部シェル起動バージョン) + * ShellRarArchive represents a RAR archive using shell outoput. * * @author Naohide Sano (nsano) * @version 0.00 021105 nsano initial version
@@ -40,7 +39,7 @@ public class ShellRarArchive implements Archive { /** */ public ShellRarArchive(File file) throws IOException { - final DateFormat sdf = new SimpleDateFormat("dd-MM-yy HH:mm"); + DateFormat sdf = new SimpleDateFormat("dd-MM-yy HH:mm"); Process p = Runtime.getRuntime().exec(new String[] { "unrar", "v", file.toString() }); BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream())); r.readLine(); diff --git a/src/main/java/vavi/util/archive/rar/ShellRarArchiveSpi.java b/src/main/java/vavi/util/archive/rar/ShellRarArchiveSpi.java index 02e9497..ea9b924 100644 --- a/src/main/java/vavi/util/archive/rar/ShellRarArchiveSpi.java +++ b/src/main/java/vavi/util/archive/rar/ShellRarArchiveSpi.java @@ -17,7 +17,7 @@ /** - * The SPI for RAR archive using native library. + * The service provider for RAR archive using native library. * * @author Naohide Sano (nsano) * @version 0.00 021222 nsano initial version
@@ -27,9 +27,9 @@ public class ShellRarArchiveSpi extends RarArchiveSpi { /** - * 解凍できるかどうか調べます. - * @param target 今のところ File しか受け付けません + * @param target currently accepts only File */ + @Override public boolean canExtractInput(Object target) throws IOException { if (!isSupported(target)) { return false; @@ -48,7 +48,7 @@ public boolean canExtractInput(Object target) throws IOException { return canExtractInput(is, needToClose); } - /* */ + @Override public Archive createArchiveInstance(Object obj, Map env) throws IOException { return new ShellRarArchive((File) obj); } diff --git a/src/main/java/vavi/util/archive/sevenzip/ApacheSevenZipArchiveSpi.java b/src/main/java/vavi/util/archive/sevenzip/ApacheSevenZipArchiveSpi.java index b58e430..79cb445 100644 --- a/src/main/java/vavi/util/archive/sevenzip/ApacheSevenZipArchiveSpi.java +++ b/src/main/java/vavi/util/archive/sevenzip/ApacheSevenZipArchiveSpi.java @@ -17,7 +17,7 @@ /** - * The SPI for 7zip using Apache commons compress. + * The service provider for 7zip archive using apache commons-compress. * * @author Naohide Sano (umjammer) * @version 0.00 2021/11/16 umjammer initial version
diff --git a/src/main/java/vavi/util/archive/sevenzip/ApacheSevenZipEntry.java b/src/main/java/vavi/util/archive/sevenzip/ApacheSevenZipEntry.java index 15b1389..40ec92c 100644 --- a/src/main/java/vavi/util/archive/sevenzip/ApacheSevenZipEntry.java +++ b/src/main/java/vavi/util/archive/sevenzip/ApacheSevenZipEntry.java @@ -113,6 +113,7 @@ public Object clone() { } /** */ + @Override public SevenZArchiveEntry getWrappedObject() { return entry; } diff --git a/src/main/java/vavi/util/archive/sevenzip/NativeSevenZipArchive.java b/src/main/java/vavi/util/archive/sevenzip/NativeSevenZipArchive.java index a07e7b1..d5b4f5e 100644 --- a/src/main/java/vavi/util/archive/sevenzip/NativeSevenZipArchive.java +++ b/src/main/java/vavi/util/archive/sevenzip/NativeSevenZipArchive.java @@ -152,56 +152,56 @@ public int size() { } } - // for Native method ------------------------------------------------------ + // for Native method ---- - /** インスタンス識別子 */ + /** instance id for dll */ private int instance; - /** getFileName がうまくいかんから代用 */ + /** getFileName() doesn't work well, so this is alternative */ private String currentFilename; - // インターフェース + // interface - /** コマンド文字列を与えて,各種の書庫操作を行います。 */ + /** processes each functionality by a command string */ private native void exec(String command) throws IOException; - /** バージョンを返します。 */ + /** gets version */ private native int getVersion(); - /** 動作中か否かを得ます。 */ + /** tells is running or not */ private native boolean isRunning(); - /** 指定ファイルが書庫として正しいかどうかを返します。 */ + /** checks the archive is valid or not */ private native boolean checkArchive(String filename, int mode); - /** 指定された書庫ファイルに格納されているファイル数を得ます。 */ + /** gets entries in an archive */ private native int getFileCount(String filename) throws IOException; - /** 書庫ファイルを開きます。 */ + /** open an archive */ private native void openArchive(String filename, int mode) throws IOException; - /** 書庫ファイルを閉じます。 */ + /** close the archive */ private native void closeArchive() throws IOException; - /** 最初の格納ファイルの情報を得ます。 */ + /** gets the first entry */ private native boolean findFirst(String key) throws IOException; - /** 2 番目以降の格納ファイルの情報を得ます。 */ + /** gets after 2nd entry */ private native boolean findNext(); - /** 格納ファイルのファイル名を得ます。 */ + /** gets the current entry filename */ private native String getCurrentFileName() throws IOException; - /** 格納ファイルの圧縮法を得ます。 */ + /** gets the current entry archive method */ private native int getCurrentMethod() throws IOException; - /** 格納ファイルのサイズを得ます。 */ + /** gets the current entry original size */ private native long getCurrentOriginalSize() throws IOException; - /** 格納ファイルの圧縮サイズを得ます。 */ + /** gets the current entry compressed size */ private native long getCurrentCompressedSize() throws IOException; - /** 格納ファイルの日付を DOS 形式で得ます。 */ + /** gets the current entry date in DOS format */ private native int getCurrentDate() throws IOException; - /** 格納ファイルの時刻を DOS 形式で得ます。 */ + /** gets the current entry time in DOS format */ private native int getCurrentTime() throws IOException; - /** 格納ファイルのチェックサムを得ます。 */ + /** gets the current entry checksum */ private native long getCurrentCRC() throws IOException; - /** 検索にマッチしたファイルのサイズの合計を得ます。 */ + /** gets a sum of selected entries size */ private native long getSelectedSize() throws IOException; - /** 検索にマッチしたファイルの圧縮サイズの合計を得ます。 */ + /** gets a sum of selected entries compressed size */ private native long getSelectedCompressedSize() throws IOException; - /** 検索にマッチしたファイルの全体の圧縮率を得ます。 */ + /** gets compression ratio of selected entries */ private native int getSelectedRatio() throws IOException; /* */ diff --git a/src/main/java/vavi/util/archive/sevenzip/NativeSevenZipArchiveSpi.java b/src/main/java/vavi/util/archive/sevenzip/NativeSevenZipArchiveSpi.java index 1117925..6ad0d26 100644 --- a/src/main/java/vavi/util/archive/sevenzip/NativeSevenZipArchiveSpi.java +++ b/src/main/java/vavi/util/archive/sevenzip/NativeSevenZipArchiveSpi.java @@ -17,7 +17,7 @@ /** - * The SPI for SevenZip using native library. + * The service provider for SevenZip archive using native library. * * @author Naohide Sano (nsano) * @version 0.00 030228 nsano initial version
diff --git a/src/main/java/vavi/util/archive/spi/ArchiveSpi.java b/src/main/java/vavi/util/archive/spi/ArchiveSpi.java index bbe9c31..1874776 100644 --- a/src/main/java/vavi/util/archive/spi/ArchiveSpi.java +++ b/src/main/java/vavi/util/archive/spi/ArchiveSpi.java @@ -13,7 +13,7 @@ /** - * Service Provider Interface for Archive class. + * Service Provider Interface for {@link Archive} class. * * @author Naohide Sano (nsano) * @version 0.00 021222 nsano initial version
@@ -28,16 +28,25 @@ public interface ArchiveSpi { */ boolean canExtractInput(Object target) throws IOException; - /** */ + /** + * Creates a {@link Archive} instance. + * @param env spi specific options + */ Archive createArchiveInstance(Object obj, Map env) throws IOException; - /** TODO */ + /** + * classes which is determined as extractable by {{@link #isSupported(Object)}} + * TODO candidate + */ Class[] getInputTypes(); - /** TODO */ + /** + * file extensions which is determined as extractable + * TODO candidate + */ String[] getFileSuffixes(); - /** */ + /** Tells the target object is able to extract. */ default boolean isSupported(Object target) { for (Class c : getInputTypes()) { if (c.isInstance(target)) { @@ -47,6 +56,7 @@ default boolean isSupported(Object target) { return false; } + /** utility for env Map */ static boolean isEnabled(String key, Map map) { return map.containsKey(key) && (map.get(key) == null || (boolean) map.get(key)); } diff --git a/src/main/java/vavi/util/archive/spi/InputStreamSpi.java b/src/main/java/vavi/util/archive/spi/InputStreamSpi.java index 50f0927..6f81888 100644 --- a/src/main/java/vavi/util/archive/spi/InputStreamSpi.java +++ b/src/main/java/vavi/util/archive/spi/InputStreamSpi.java @@ -11,7 +11,7 @@ /** - * Service Provider Interface for archived InpuStream class. + * Service Provider Interface class for {@link InputStream} of archived files. * * @author Naohide Sano (nsano) * @version 0.00 040105 nsano initial version
@@ -24,7 +24,10 @@ public interface InputStreamSpi { */ boolean canExpandInput(Object target) throws IOException; - /** TODO should have input argument */ + /** + * Creates a decompressing {@link InputStream} instance. + * TODO should have input argument + */ InputStream createInputStreamInstance() throws IOException; } diff --git a/src/main/java/vavi/util/archive/stuffit/NativeStuffItArchive.java b/src/main/java/vavi/util/archive/stuffit/NativeStuffItArchive.java index 7c7b7b2..4c30c6d 100644 --- a/src/main/java/vavi/util/archive/stuffit/NativeStuffItArchive.java +++ b/src/main/java/vavi/util/archive/stuffit/NativeStuffItArchive.java @@ -22,7 +22,7 @@ /** - * StuffItWrapper.dll のラッパークラスです。 + * NativeStuffItArchive represents a StuffIt archive wrapping StuffItWrapper.dll. * * @author Naohide Sano (nsano) * @version 0.00 030226 nsano initial version
@@ -45,25 +45,19 @@ public NativeStuffItArchive(File file) throws IOException { openArchive(file.getPath(), 0); } - /** - * ファイルを閉じます。 - */ + @Override public void close() throws IOException { closeArchive(); } - /** - * ファイルエントリの列挙を返します。 - */ + @Override public Entry[] entries() { Entry[] entries = new Entry[this.entries.size()]; this.entries.toArray(entries); return entries; } - /** - * 指定された名前の ZIP ファイルエントリを返します。 - */ + @Override public Entry getEntry(String name) { for (Entry entry : entries) { if (entry.getName().equals(name)) { @@ -73,10 +67,7 @@ public Entry getEntry(String name) { return null; } - /** - * 指定された ファイルエントリの内容を読み込むための入力ストリームを - * 返します。 - */ + @Override public InputStream getInputStream(Entry entry) throws IOException { String commandLine = MessageFormat.format("e \"{0}\" \"{1}\" \"{2}\"", @@ -96,16 +87,12 @@ public InputStream getInputStream(Entry entry) throws IOException { } } - /** - * ファイルのパス名を返します。 - */ + @Override public String getName() { return file.getPath(); } - /** - * ファイル中のエントリの数を返します。 - */ + @Override public int size() { return entries.size(); } @@ -147,21 +134,21 @@ protected void addDirectoryEntry(String filename, long time) { entries.add(entry); } - // for Native method ------------------------------------------------------ + // for Native method ---- - /** インスタンス識別子 */ + /** instance id for dll */ private int instance; - // インターフェース + // interface - /** コマンド文字列を与えて,各種の書庫操作を行います。 */ + /** processes each functionality by a command string */ private native void exec(String command) throws IOException; - /** バージョンを返します。 */ + /** gets version */ protected native int getVersion(); - /** 書庫ファイルを開きます。 */ + /** open an archive */ private native void openArchive(String filename, int mode) throws IOException; - /** 書庫ファイルを閉じます。 */ + /** close the archive */ private native void closeArchive() throws IOException; /* */ diff --git a/src/main/java/vavi/util/archive/stuffit/NativeStuffItArchiveSpi.java b/src/main/java/vavi/util/archive/stuffit/NativeStuffItArchiveSpi.java index 20c2ea6..711603b 100644 --- a/src/main/java/vavi/util/archive/stuffit/NativeStuffItArchiveSpi.java +++ b/src/main/java/vavi/util/archive/stuffit/NativeStuffItArchiveSpi.java @@ -14,14 +14,14 @@ /** - * StuffIt アーカイブを処理するサービスプロバイダです. + * The service provider for StuffIt archive. * * @author Naohide Sano (nsano) * @version 0.00 060106 nsano initial version
*/ public class NativeStuffItArchiveSpi extends StuffItArchiveSpi { - /* */ + @Override public Archive createArchiveInstance(Object obj, Map env) throws IOException { return new NativeStuffItArchive((File) obj); } diff --git a/src/main/java/vavi/util/archive/stuffit/StuffItArchiveSpi.java b/src/main/java/vavi/util/archive/stuffit/StuffItArchiveSpi.java index c3be6a0..3a3c856 100644 --- a/src/main/java/vavi/util/archive/stuffit/StuffItArchiveSpi.java +++ b/src/main/java/vavi/util/archive/stuffit/StuffItArchiveSpi.java @@ -20,7 +20,7 @@ /** - * The SPI for StuffIt archived file. + * The service provider for StuffIt archive file. * * @author Naohide Sano (nsano) * @version 0.00 060106 nsano initial version
diff --git a/src/main/java/vavi/util/archive/tar/TarArchive.java b/src/main/java/vavi/util/archive/tar/TarArchive.java index 55ac3f9..d00a5d5 100644 --- a/src/main/java/vavi/util/archive/tar/TarArchive.java +++ b/src/main/java/vavi/util/archive/tar/TarArchive.java @@ -21,7 +21,7 @@ /** - * Represents TAR archived file. + * TarArchive represents TAR archive file. * * @author Naohide Sano (nsano) * @version 0.00 040106 nsano initial version
diff --git a/src/main/java/vavi/util/archive/tar/TarArchiveSpi.java b/src/main/java/vavi/util/archive/tar/TarArchiveSpi.java index a5026e0..f262206 100644 --- a/src/main/java/vavi/util/archive/tar/TarArchiveSpi.java +++ b/src/main/java/vavi/util/archive/tar/TarArchiveSpi.java @@ -20,7 +20,7 @@ /** - * TAR アーカイブを処理するサービスプロバイダです. + * The service provider for TAR archive. * * @author Naohide Sano (nsano) * @version 0.00 040106 nsano initial version
@@ -31,9 +31,9 @@ public class TarArchiveSpi implements ArchiveSpi { private static final int SKIP = 257; /** - * 解凍できるかどうか調べます. - * @param target 今のところ InputStream しか受け付けません + * @param target currently accepts only InputStream */ + @Override public boolean canExtractInput(Object target) throws IOException { if (!(target instanceof InputStream)) { @@ -72,7 +72,7 @@ public boolean canExtractInput(Object target) throws IOException { Debug.println(Level.FINE, "tar magic:\n" + StringUtil.getDump(b)); return "ustar".equals(new String(b, StandardCharsets.ISO_8859_1)) || - (b[0] == 0x00 && // TODO magic 無い奴がいる + (b[0] == 0x00 && // TODO w/ magic b[1] == 0x00 && b[2] == 0x00 && b[3] == 0x00 && @@ -90,7 +90,7 @@ private boolean isAllAsciiAndNull(byte[] bytes) { return true; } - /** */ + @Override public Archive createArchiveInstance(Object obj, Map env) throws IOException { return new TarArchive((InputStream) obj); } diff --git a/src/main/java/vavi/util/archive/tar/TarEntry.java b/src/main/java/vavi/util/archive/tar/TarEntry.java index 37205d2..74025a4 100644 --- a/src/main/java/vavi/util/archive/tar/TarEntry.java +++ b/src/main/java/vavi/util/archive/tar/TarEntry.java @@ -12,7 +12,7 @@ /** - * Wrapper for the TAR archived file entry. + * Wrapper for the TAR archive file entry. * * @author Naohide Sano (nsano) * @version 0.00 040106 nsano initial version
@@ -107,7 +107,7 @@ public void setTime(long time) { entry.setModTime(new Date(time)); } - /** */ + @Override public org.apache.commons.compress.archivers.tar.TarArchiveEntry getWrappedObject() { return entry; } diff --git a/src/main/java/vavi/util/archive/tar/TarInputStreamSpi.java b/src/main/java/vavi/util/archive/tar/TarInputStreamSpi.java index 3b97eac..5e7e254 100644 --- a/src/main/java/vavi/util/archive/tar/TarInputStreamSpi.java +++ b/src/main/java/vavi/util/archive/tar/TarInputStreamSpi.java @@ -20,7 +20,7 @@ /** - * Tar アーカイブを処理するサービスプロバイダです. + * The service provider for Tar archive. * * @author Naohide Sano (nsano) * @version 0.00 040106 nsano initial version
@@ -34,9 +34,9 @@ public class TarInputStreamSpi implements InputStreamSpi { private static final int SKIP = 257; /** - * 解凍できるかどうか調べます. - * @param target 今のところ {#link InputStream} しか受け付けません + * @param target currently accepts only {#link InputStream} */ + @Override public boolean canExpandInput(Object target) throws IOException { if (!(target instanceof InputStream)) { @@ -96,6 +96,7 @@ private boolean isAllAsciiAndNull(byte[] bytes) { } /** */ + @Override public InputStream createInputStreamInstance() { return new TarArchiveInputStream((InputStream) target); } diff --git a/src/main/java/vavi/util/archive/zip/AntZipArchive.java b/src/main/java/vavi/util/archive/zip/AntZipArchive.java index 7648758..7a84cda 100644 --- a/src/main/java/vavi/util/archive/zip/AntZipArchive.java +++ b/src/main/java/vavi/util/archive/zip/AntZipArchive.java @@ -22,7 +22,7 @@ /** - * The ZIP SPI using the Ant zip library. + * The service provider for ZIP archive using the Ant zip library. * * @author Naohide Sano (nsano) * @version 0.00 021103 nsano initial version
diff --git a/src/main/java/vavi/util/archive/zip/AntZipArchiveSpi.java b/src/main/java/vavi/util/archive/zip/AntZipArchiveSpi.java index c32aa7c..651c8a1 100644 --- a/src/main/java/vavi/util/archive/zip/AntZipArchiveSpi.java +++ b/src/main/java/vavi/util/archive/zip/AntZipArchiveSpi.java @@ -17,7 +17,7 @@ /** - * The ZIP SPI using the Ant zip library. + * The service provider for ZIP archive using the Ant zip library. * * @author Naohide Sano (nsano) * @version 0.00 021222 nsano initial version
diff --git a/src/main/java/vavi/util/archive/zip/JdkZipArchive.java b/src/main/java/vavi/util/archive/zip/JdkZipArchive.java index 3262bfe..bf9fec7 100644 --- a/src/main/java/vavi/util/archive/zip/JdkZipArchive.java +++ b/src/main/java/vavi/util/archive/zip/JdkZipArchive.java @@ -15,6 +15,7 @@ import java.util.Enumeration; import java.util.List; import java.util.logging.Level; +import java.util.zip.ZipException; import java.util.zip.ZipFile; import vavi.util.Debug; @@ -84,12 +85,12 @@ private void init(File file, String failsafeEncoding) throws IOException { String encoding = System.getProperty(ZIP_ENCODING, StandardCharsets.UTF_8.toString()); this.archive = new ZipFile(file, Charset.forName(encoding)); this.entries = entries(); - } catch (IllegalArgumentException e) { - if (failsafeEncoding != null && e.getMessage().equals("MALFORMED")) { -Debug.println("zip reading failure by utf-8, retry using " + failsafeEncoding); + } catch (ZipException e) { + if (failsafeEncoding != null && e.getMessage().contains("invalid CEN header")) { +Debug.println(Level.FINE, "zip reading failure by utf-8, retry using " + failsafeEncoding); this.archive = new ZipFile(file, Charset.forName(failsafeEncoding)); this.entries = entries(); -Debug.println("entries " + entries.length); +Debug.println(Level.FINE, "entries " + entries.length); } else { // IllegalArgumentException used for next provider throw new IOException(e); diff --git a/src/main/java/vavi/util/archive/zip/JdkZipArchiveSpi.java b/src/main/java/vavi/util/archive/zip/JdkZipArchiveSpi.java index bf513d8..e7d5e55 100644 --- a/src/main/java/vavi/util/archive/zip/JdkZipArchiveSpi.java +++ b/src/main/java/vavi/util/archive/zip/JdkZipArchiveSpi.java @@ -19,7 +19,7 @@ /** - * The ZIP SPI using the JDK zip library. + * The service provider for ZIP archive using the JDK zip library. * * @author Naohide Sano (nsano) * @version 0.00 021222 nsano initial version
diff --git a/src/main/java/vavi/util/archive/zip/ZipArchiveSpi.java b/src/main/java/vavi/util/archive/zip/ZipArchiveSpi.java index 6510954..8a1fe2b 100644 --- a/src/main/java/vavi/util/archive/zip/ZipArchiveSpi.java +++ b/src/main/java/vavi/util/archive/zip/ZipArchiveSpi.java @@ -13,7 +13,7 @@ /** - * The ZIP SPI base. + * The service provider for ZIP archive base. * * @author Naohide Sano (nsano) * @version 0.00 220929 nsano initial version
diff --git a/src/main/java/vavi/util/codec/lzma/LzmaInputStream.java b/src/main/java/vavi/util/codec/lzma/LzmaInputStream.java index e052666..f4c8d3c 100644 --- a/src/main/java/vavi/util/codec/lzma/LzmaInputStream.java +++ b/src/main/java/vavi/util/codec/lzma/LzmaInputStream.java @@ -397,6 +397,7 @@ private void readHeader() throws IOException { } /** */ + @Override public int read(byte[] buf, int off, int len) throws IOException { if (closed) { throw new IOException("stream closed"); @@ -423,6 +424,7 @@ public int read(byte[] buf, int off, int len) throws IOException { } /** */ + @Override public void close() throws IOException { closed = true; super.close(); diff --git a/src/main/java/vavi/util/codec/rpm/RPMIndexEntry.java b/src/main/java/vavi/util/codec/rpm/RPMIndexEntry.java index 0ecede5..c6d213b 100644 --- a/src/main/java/vavi/util/codec/rpm/RPMIndexEntry.java +++ b/src/main/java/vavi/util/codec/rpm/RPMIndexEntry.java @@ -51,26 +51,26 @@ public void dump(PrintStream out, String prefix) { case RPMTYPE_INT8: value = this.values.get(i); int int8 = (Integer) value; - out.println(prefix + "[" + i + "] = " + int8 + ""); + out.println(prefix + "[" + i + "] = " + int8); break; case RPMTYPE_INT16: value = this.values.get(i); int int16 = (Integer) value; - out.println(prefix + "[" + i + "] = " + int16 + ""); + out.println(prefix + "[" + i + "] = " + int16); break; case RPMTYPE_INT32: value = this.values.get(i); int int32 = (Integer) value; - out.println(prefix + "[" + i + "] = " + int32 + ""); + out.println(prefix + "[" + i + "] = " + int32); break; case RPMTYPE_INT64: value = this.values.get(i); long int64 = (Long) value; - out.println(prefix + "[" + i + "] = " + int64 + ""); + out.println(prefix + "[" + i + "] = " + int64); break; case RPMTYPE_STRING: String str = (String) this.values.get(i); - out.println(prefix + "[" + i + "] = " + str + ""); + out.println(prefix + "[" + i + "] = " + str); break; case RPMTYPE_BIN: byte[] data = (byte[]) this.values.get(0); @@ -79,7 +79,7 @@ public void dump(PrintStream out, String prefix) { break; case RPMTYPE_STRING_ARRAY: String[] sAry = (String[]) this.values.get(0); - out.println(prefix + "[" + i + "] = " + sAry[i] + ""); + out.println(prefix + "[" + i + "] = " + sAry[i]); break; case RPMTYPE_I18NSTRING: // UNDONE diff --git a/src/main/java/vavi/util/codec/rpm/RPMUtil.java b/src/main/java/vavi/util/codec/rpm/RPMUtil.java index d0dffd5..2b7a1a2 100644 --- a/src/main/java/vavi/util/codec/rpm/RPMUtil.java +++ b/src/main/java/vavi/util/codec/rpm/RPMUtil.java @@ -11,7 +11,7 @@ public static String hexString(byte[] buf, int off, int len) { } public static String hexString(byte[] buf, int off, int len, int sepFreq, String sep) { - final char[] hexChars = { + char[] hexChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; diff --git a/src/test/java/Bzip2Compress.java b/src/test/java/vavi/util/archive/bzip2/Bzip2Compress.java similarity index 74% rename from src/test/java/Bzip2Compress.java rename to src/test/java/vavi/util/archive/bzip2/Bzip2Compress.java index dfa08e0..3fb2a23 100644 --- a/src/test/java/Bzip2Compress.java +++ b/src/test/java/vavi/util/archive/bzip2/Bzip2Compress.java @@ -1,5 +1,5 @@ -/* - * $Header: /home/cvspublic/jakarta-commons-sandbox/compress/src/test/org/apache/commons/compress/bzip2/example/Bzip2Compress.java,v 1.1 2003/12/02 20:44:24 dirkv Exp $ +package vavi.util.archive.bzip2;/* + * $Header: /home/cvspublic/jakarta-commons-sandbox/compress/src/test/org/apache/commons/compress/bzip2/example/vavi.util.archive.bzip2.Bzip2Compress.java,v 1.1 2003/12/02 20:44:24 dirkv Exp $ * $Revision: 1.1 $ * $Date: 2003/12/02 20:44:24 $ * @@ -60,11 +60,7 @@ */ import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import java.nio.file.Files; import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; @@ -76,30 +72,16 @@ * @version $Revision: 1.1 $ $Date: 2003/12/02 20:44:24 $ */ public class Bzip2Compress { - public static void main(final String[] args) throws Exception { + public static void main(String[] args) throws Exception { if (2 != args.length) { - System.out.println("java Bzip2Compress "); + System.out.println("java vavi.util.archive.bzip2.Bzip2Compress "); System.exit(1); } - final File source = new File(args[0]); - final File destination = new File(args[1]); - final BZip2CompressorOutputStream output = new BZip2CompressorOutputStream(new FileOutputStream(destination)); - final FileInputStream input = new FileInputStream(source); - copy(input, output); - input.close(); + File source = new File(args[0]); + File destination = new File(args[1]); + BZip2CompressorOutputStream output = new BZip2CompressorOutputStream(Files.newOutputStream(destination.toPath())); + Files.copy(source.toPath(), output); output.close(); } - - /** - * Copy bytes from an InputStream to an OutputStream. - */ - private static void copy(final InputStream input, final OutputStream output) - throws IOException { - final byte[] buffer = new byte[8024]; - int n; - while (-1 != (n = input.read(buffer))) { - output.write(buffer, 0, n); - } - } } diff --git a/src/test/java/Bzip2Uncompress.java b/src/test/java/vavi/util/archive/bzip2/Bzip2Uncompress.java similarity index 70% rename from src/test/java/Bzip2Uncompress.java rename to src/test/java/vavi/util/archive/bzip2/Bzip2Uncompress.java index a156cd3..d28fee1 100644 --- a/src/test/java/Bzip2Uncompress.java +++ b/src/test/java/vavi/util/archive/bzip2/Bzip2Uncompress.java @@ -1,5 +1,5 @@ -/* - * $Header: /home/cvspublic/jakarta-commons-sandbox/compress/src/test/org/apache/commons/compress/bzip2/example/Bzip2Uncompress.java,v 1.1 2003/12/02 20:44:24 dirkv Exp $ +package vavi.util.archive.bzip2;/* + * $Header: /home/cvspublic/jakarta-commons-sandbox/compress/src/test/org/apache/commons/compress/bzip2/example/vavi.util.archive.bzip2.Bzip2Uncompress.java,v 1.1 2003/12/02 20:44:24 dirkv Exp $ * $Revision: 1.1 $ * $Date: 2003/12/02 20:44:24 $ * @@ -60,52 +60,30 @@ */ import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import java.nio.file.Files; import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; /** - * This simple example shows how to use the Bzip2 classes to uncompress a file. + * This simple example shows how to use the Bzip2 classes to uncompressed a file. * * @author Peter Donald * @author Nicola Ken Barozzi * @version $Revision: 1.1 $ $Date: 2003/12/02 20:44:24 $ */ public class Bzip2Uncompress { - public static void main(final String[] args) { - try { - if (2 != args.length) { - System.out.println("java Bzip2Uncompress "); - System.exit(1); - } - final File source = new File(args[0]); - final File destination = new File(args[1]); - final FileOutputStream output = new FileOutputStream(destination); - final BZip2CompressorInputStream input = new BZip2CompressorInputStream(new FileInputStream(source)); - copy(input, output); - input.close(); - output.close(); - } catch (Exception e) { - e.printStackTrace(); + public static void main(String[] args) throws Exception { + if (2 != args.length) { + System.out.println("java vavi.util.archive.bzip2.Bzip2Uncompress "); System.exit(1); } - } - /** - * Copy bytes from an InputStream to an OutputStream. - */ - private static void copy(final InputStream input, final OutputStream output) - throws IOException { - final byte[] buffer = new byte[8024]; - int n; - while (-1 != (n = input.read(buffer))) { - output.write(buffer, 0, n); - } + File source = new File(args[0]); + File destination = new File(args[1]); + BZip2CompressorInputStream input = new BZip2CompressorInputStream(Files.newInputStream(source.toPath())); + Files.copy(input, destination.toPath()); + input.close(); } } diff --git a/src/test/java/vavi/util/archive/gca/NativeGcaArchiveTest.java b/src/test/java/vavi/util/archive/gca/NativeGcaArchiveTest.java index e7ec74b..5e7d9e4 100644 --- a/src/test/java/vavi/util/archive/gca/NativeGcaArchiveTest.java +++ b/src/test/java/vavi/util/archive/gca/NativeGcaArchiveTest.java @@ -7,9 +7,9 @@ package vavi.util.archive.gca; import java.io.File; -import java.io.IOException; import java.io.InputStream; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledOnOs; import org.junit.jupiter.api.condition.OS; @@ -23,18 +23,19 @@ * @author Naohide Sano (umjammer) * @version 0.00 2020/05/12 umjammer initial version
*/ +@EnabledOnOs(OS.WINDOWS) class NativeGcaArchiveTest { @Test - @EnabledOnOs(OS.WINDOWS) - void test() throws IOException { + @Disabled("no test environment") + void test() throws Exception { main(new String[] { "src/test/resources/test.gca" }); } // ---- /** */ - public static void main(String[] args) throws IOException { + public static void main(String[] args) throws Exception { NativeGcaArchive gca = new NativeGcaArchive(new File(args[0])) { { System.err.println("gca: " + getVersion()); diff --git a/src/test/java/vavi/util/archive/lha/LhaArchiveTest.java b/src/test/java/vavi/util/archive/lha/LhaArchiveTest.java index 17391ab..deae5ca 100644 --- a/src/test/java/vavi/util/archive/lha/LhaArchiveTest.java +++ b/src/test/java/vavi/util/archive/lha/LhaArchiveTest.java @@ -70,7 +70,7 @@ public void test3() throws Exception { } /** - * @param args + * @param args 0: lha */ public static void main(String[] args) throws Exception { Path target = Paths.get(System.getenv("HOME"), args[0]); diff --git a/src/test/java/vavi/util/archive/rar/NativeRarArchiveTest.java b/src/test/java/vavi/util/archive/rar/NativeRarArchiveTest.java index 3efb31b..cf65214 100644 --- a/src/test/java/vavi/util/archive/rar/NativeRarArchiveTest.java +++ b/src/test/java/vavi/util/archive/rar/NativeRarArchiveTest.java @@ -7,7 +7,6 @@ package vavi.util.archive.rar; import java.io.File; -import java.io.IOException; import java.io.InputStream; import org.junit.jupiter.api.Disabled; @@ -26,11 +25,11 @@ * @author Naohide Sano (umjammer) * @version 0.00 2020/05/12 umjammer initial version
*/ +@EnabledOnOs(OS.WINDOWS) class NativeRarArchiveTest { @Test @Disabled - @EnabledOnOs(OS.WINDOWS) void test() { fail("Not yet implemented"); } @@ -38,7 +37,7 @@ void test() { // for Native method ------------------------------------------------------ /** */ - public static void main(String[] args) throws IOException { + public static void main(String[] args) throws Exception { NativeRarArchive rar = new NativeRarArchive(new File(args[0])) { { System.err.println("rar: " + getVersion()); @@ -51,7 +50,6 @@ public static void main(String[] args) throws IOException { Entry entry = rar.getEntry(args[1]); InputStream is = rar.getInputStream(entry); System.err.println("is: " + is); - System.exit(0); } } diff --git a/src/test/java/vavi/util/archive/sevenzip/ApacheSevenZipArchiveTest.java b/src/test/java/vavi/util/archive/sevenzip/ApacheSevenZipArchiveTest.java index 9fb9804..72dfbbf 100644 --- a/src/test/java/vavi/util/archive/sevenzip/ApacheSevenZipArchiveTest.java +++ b/src/test/java/vavi/util/archive/sevenzip/ApacheSevenZipArchiveTest.java @@ -50,7 +50,6 @@ public void test2() throws Exception { assertEquals(6, c); } - @Test @DisplayName("inputStream") void test5() throws Exception { diff --git a/src/test/java/vavi/util/archive/sevenzip/NativeSevenZipArchiveTest.java b/src/test/java/vavi/util/archive/sevenzip/NativeSevenZipArchiveTest.java index 6020f14..e9cb3e8 100644 --- a/src/test/java/vavi/util/archive/sevenzip/NativeSevenZipArchiveTest.java +++ b/src/test/java/vavi/util/archive/sevenzip/NativeSevenZipArchiveTest.java @@ -7,7 +7,6 @@ package vavi.util.archive.sevenzip; import java.io.File; -import java.io.IOException; import java.io.InputStream; import org.junit.jupiter.api.Test; @@ -27,14 +26,14 @@ class NativeSevenZipArchiveTest { @Test @EnabledOnOs(OS.WINDOWS) - void test() throws IOException { + void test() throws Exception { main(new String[] { "src/test/resources/test.sit" }); } // ---- /** java NativeSevenZipArchive sevenZipFile oneOfEntry */ - public static void main(String[] args) throws IOException { + public static void main(String[] args) throws Exception { NativeSevenZipArchive sevenZip = new NativeSevenZipArchive(new File(args[0])); Entry entry = sevenZip.getEntry(args[1]); InputStream is = sevenZip.getInputStream(entry); @@ -44,7 +43,6 @@ public static void main(String[] args) throws IOException { //System.err.println("size: " + sevenZip.getSelectedSize()); //System.err.println("csize: " + sevenZip.getSelectedCompressedSize()); //System.err.println("ratio: " + sevenZip.getSelectedRatio()); - System.exit(0); } } diff --git a/src/test/java/vavi/util/archive/stuffit/NativeStuffItArchiveTest.java b/src/test/java/vavi/util/archive/stuffit/NativeStuffItArchiveTest.java index f3a811e..ee173c0 100644 --- a/src/test/java/vavi/util/archive/stuffit/NativeStuffItArchiveTest.java +++ b/src/test/java/vavi/util/archive/stuffit/NativeStuffItArchiveTest.java @@ -7,7 +7,6 @@ package vavi.util.archive.stuffit; import java.io.File; -import java.io.IOException; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledOnOs; @@ -22,18 +21,18 @@ * @author Naohide Sano (umjammer) * @version 0.00 2020/05/12 umjammer initial version
*/ +@EnabledOnOs(OS.WINDOWS) class NativeStuffItArchiveTest { @Test - @EnabledOnOs(OS.WINDOWS) - void test() throws IOException { + void test() throws Exception { main(new String[] { "src/test/resources/test.sit" }); } // ---- /** */ - public static void main(String[] args) throws IOException { + public static void main(String[] args) throws Exception { NativeStuffItArchive sit = new NativeStuffItArchive(new File(args[0])) {{ System.err.println("sit: " + getVersion()); }}; @@ -47,7 +46,6 @@ public static void main(String[] args) throws IOException { for (Entry entry : sit.entries()) { System.err.println("entry: " + entry); } - System.exit(0); } } diff --git a/src/test/java/vavi/util/archive/zip/JdkZipArchiveTest.java b/src/test/java/vavi/util/archive/zip/JdkZipArchiveTest.java index 24a9f67..3bcf781 100644 --- a/src/test/java/vavi/util/archive/zip/JdkZipArchiveTest.java +++ b/src/test/java/vavi/util/archive/zip/JdkZipArchiveTest.java @@ -21,6 +21,7 @@ import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; +import java.util.zip.ZipException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -37,6 +38,7 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -113,8 +115,8 @@ void test22() throws Exception { } }); Debug.println("exception cause: " + e.getMessage()); - assertInstanceOf(IllegalArgumentException.class, e.getCause()); - assertEquals("MALFORMED", e.getCause().getMessage()); + assertInstanceOf(ZipException.class, e.getCause()); + assertTrue(e.getCause().getMessage().contains("invalid CEN header")); } @Test @@ -150,8 +152,8 @@ void test25() throws Exception { Path path = Paths.get(file932); IOException e = assertThrows(IOException.class, () -> Archives.getArchive(path.toFile())); Debug.println("exception cause: " + e.getMessage()); - assertInstanceOf(IllegalArgumentException.class, e.getCause()); - assertEquals("MALFORMED", e.getCause().getMessage()); + assertInstanceOf(ZipException.class, e.getCause()); + assertTrue(e.getCause().getMessage().contains("invalid CEN header")); } /** until Predicate#not release */ diff --git a/src/test/java/vavi/util/codec/cpio/cpio.java b/src/test/java/vavi/util/codec/cpio/cpio.java index 29e9754..f0ce8ef 100644 --- a/src/test/java/vavi/util/codec/cpio/cpio.java +++ b/src/test/java/vavi/util/codec/cpio/cpio.java @@ -6,6 +6,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Paths; public class cpio { @@ -57,7 +59,7 @@ private void processArguments(String[] args) throws IOException { break; case "-I": String archFile = args[++i]; - this.inStream = new FileInputStream(archFile); + this.inStream = Files.newInputStream(Paths.get(archFile)); break; case "--basedir": String baseDir = args[++i];