From e0a4a1188bb8c635c8e75d020e371a3df2d4d7f8 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Sat, 18 May 2024 02:16:27 +0200 Subject: [PATCH] [WIP] Update dependencies, small optimizations --- .../datromtool/command/OneGameOneRom.java | 7 +- .../io/github/datromtool/io/ArchiveType.java | 20 ++-- .../io/github/datromtool/io/FileCopier.java | 94 ++++++++----------- .../SevenZipArchiveSourceInternalSpec.java | 6 +- .../impl/SevenZipArchiveSourceSpec.java | 2 +- .../impl/TarArchiveSourceInternalSpec.java | 7 +- .../archive/impl/TarArchiveSourceSpec.java | 2 +- .../archive/impl/ZipArchiveSourceSpec.java | 2 +- .../ProcessArchiveSourceInternalSpec.java | 4 +- .../github/datromtool/util/ArchiveUtils.java | 20 +++- .../io/ArchiveContentsDependantTest.java | 4 +- .../github/datromtool/io/FileCopierTest.java | 6 +- .../SevenZipArchiveDestinationSpecTest.java | 2 +- .../impl/TarArchiveDestinationSpecTest.java | 2 +- .../impl/ZipArchiveDestinationSpecTest.java | 2 +- .../compression/CompressionAlgorithmTest.java | 8 +- .../copy/impl/FileSourceDestinationTest.java | 2 +- pom.xml | 81 +++++++++------- 18 files changed, 144 insertions(+), 127 deletions(-) diff --git a/core/src/main/java/io/github/datromtool/command/OneGameOneRom.java b/core/src/main/java/io/github/datromtool/command/OneGameOneRom.java index ce267cc..21c327d 100644 --- a/core/src/main/java/io/github/datromtool/command/OneGameOneRom.java +++ b/core/src/main/java/io/github/datromtool/command/OneGameOneRom.java @@ -47,6 +47,7 @@ import java.util.Objects; import java.util.Optional; import java.util.function.Consumer; +import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -447,7 +448,7 @@ private static Stream simpleCopyOrExtractionStream( .from(m.getResult().getArchivePath()) .to(baseDir.resolve(m.getRom().getName())) .build()) - .collect(ImmutableSet.toImmutableSet())) + .collect(ImmutableMap.toImmutableMap(FileCopier.ExtractionSpec.InternalSpec::getFrom, Function.identity(), (a, b) -> a))) .build()); } }); @@ -489,7 +490,7 @@ private static Stream buildCompressionSpecs( List forCompression = matches .stream() .filter(m -> m.getResult().getArchiveType() == null) - .collect(Collectors.toList()); + .toList(); Stream compressions; if (forCompression.isEmpty()) { compressions = Stream.empty(); @@ -537,7 +538,7 @@ private static FileCopier.ArchiveCopySpec buildArchiveCopySpec( .from(m.getResult().getArchivePath()) .to(m.getRom().getName()) .build()) - .collect(ImmutableSet.toImmutableSet())) + .collect(ImmutableMap.toImmutableMap(FileCopier.ArchiveCopySpec.InternalSpec::getFrom, Function.identity(), (a, b) -> a))) .build(); } diff --git a/core/src/main/java/io/github/datromtool/io/ArchiveType.java b/core/src/main/java/io/github/datromtool/io/ArchiveType.java index 49e3fe0..fdf9012 100644 --- a/core/src/main/java/io/github/datromtool/io/ArchiveType.java +++ b/core/src/main/java/io/github/datromtool/io/ArchiveType.java @@ -17,7 +17,9 @@ import java.util.function.Predicate; import java.util.regex.Pattern; -import static java.util.regex.Pattern.*; +import static java.util.regex.Pattern.CASE_INSENSITIVE; +import static java.util.regex.Pattern.compile; +import static java.util.regex.Pattern.quote; @AllArgsConstructor public enum ArchiveType { @@ -50,13 +52,13 @@ private static boolean isTar(String s) { } private static boolean isBzip2(String s) { - return BZip2Utils.isCompressedFilename(s) - && Constants.TAR_PATTERN.matcher(BZip2Utils.getUncompressedFilename(s)).find(); + return BZip2Utils.isCompressedFileName(s) + && Constants.TAR_PATTERN.matcher(BZip2Utils.getUncompressedFileName(s)).find(); } private static boolean isGzip(String s) { - return GzipUtils.isCompressedFilename(s) - && Constants.TAR_PATTERN.matcher(GzipUtils.getUncompressedFilename(s)).find(); + return GzipUtils.isCompressedFileName(s) + && Constants.TAR_PATTERN.matcher(GzipUtils.getUncompressedFileName(s)).find(); } private static boolean isLz4(String s) { @@ -65,14 +67,14 @@ private static boolean isLz4(String s) { private static boolean isTarLzma(String s) { return LZMAUtils.isLZMACompressionAvailable() - && LZMAUtils.isCompressedFilename(s) - && Constants.TAR_PATTERN.matcher(LZMAUtils.getUncompressedFilename(s)).find(); + && LZMAUtils.isCompressedFileName(s) + && Constants.TAR_PATTERN.matcher(LZMAUtils.getUncompressedFileName(s)).find(); } private static boolean isTarXz(String s) { return XZUtils.isXZCompressionAvailable() - && XZUtils.isCompressedFilename(s) - && Constants.TAR_PATTERN.matcher(XZUtils.getUncompressedFilename(s)).find(); + && XZUtils.isCompressedFileName(s) + && Constants.TAR_PATTERN.matcher(XZUtils.getUncompressedFileName(s)).find(); } @Getter(onMethod_ = {@JsonValue}) diff --git a/core/src/main/java/io/github/datromtool/io/FileCopier.java b/core/src/main/java/io/github/datromtool/io/FileCopier.java index b1088d6..0ccb734 100644 --- a/core/src/main/java/io/github/datromtool/io/FileCopier.java +++ b/core/src/main/java/io/github/datromtool/io/FileCopier.java @@ -3,6 +3,7 @@ import com.github.junrar.exception.RarException; import com.github.junrar.exception.UnsupportedRarV5Exception; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import io.github.datromtool.config.AppConfig; import io.github.datromtool.io.logging.FileCopierLoggingListener; @@ -14,7 +15,6 @@ import lombok.NonNull; import lombok.Value; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry; import org.apache.commons.compress.archivers.sevenz.SevenZOutputFile; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; @@ -107,7 +107,7 @@ public static class InternalSpec { @NonNull Path from; @NonNull - ImmutableSet internalSpecs; + ImmutableMap internalSpecs; } @Builder @@ -161,7 +161,7 @@ public static class InternalSpec { @NonNull Path to; @NonNull - ImmutableSet internalSpecs; + ImmutableMap internalSpecs; } public interface Listener { @@ -410,7 +410,7 @@ private void extractZipEntries(ExtractionSpec spec, int index) throws IOExceptio } catch (FileAlreadyExistsException e) { throw e; } catch (IOException e) { - Files.delete(to); + Files.deleteIfExists(to); throw e; } BasicFileAttributeView toAttrib = Files.getFileAttributeView(to, BasicFileAttributeView.class); @@ -442,7 +442,7 @@ private void extractRarEntries(ExtractionSpec spec, int index) throws Exception } catch (FileAlreadyExistsException e) { throw e; } catch (IOException e) { - Files.delete(to); + Files.deleteIfExists(to); throw e; } BasicFileAttributeView toAttrib = Files.getFileAttributeView(to, BasicFileAttributeView.class); @@ -461,9 +461,7 @@ private void extractRarEntries(ExtractionSpec spec, int index) throws Exception } private void extractRarEntriesWithUnrar(ExtractionSpec spec, int index) throws Exception { - ImmutableSet desiredEntryNames = spec.getInternalSpecs().stream() - .map(ExtractionSpec.InternalSpec::getFrom) - .collect(ImmutableSet.toImmutableSet()); + ImmutableSet desiredEntryNames = spec.getInternalSpecs().keySet(); ArchiveUtils.readRarWithUnrar( spec.getFrom(), desiredEntryNames, @@ -471,9 +469,7 @@ private void extractRarEntriesWithUnrar(ExtractionSpec spec, int index) throws E } private void extractRarEntriesWithSevenZip(ExtractionSpec spec, int index) throws Exception { - ImmutableSet desiredEntryNames = spec.getInternalSpecs().stream() - .map(ExtractionSpec.InternalSpec::getFrom) - .collect(ImmutableSet.toImmutableSet()); + ImmutableSet desiredEntryNames = spec.getInternalSpecs().keySet(); ArchiveUtils.readRarWithSevenZip( spec.getFrom(), desiredEntryNames, @@ -504,7 +500,7 @@ private void processRarEntry( } catch (FileAlreadyExistsException e) { throw e; } catch (IOException e) { - Files.delete(to); + Files.deleteIfExists(to); throw e; } BasicFileAttributeView toAttrib = Files.getFileAttributeView(to, BasicFileAttributeView.class); @@ -526,7 +522,7 @@ private void extractSevenZipEntries(ExtractionSpec spec, int index) throws IOExc } catch (FileAlreadyExistsException e) { throw e; } catch (IOException e) { - Files.delete(to); + Files.deleteIfExists(to); throw e; } BasicFileAttributeView toAttrib = Files.getFileAttributeView(to, BasicFileAttributeView.class); @@ -561,7 +557,7 @@ private void extractTarEntries(ExtractionSpec spec, int index) throws IOExceptio } catch (FileAlreadyExistsException e) { throw e; } catch (IOException e) { - Files.delete(to); + Files.deleteIfExists(to); throw e; } BasicFileAttributeView toAttrib = Files.getFileAttributeView(to, BasicFileAttributeView.class); @@ -574,7 +570,7 @@ private void compressZipEntries(CompressionSpec spec, int index) throws IOExcept for (CompressionSpec.InternalSpec internal : spec.getInternalSpecs()) { Path source = internal.getFrom(); try (InputStream inputStream = Files.newInputStream(source)) { - ZipArchiveEntry archiveEntry = (ZipArchiveEntry) zipArchiveOutputStream.createArchiveEntry( + ZipArchiveEntry archiveEntry = zipArchiveOutputStream.createArchiveEntry( source.toFile(), internal.getTo()); BasicFileAttributes fromAttrib = Files.readAttributes(source, BasicFileAttributes.class); @@ -594,7 +590,7 @@ private void compressZipEntries(CompressionSpec spec, int index) throws IOExcept } catch (FileAlreadyExistsException e) { throw e; } catch (IOException e) { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } @@ -624,7 +620,7 @@ private void compressSevenZipEntries(CompressionSpec spec, int index) throws IOE } catch (FileAlreadyExistsException e) { throw e; } catch (IOException e) { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } @@ -638,7 +634,7 @@ private void compressTarEntries(CompressionSpec spec, int index) throws IOExcept for (CompressionSpec.InternalSpec internal : spec.getInternalSpecs()) { Path source = internal.getFrom(); try (InputStream inputStream = Files.newInputStream(source)) { - ArchiveEntry archiveEntry = + TarArchiveEntry archiveEntry = tarOutputStream.createArchiveEntry(source.toFile(), internal.getTo()); Path destination = spec.getTo().resolve(internal.getTo()); tarOutputStream.putArchiveEntry(archiveEntry); @@ -655,7 +651,7 @@ private void compressTarEntries(CompressionSpec spec, int index) throws IOExcept } catch (FileAlreadyExistsException e) { throw e; } catch (IOException e) { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } @@ -732,7 +728,7 @@ private void fromZipToZipRaw(ArchiveCopySpec spec, int index) throws IOException } catch (FileAlreadyExistsException e) { throw e; } catch (IOException e) { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } @@ -764,7 +760,7 @@ private void fromZipToZip(ArchiveCopySpec spec, int index) throws IOException { } catch (FileAlreadyExistsException e) { throw e; } catch (IOException e) { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } @@ -796,7 +792,7 @@ private void fromZipToSevenZip(ArchiveCopySpec spec, int index) throws IOExcepti } catch (FileAlreadyExistsException e) { throw e; } catch (IOException e) { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } @@ -830,7 +826,7 @@ private void fromZipToTar(ArchiveCopySpec spec, int index) throws IOException { } catch (FileAlreadyExistsException e) { throw e; } catch (IOException e) { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } @@ -867,11 +863,11 @@ private void fromRarToZip(ArchiveCopySpec spec, int index) throws Exception { } else if (isUseSevenZip()) { fromRarWithSevenZipToZip(spec, index); } else { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } catch (IOException | RarException e) { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } @@ -886,7 +882,7 @@ private void fromRarWithUnrarToZip(ArchiveCopySpec spec, int index) throws Excep } catch (FileAlreadyExistsException e) { throw e; } catch (IOException | RarException e) { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } @@ -901,7 +897,7 @@ private void fromRarWithSevenZipToZip(ArchiveCopySpec spec, int index) throws Ex } catch (FileAlreadyExistsException e) { throw e; } catch (IOException | RarException e) { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } @@ -962,11 +958,11 @@ private void fromRarToSevenZip(ArchiveCopySpec spec, int index) throws Exception } else if (isUseSevenZip()) { fromRarWithSevenZipToSevenZip(spec, index); } else { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } catch (IOException | RarException e) { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } @@ -981,7 +977,7 @@ private void fromRarWithUnrarToSevenZip(ArchiveCopySpec spec, int index) throws } catch (FileAlreadyExistsException e) { throw e; } catch (IOException | RarException e) { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } @@ -996,7 +992,7 @@ private void fromRarWithSevenZipToSevenZip(ArchiveCopySpec spec, int index) thro } catch (FileAlreadyExistsException e) { throw e; } catch (IOException | RarException e) { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } @@ -1059,11 +1055,11 @@ private void fromRarToTar(ArchiveCopySpec spec, int index) throws Exception { } else if (isUseSevenZip()) { fromRarWithSevenZipToTar(spec, index); } else { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } catch (IOException | RarException e) { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } @@ -1092,7 +1088,7 @@ private void fromRarWithUnrarToTar( } catch (FileAlreadyExistsException e) { throw e; } catch (IOException | RarException e) { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } @@ -1113,7 +1109,7 @@ private void fromRarWithSevenZipToTar( } catch (FileAlreadyExistsException e) { throw e; } catch (IOException | RarException e) { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } @@ -1163,14 +1159,14 @@ private void fromSevenZipToZip(ArchiveCopySpec spec, int index) throws IOExcepti } catch (FileAlreadyExistsException e) { throw e; } catch (IOException e) { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } private void fromSevenZipToSevenZip(ArchiveCopySpec spec, int index) throws IOException { try (SevenZOutputFile sevenZOutputFile = - new SevenZOutputFile(spec.getTo().toFile())) { + new SevenZOutputFile(spec.getTo().toFile())) { ArchiveUtils.readSevenZip( spec.getFrom(), (sevenZFile, sevenZArchiveEntry) -> toSevenZip( @@ -1192,7 +1188,7 @@ private void fromSevenZipToSevenZip(ArchiveCopySpec spec, int index) throws IOEx } catch (FileAlreadyExistsException e) { throw e; } catch (IOException e) { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } @@ -1218,7 +1214,7 @@ private void fromSevenZipToTar(ArchiveCopySpec spec, int index) throws IOExcepti } catch (FileAlreadyExistsException e) { throw e; } catch (IOException e) { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } @@ -1242,7 +1238,7 @@ private void fromTarToZip(ArchiveCopySpec spec, int index) } catch (FileAlreadyExistsException e) { throw e; } catch (IOException e) { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } @@ -1265,7 +1261,7 @@ private void fromTarToSevenZip(ArchiveCopySpec spec, int index) throws IOExcepti } catch (FileAlreadyExistsException e) { throw e; } catch (IOException e) { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } @@ -1290,15 +1286,13 @@ private void fromTarToTar(ArchiveCopySpec spec, int index) throws IOException { } catch (FileAlreadyExistsException e) { throw e; } catch (IOException e) { - Files.delete(spec.getTo()); + Files.deleteIfExists(spec.getTo()); throw e; } } private static ImmutableSet getInternalSources(ArchiveCopySpec spec) { - return spec.getInternalSpecs().stream() - .map(ArchiveCopySpec.InternalSpec::getFrom) - .collect(ImmutableSet.toImmutableSet()); + return spec.getInternalSpecs().keySet(); } private void toZip( @@ -1561,18 +1555,12 @@ private static FileTime from(@Nullable LocalDateTime date) { @Nullable private ExtractionSpec.InternalSpec findInternalSpec(ExtractionSpec spec, String name) { - return spec.getInternalSpecs().stream() - .filter(ad -> ad.getFrom().equals(name)) - .findFirst() - .orElse(null); + return spec.getInternalSpecs().get(name); } @Nullable private ArchiveCopySpec.InternalSpec findInternalSpec(ArchiveCopySpec spec, String name) { - return spec.getInternalSpecs().stream() - .filter(ad -> ad.getFrom().equals(name)) - .findFirst() - .orElse(null); + return spec.getInternalSpecs().get(name); } private void copyWithProgress( diff --git a/core/src/main/java/io/github/datromtool/io/copy/archive/impl/SevenZipArchiveSourceInternalSpec.java b/core/src/main/java/io/github/datromtool/io/copy/archive/impl/SevenZipArchiveSourceInternalSpec.java index 3a0d5de..3f0adb6 100644 --- a/core/src/main/java/io/github/datromtool/io/copy/archive/impl/SevenZipArchiveSourceInternalSpec.java +++ b/core/src/main/java/io/github/datromtool/io/copy/archive/impl/SevenZipArchiveSourceInternalSpec.java @@ -8,7 +8,7 @@ import lombok.RequiredArgsConstructor; import org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry; import org.apache.commons.compress.archivers.sevenz.SevenZFile; -import org.apache.commons.compress.utils.BoundedInputStream; +import org.apache.commons.io.input.BoundedInputStream; import javax.annotation.Nonnull; import java.io.IOException; @@ -47,7 +47,7 @@ public FileTimes getFileTimes() { } @Override - public InputStream getInputStream() throws IOException { + public InputStream getInputStream() { if (inputStream == null) { inputStream = new BoundedInputStream(new SevenZFileInputStream(sevenZFile), sevenZArchiveEntry.getSize()); } @@ -55,7 +55,7 @@ public InputStream getInputStream() throws IOException { } @Override - public void close() throws IOException { + public void close() { // No need to close this InputStream inputStream = null; } diff --git a/core/src/main/java/io/github/datromtool/io/copy/archive/impl/SevenZipArchiveSourceSpec.java b/core/src/main/java/io/github/datromtool/io/copy/archive/impl/SevenZipArchiveSourceSpec.java index 37155bd..716c159 100644 --- a/core/src/main/java/io/github/datromtool/io/copy/archive/impl/SevenZipArchiveSourceSpec.java +++ b/core/src/main/java/io/github/datromtool/io/copy/archive/impl/SevenZipArchiveSourceSpec.java @@ -26,7 +26,7 @@ public SevenZipArchiveSourceSpec(@Nonnull Path path, @Nonnull Iterable n @Override protected void initArchive() throws IOException { if (sevenZFile == null) { - sevenZFile = new SevenZFile(getPath().toFile()); + sevenZFile = SevenZFile.builder().setPath(getPath()).get(); } } diff --git a/core/src/main/java/io/github/datromtool/io/copy/archive/impl/TarArchiveSourceInternalSpec.java b/core/src/main/java/io/github/datromtool/io/copy/archive/impl/TarArchiveSourceInternalSpec.java index d24796b..ce5cda4 100644 --- a/core/src/main/java/io/github/datromtool/io/copy/archive/impl/TarArchiveSourceInternalSpec.java +++ b/core/src/main/java/io/github/datromtool/io/copy/archive/impl/TarArchiveSourceInternalSpec.java @@ -8,10 +8,9 @@ import lombok.RequiredArgsConstructor; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; -import org.apache.commons.compress.utils.BoundedInputStream; +import org.apache.commons.io.input.BoundedInputStream; import javax.annotation.Nullable; -import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; import java.nio.file.attribute.FileTime; @@ -75,7 +74,7 @@ private static FileTime fromEpochSeconds(@Nullable String seconds, @Nullable Dat } @Override - public InputStream getInputStream() throws IOException { + public InputStream getInputStream() { if (inputStream == null) { inputStream = new BoundedInputStream(tarArchiveInputStream, tarArchiveEntry.getRealSize()); } @@ -83,7 +82,7 @@ public InputStream getInputStream() throws IOException { } @Override - public void close() throws IOException { + public void close() { // No need to close this InputStream inputStream = null; } diff --git a/core/src/main/java/io/github/datromtool/io/copy/archive/impl/TarArchiveSourceSpec.java b/core/src/main/java/io/github/datromtool/io/copy/archive/impl/TarArchiveSourceSpec.java index c867615..841bd72 100644 --- a/core/src/main/java/io/github/datromtool/io/copy/archive/impl/TarArchiveSourceSpec.java +++ b/core/src/main/java/io/github/datromtool/io/copy/archive/impl/TarArchiveSourceSpec.java @@ -55,7 +55,7 @@ protected void initArchive() throws IOException { @Override protected ArchiveSourceInternalSpec getNextEntry() throws IOException { TarArchiveEntry tarArchiveEntry; - while ((tarArchiveEntry = tarArchiveInputStream.getNextTarEntry()) != null) { + while ((tarArchiveEntry = tarArchiveInputStream.getNextEntry()) != null) { if (tarArchiveEntry.isFile() && tarArchiveInputStream.canReadEntryData(tarArchiveEntry)) { return new TarArchiveSourceInternalSpec(this, tarArchiveInputStream, tarArchiveEntry); } diff --git a/core/src/main/java/io/github/datromtool/io/copy/archive/impl/ZipArchiveSourceSpec.java b/core/src/main/java/io/github/datromtool/io/copy/archive/impl/ZipArchiveSourceSpec.java index b6b6be8..27ce35f 100644 --- a/core/src/main/java/io/github/datromtool/io/copy/archive/impl/ZipArchiveSourceSpec.java +++ b/core/src/main/java/io/github/datromtool/io/copy/archive/impl/ZipArchiveSourceSpec.java @@ -28,7 +28,7 @@ public ZipArchiveSourceSpec(@Nonnull Path path, @Nonnull Iterable names) @Override protected void initArchive() throws IOException { if (zipFile == null) { - zipFile = new ZipFile(getPath().toFile()); + zipFile = ZipFile.builder().setPath(getPath()).get(); } if (entries == null) { entries = zipFile.getEntriesInPhysicalOrder(); diff --git a/core/src/main/java/io/github/datromtool/io/copy/archive/impl/process/ProcessArchiveSourceInternalSpec.java b/core/src/main/java/io/github/datromtool/io/copy/archive/impl/process/ProcessArchiveSourceInternalSpec.java index 8a929d5..245067a 100644 --- a/core/src/main/java/io/github/datromtool/io/copy/archive/impl/process/ProcessArchiveSourceInternalSpec.java +++ b/core/src/main/java/io/github/datromtool/io/copy/archive/impl/process/ProcessArchiveSourceInternalSpec.java @@ -7,7 +7,7 @@ import lombok.Getter; import lombok.NonNull; import lombok.RequiredArgsConstructor; -import org.apache.commons.compress.utils.BoundedInputStream; +import org.apache.commons.io.input.BoundedInputStream; import javax.annotation.Nonnull; import java.io.IOException; @@ -44,7 +44,7 @@ public FileTimes getFileTimes() { } @Override - public InputStream getInputStream() throws IOException { + public InputStream getInputStream() { if (inputStream == null) { inputStream = new BoundedInputStream(processInputStream, file.getSize()); } diff --git a/core/src/main/java/io/github/datromtool/util/ArchiveUtils.java b/core/src/main/java/io/github/datromtool/util/ArchiveUtils.java index 039896f..d3fff5b 100644 --- a/core/src/main/java/io/github/datromtool/util/ArchiveUtils.java +++ b/core/src/main/java/io/github/datromtool/util/ArchiveUtils.java @@ -29,8 +29,18 @@ import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream; import javax.annotation.Nullable; -import java.io.*; -import java.nio.file.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.StandardCopyOption; import java.nio.file.attribute.BasicFileAttributes; import java.time.LocalDateTime; import java.util.Enumeration; @@ -114,7 +124,7 @@ public static OutputStream outputStreamForTar(ArchiveType archiveType, Path file public static void readZip( Path file, ThrowingBiConsumer consumer) throws IOException, T { - try (ZipFile zipFile = new ZipFile(file.toFile())) { + try (ZipFile zipFile = ZipFile.builder().setPath(file).get()) { Enumeration entries = zipFile.getEntriesInPhysicalOrder(); while (entries.hasMoreElements()) { ZipArchiveEntry zipArchiveEntry = entries.nextElement(); @@ -586,7 +596,7 @@ public static void readSevenZip( Path file, ThrowingBiConsumer consumer) throws IOException, T { - try (SevenZFile sevenZFile = new SevenZFile(file.toFile())) { + try (SevenZFile sevenZFile = SevenZFile.builder().setPath(file).get()) { SevenZArchiveEntry sevenZArchiveEntry; while ((sevenZArchiveEntry = sevenZFile.getNextEntry()) != null) { if (sevenZArchiveEntry.isDirectory() || sevenZArchiveEntry.isAntiItem()) { @@ -606,7 +616,7 @@ public static void readTar( if (inputStream != null) { try (TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(inputStream)) { TarArchiveEntry tarArchiveEntry; - while ((tarArchiveEntry = tarArchiveInputStream.getNextTarEntry()) != null) { + while ((tarArchiveEntry = tarArchiveInputStream.getNextEntry()) != null) { if (!tarArchiveEntry.isFile() || !tarArchiveInputStream.canReadEntryData(tarArchiveEntry)) { continue; diff --git a/core/src/test/java/io/github/datromtool/io/ArchiveContentsDependantTest.java b/core/src/test/java/io/github/datromtool/io/ArchiveContentsDependantTest.java index 8b4db67..1f1d53f 100644 --- a/core/src/test/java/io/github/datromtool/io/ArchiveContentsDependantTest.java +++ b/core/src/test/java/io/github/datromtool/io/ArchiveContentsDependantTest.java @@ -4,7 +4,7 @@ import io.github.datromtool.io.copy.FileTimes; import io.github.datromtool.io.copy.SourceSpec; import io.github.datromtool.io.copy.archive.ArchiveSourceInternalSpec; -import org.apache.commons.compress.utils.IOUtils; +import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.BeforeAll; import javax.annotation.Nonnull; @@ -128,7 +128,7 @@ private static FileTime toFileTime(int year, int month, int day, int hour, int m Calendar calendar = Calendar.getInstance(); calendar.set(year, month, day, hour, minute, second); calendar.set(Calendar.MILLISECOND, millis); - return FileTime.from(Instant.ofEpochMilli(calendar.getTimeInMillis()).plus(nanos, ChronoUnit.NANOS)); + return FileTime.from(Instant.ofEpochMilli(calendar.getTimeInMillis()).plus(nanos, ChronoUnit.NANOS)); } protected static void assertIsShortText(ArchiveSourceInternalSpec internalSpec, boolean convertTimeZone, DateField... dateFields) throws IOException { diff --git a/core/src/test/java/io/github/datromtool/io/FileCopierTest.java b/core/src/test/java/io/github/datromtool/io/FileCopierTest.java index bb0da31..8b08250 100644 --- a/core/src/test/java/io/github/datromtool/io/FileCopierTest.java +++ b/core/src/test/java/io/github/datromtool/io/FileCopierTest.java @@ -1,6 +1,7 @@ package io.github.datromtool.io; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import io.github.datromtool.TestDirDependantTest; import io.github.datromtool.config.AppConfig; @@ -16,6 +17,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.function.Function; import java.util.stream.Collectors; import static io.github.datromtool.util.ArchiveUtils.normalizePath; @@ -75,7 +77,7 @@ void testCopy() { .from(p) .to(p) .build()) - .collect(ImmutableSet.toImmutableSet())) + .collect(ImmutableMap.toImmutableMap(FileCopier.ArchiveCopySpec.InternalSpec::getFrom, Function.identity(), (a, b) -> a))) .build(); } return FileCopier.ArchiveCopySpec.builder() @@ -89,7 +91,7 @@ void testCopy() { .from(p) .to(p) .build()) - .collect(ImmutableSet.toImmutableSet())) + .collect(ImmutableMap.toImmutableMap(FileCopier.ArchiveCopySpec.InternalSpec::getFrom, Function.identity(), (a, b) -> a))) .build(); }).collect(ImmutableSet.toImmutableSet()); FileCopier fc = new FileCopier(AppConfig.FileCopierConfig.builder().build(), ImmutableList.of()); diff --git a/core/src/test/java/io/github/datromtool/io/copy/archive/impl/SevenZipArchiveDestinationSpecTest.java b/core/src/test/java/io/github/datromtool/io/copy/archive/impl/SevenZipArchiveDestinationSpecTest.java index 5b980ac..5ff8e85 100644 --- a/core/src/test/java/io/github/datromtool/io/copy/archive/impl/SevenZipArchiveDestinationSpecTest.java +++ b/core/src/test/java/io/github/datromtool/io/copy/archive/impl/SevenZipArchiveDestinationSpecTest.java @@ -6,7 +6,7 @@ import io.github.datromtool.io.copy.archive.ArchiveDestinationSpec; import io.github.datromtool.io.copy.impl.FileSourceSpec; import io.github.datromtool.util.ArchiveUtils; -import org.apache.commons.compress.utils.IOUtils; +import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/core/src/test/java/io/github/datromtool/io/copy/archive/impl/TarArchiveDestinationSpecTest.java b/core/src/test/java/io/github/datromtool/io/copy/archive/impl/TarArchiveDestinationSpecTest.java index c859938..32a7cc8 100644 --- a/core/src/test/java/io/github/datromtool/io/copy/archive/impl/TarArchiveDestinationSpecTest.java +++ b/core/src/test/java/io/github/datromtool/io/copy/archive/impl/TarArchiveDestinationSpecTest.java @@ -8,7 +8,7 @@ import io.github.datromtool.io.copy.impl.FileSourceSpec; import io.github.datromtool.util.ArchiveUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.compress.utils.IOUtils; +import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; diff --git a/core/src/test/java/io/github/datromtool/io/copy/archive/impl/ZipArchiveDestinationSpecTest.java b/core/src/test/java/io/github/datromtool/io/copy/archive/impl/ZipArchiveDestinationSpecTest.java index effbc3d..78dad1a 100644 --- a/core/src/test/java/io/github/datromtool/io/copy/archive/impl/ZipArchiveDestinationSpecTest.java +++ b/core/src/test/java/io/github/datromtool/io/copy/archive/impl/ZipArchiveDestinationSpecTest.java @@ -6,7 +6,7 @@ import io.github.datromtool.io.copy.archive.ArchiveDestinationSpec; import io.github.datromtool.io.copy.impl.FileSourceSpec; import io.github.datromtool.util.ArchiveUtils; -import org.apache.commons.compress.utils.IOUtils; +import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/core/src/test/java/io/github/datromtool/io/copy/compression/CompressionAlgorithmTest.java b/core/src/test/java/io/github/datromtool/io/copy/compression/CompressionAlgorithmTest.java index 0727804..4c2f25b 100644 --- a/core/src/test/java/io/github/datromtool/io/copy/compression/CompressionAlgorithmTest.java +++ b/core/src/test/java/io/github/datromtool/io/copy/compression/CompressionAlgorithmTest.java @@ -3,12 +3,16 @@ import io.github.datromtool.io.ArchiveContentsDependantTest; import io.github.datromtool.io.compression.CompressionAlgorithm; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.compress.utils.IOUtils; +import org.apache.commons.io.IOUtils; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; diff --git a/core/src/test/java/io/github/datromtool/io/copy/impl/FileSourceDestinationTest.java b/core/src/test/java/io/github/datromtool/io/copy/impl/FileSourceDestinationTest.java index 0552817..e376101 100644 --- a/core/src/test/java/io/github/datromtool/io/copy/impl/FileSourceDestinationTest.java +++ b/core/src/test/java/io/github/datromtool/io/copy/impl/FileSourceDestinationTest.java @@ -4,7 +4,7 @@ import io.github.datromtool.io.copy.DestinationSpec; import io.github.datromtool.io.copy.SourceSpec; import io.github.datromtool.util.ArchiveUtils; -import org.apache.commons.compress.utils.IOUtils; +import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/pom.xml b/pom.xml index 62740de..9a92707 100644 --- a/pom.xml +++ b/pom.xml @@ -33,23 +33,34 @@ UTF-8 17 - 5.9.2 - 2.0.0 - 1.18.26 - 1.23.0 - 3.12.0 - 1.15 - 4.7.1 - 2.0.7 - 1.4.6 - 31.1-jre - 2.14.2 + 5.10.2 + 2.2.0 + 1.18.32 + 1.26.1 + 3.14.0 + 1.17.0 + 4.7.6 + 2.0.13 + 1.5.6 + 33.2.0-jre + 2.17.1 1.9 - 7.5.4 - 5.0.0 - 5.2.0 - 3.23.0 - 2.4.0 + 7.5.5 + 8.0.2 + 5.12.0 + 3.26.1 + 2.4.1 + 2.16.2 + 2.1.0 + 2.1.0 + + 3.13.0 + 3.2.5 + 3.7.1 + 3.4.1 + 3.1.2 + 3.1.2 + 3.0.1 @@ -156,41 +167,41 @@ maven-compiler-plugin - 3.10.1 + ${maven-compiler-plugin.version} maven-surefire-plugin - 3.0.0 + ${maven-surefire-plugin.version} maven-assembly-plugin - 3.5.0 - - - org.codehaus.mojo - versions-maven-plugin - 2.15.0 - - - io.github.git-commit-id - git-commit-id-maven-plugin - ${git-commit-id-maven-plugin.version} + ${maven-assembly-plugin.version} maven-jar-plugin - 3.3.0 + ${maven-jar-plugin.version} maven-install-plugin - 3.1.1 + ${maven-install-plugin.version} maven-deploy-plugin - 3.1.1 + ${maven-deploy-plugin.version} maven-release-plugin - 3.0.0 + ${maven-release-plugin.version} + + + org.codehaus.mojo + versions-maven-plugin + ${versions-maven-plugin.version} + + + io.github.git-commit-id + git-commit-id-maven-plugin + ${git-commit-id-maven-plugin.version} @@ -233,12 +244,12 @@ org.apache.maven.scm maven-scm-provider-gitexe - 2.0.0-M1 + ${maven-scm-provider-gitexe.version} org.apache.maven.scm maven-scm-api - 2.0.0-M1 + ${maven-scm-api.version}