This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git
The following commit(s) were added to refs/heads/master by this push: new f56300c Use lambdas. f56300c is described below commit f56300c867658d77451bb7647479cbef59a6bf05 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sun Oct 25 15:36:50 2020 -0400 Use lambdas. --- .../archivers/dump/DumpArchiveInputStream.java | 14 +-- .../archivers/zip/ParallelScatterZipCreator.java | 31 ++--- .../commons/compress/archivers/zip/ZipFile.java | 41 +++--- .../commons/compress/archivers/LongPathTest.java | 8 +- .../compress/archivers/LongSymLinkTest.java | 8 +- .../archivers/tar/TarMemoryFileSystemTest.java | 14 +-- .../zip/ParallelScatterZipCreatorTest.java | 125 +++---------------- .../compress/archivers/zip/ScatterSampleTest.java | 7 +- .../archivers/zip/ScatterZipOutputStreamTest.java | 8 +- .../compress/archivers/zip/ZipFileTest.java | 22 ++-- .../compress/compressors/FramedSnappyTestCase.java | 27 +--- .../commons/compress/compressors/ZTestCase.java | 26 +--- .../lz4/FramedLZ4CompressorInputStreamTest.java | 48 ++----- .../lz77support/LZ77CompressorTest.java | 138 +++++++++------------ .../compressors/zstandard/ZstdRoundtripTest.java | 28 +---- .../apache/commons/compress/utils/IOUtilsTest.java | 51 +++----- 16 files changed, 168 insertions(+), 428 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java index 0735b6a..022c4df 100644 --- a/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java @@ -28,7 +28,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.Arrays; -import java.util.Comparator; import java.util.HashMap; import java.util.Map; import java.util.PriorityQueue; @@ -137,15 +136,12 @@ public class DumpArchiveInputStream extends ArchiveInputStream { // use priority based on queue to ensure parent directories are // released first. queue = new PriorityQueue<>(10, - new Comparator<DumpArchiveEntry>() { - @Override - public int compare(final DumpArchiveEntry p, final DumpArchiveEntry q) { - if (p.getOriginalName() == null || q.getOriginalName() == null) { - return Integer.MAX_VALUE; - } - - return p.getOriginalName().compareTo(q.getOriginalName()); + (p, q) -> { + if (p.getOriginalName() == null || q.getOriginalName() == null) { + return Integer.MAX_VALUE; } + + return p.getOriginalName().compareTo(q.getOriginalName()); }); } diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java b/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java index 86b89ff..a73c965 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java @@ -181,12 +181,9 @@ public class ParallelScatterZipCreator { * @param callable The callable to run, created by {@link #createCallable createCallable}, possibly wrapped by caller. */ public final void submit(final Callable<? extends Object> callable) { - submitStreamAwareCallable(new Callable<ScatterZipOutputStream>() { - @Override - public ScatterZipOutputStream call() throws Exception { - callable.call(); - return tlScatterStreams.get(); - } + submitStreamAwareCallable(() -> { + callable.call(); + return tlScatterStreams.get(); }); } @@ -227,13 +224,10 @@ public class ParallelScatterZipCreator { throw new IllegalArgumentException("Method must be set on zipArchiveEntry: " + zipArchiveEntry); } final ZipArchiveEntryRequest zipArchiveEntryRequest = createZipArchiveEntryRequest(zipArchiveEntry, source); - return new Callable<ScatterZipOutputStream>() { - @Override - public ScatterZipOutputStream call() throws Exception { - final ScatterZipOutputStream scatterStream = tlScatterStreams.get(); - scatterStream.addArchiveEntry(zipArchiveEntryRequest); - return scatterStream; - } + return () -> { + final ScatterZipOutputStream scatterStream = tlScatterStreams.get(); + scatterStream.addArchiveEntry(zipArchiveEntryRequest); + return scatterStream; }; } @@ -254,13 +248,10 @@ public class ParallelScatterZipCreator { * @since 1.13 */ public final Callable<ScatterZipOutputStream> createCallable(final ZipArchiveEntryRequestSupplier zipArchiveEntryRequestSupplier) { - return new Callable<ScatterZipOutputStream>() { - @Override - public ScatterZipOutputStream call() throws Exception { - final ScatterZipOutputStream scatterStream = tlScatterStreams.get(); - scatterStream.addArchiveEntry(zipArchiveEntryRequestSupplier.get()); - return scatterStream; - } + return () -> { + final ScatterZipOutputStream scatterStream = tlScatterStreams.get(); + scatterStream.addArchiveEntry(zipArchiveEntryRequestSupplier.get()); + return scatterStream; }; } diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java index 30f7087..0b1e27b 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java @@ -1432,31 +1432,28 @@ public class ZipFile implements Closeable { * @since 1.1 */ private final Comparator<ZipArchiveEntry> offsetComparator = - new Comparator<ZipArchiveEntry>() { - @Override - public int compare(final ZipArchiveEntry e1, final ZipArchiveEntry e2) { - if (e1 == e2) { - return 0; - } + (e1, e2) -> { + if (e1 == e2) { + return 0; + } - final Entry ent1 = e1 instanceof Entry ? (Entry) e1 : null; - final Entry ent2 = e2 instanceof Entry ? (Entry) e2 : null; - if (ent1 == null) { - return 1; - } - if (ent2 == null) { - return -1; - } + final Entry ent1 = e1 instanceof Entry ? (Entry) e1 : null; + final Entry ent2 = e2 instanceof Entry ? (Entry) e2 : null; + if (ent1 == null) { + return 1; + } + if (ent2 == null) { + return -1; + } - // disk number is prior to relative offset - final long diskNumberStartVal = ent1.getDiskNumberStart() - ent2.getDiskNumberStart(); - if (diskNumberStartVal != 0) { - return diskNumberStartVal < 0 ? -1 : +1; - } - final long val = (ent1.getLocalHeaderOffset() - - ent2.getLocalHeaderOffset()); - return val == 0 ? 0 : val < 0 ? -1 : +1; + // disk number is prior to relative offset + final long diskNumberStartVal = ent1.getDiskNumberStart() - ent2.getDiskNumberStart(); + if (diskNumberStartVal != 0) { + return diskNumberStartVal < 0 ? -1 : +1; } + final long val = (ent1.getLocalHeaderOffset() + - ent2.getLocalHeaderOffset()); + return val == 0 ? 0 : val < 0 ? -1 : +1; }; /** diff --git a/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java b/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java index 147b372..bc76795 100644 --- a/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java @@ -26,7 +26,6 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileReader; -import java.io.FilenameFilter; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Collection; @@ -91,12 +90,7 @@ public class LongPathTest extends AbstractTestCase { @Parameters(name = "file={0}") public static Collection<Object[]> data() { final Collection<Object[]> params = new ArrayList<>(); - for (final String f : ARCDIR.list(new FilenameFilter() { - @Override - public boolean accept(final File dir, final String name) { - return !name.endsWith(".txt"); - } - })) + for (final String f : ARCDIR.list((dir, name) -> !name.endsWith(".txt"))) { params.add(new Object[] { f }); } diff --git a/src/test/java/org/apache/commons/compress/archivers/LongSymLinkTest.java b/src/test/java/org/apache/commons/compress/archivers/LongSymLinkTest.java index 882fa39..a0a6f6f 100644 --- a/src/test/java/org/apache/commons/compress/archivers/LongSymLinkTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/LongSymLinkTest.java @@ -26,7 +26,6 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileReader; -import java.io.FilenameFilter; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Collection; @@ -89,12 +88,7 @@ public class LongSymLinkTest extends AbstractTestCase { @Parameters(name = "file={0}") public static Collection<Object[]> data() { final Collection<Object[]> params = new ArrayList<>(); - for (final String f : ARCDIR.list(new FilenameFilter() { - @Override - public boolean accept(final File dir, final String name) { - return !name.endsWith(".txt"); - } - })) + for (final String f : ARCDIR.list((dir, name) -> !name.endsWith(".txt"))) { params.add(new Object[] { f }); } diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarMemoryFileSystemTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarMemoryFileSystemTest.java index 157aef9..85445bd 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/TarMemoryFileSystemTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarMemoryFileSystemTest.java @@ -87,18 +87,8 @@ public class TarMemoryFileSystemTest { try (FileSystem fileSystem = MemoryFileSystemBuilder.newLinux().addUser(user).addGroup(group).build()) { final Path source = fileSystem.getPath("original-file.txt"); Files.write(source, "Test".getBytes(StandardCharsets.UTF_8)); - Files.setAttribute(source, "posix:owner", new UserPrincipal() { - @Override - public String getName() { - return user; - } - }); - Files.setAttribute(source, "posix:group", new GroupPrincipal() { - @Override - public String getName() { - return group; - } - }); + Files.setAttribute(source, "posix:owner", (UserPrincipal) () -> user); + Files.setAttribute(source, "posix:group", (GroupPrincipal) () -> group); final Path target = fileSystem.getPath("original-file.tar"); try (final OutputStream out = Files.newOutputStream(target); diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreatorTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreatorTest.java index cbebe88..00ebdb2 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreatorTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreatorTest.java @@ -19,7 +19,6 @@ package org.apache.commons.compress.archivers.zip; import org.apache.commons.compress.parallel.FileBasedScatterGatherBackingStore; import org.apache.commons.compress.parallel.InputStreamSupplier; -import org.apache.commons.compress.parallel.ScatterGatherBackingStore; import org.apache.commons.compress.parallel.ScatterGatherBackingStoreSupplier; import org.apache.commons.compress.utils.IOUtils; import org.junit.After; @@ -81,45 +80,20 @@ public class ParallelScatterZipCreatorTest { @Test public void callableApiUsingSubmit() throws Exception { result = File.createTempFile("parallelScatterGather2", ""); - callableApi(new CallableConsumerSupplier() { - @Override - public CallableConsumer apply(final ParallelScatterZipCreator zipCreator) { - return new CallableConsumer() { - @Override - public void accept(final Callable<? extends ScatterZipOutputStream> c) { - zipCreator.submit(c); - } - }; - } - }); + callableApi(zipCreator -> c -> zipCreator.submit(c)); } @Test public void callableApiUsingSubmitStreamAwareCallable() throws Exception { result = File.createTempFile("parallelScatterGather3", ""); - callableApi(new CallableConsumerSupplier() { - @Override - public CallableConsumer apply(final ParallelScatterZipCreator zipCreator) { - return new CallableConsumer() { - @Override - public void accept(final Callable<? extends ScatterZipOutputStream> c) { - zipCreator.submitStreamAwareCallable(c); - } - }; - } - }); + callableApi(zipCreator -> c -> zipCreator.submitStreamAwareCallable(c)); } @Test(expected = IllegalArgumentException.class) public void throwsExceptionWithCompressionLevelTooBig() throws Exception { final int compressLevelTooBig = Deflater.BEST_COMPRESSION + 1; final ExecutorService es = Executors.newFixedThreadPool(1); - final ScatterGatherBackingStoreSupplier supp = new ScatterGatherBackingStoreSupplier() { - @Override - public ScatterGatherBackingStore get() throws IOException { - return new FileBasedScatterGatherBackingStore(tmp = File.createTempFile("parallelscatter", "n1")); - } - }; + final ScatterGatherBackingStoreSupplier supp = () -> new FileBasedScatterGatherBackingStore(tmp = File.createTempFile("parallelscatter", "n1")); new ParallelScatterZipCreator(es, supp, compressLevelTooBig); } @@ -128,12 +102,7 @@ public class ParallelScatterZipCreatorTest { public void throwsExceptionWithCompressionLevelTooSmall() throws Exception { final int compressLevelTooSmall = Deflater.DEFAULT_COMPRESSION - 1; final ExecutorService es = Executors.newFixedThreadPool(1); - final ScatterGatherBackingStoreSupplier supp = new ScatterGatherBackingStoreSupplier() { - @Override - public ScatterGatherBackingStore get() throws IOException { - return new FileBasedScatterGatherBackingStore(tmp = File.createTempFile("parallelscatter", "n1")); - } - }; + final ScatterGatherBackingStoreSupplier supp = () -> new FileBasedScatterGatherBackingStore(tmp = File.createTempFile("parallelscatter", "n1")); new ParallelScatterZipCreator(es, supp, compressLevelTooSmall); } @@ -141,33 +110,13 @@ public class ParallelScatterZipCreatorTest { @Test public void callableWithLowestLevelApiUsingSubmit() throws Exception { result = File.createTempFile("parallelScatterGather4", ""); - callableApiWithTestFiles(new CallableConsumerSupplier() { - @Override - public CallableConsumer apply(final ParallelScatterZipCreator zipCreator) { - return new CallableConsumer() { - @Override - public void accept(final Callable<? extends ScatterZipOutputStream> c) { - zipCreator.submit(c); - } - }; - } - }, Deflater.NO_COMPRESSION); + callableApiWithTestFiles(zipCreator -> c -> zipCreator.submit(c), Deflater.NO_COMPRESSION); } @Test public void callableApiWithHighestLevelUsingSubmitStreamAwareCallable() throws Exception { result = File.createTempFile("parallelScatterGather5", ""); - callableApiWithTestFiles(new CallableConsumerSupplier() { - @Override - public CallableConsumer apply(final ParallelScatterZipCreator zipCreator) { - return new CallableConsumer() { - @Override - public void accept(final Callable<? extends ScatterZipOutputStream> c) { - zipCreator.submitStreamAwareCallable(c); - } - }; - } - }, Deflater.BEST_COMPRESSION); + callableApiWithTestFiles(zipCreator -> c -> zipCreator.submitStreamAwareCallable(c), Deflater.BEST_COMPRESSION); } private void callableApi(final CallableConsumerSupplier consumerSupplier) throws Exception { @@ -179,12 +128,7 @@ public class ParallelScatterZipCreatorTest { zos.setEncoding("UTF-8"); final ExecutorService es = Executors.newFixedThreadPool(1); - final ScatterGatherBackingStoreSupplier supp = new ScatterGatherBackingStoreSupplier() { - @Override - public ScatterGatherBackingStore get() throws IOException { - return new FileBasedScatterGatherBackingStore(tmp = File.createTempFile("parallelscatter", "n1")); - } - }; + final ScatterGatherBackingStoreSupplier supp = () -> new FileBasedScatterGatherBackingStore(tmp = File.createTempFile("parallelscatter", "n1")); final ParallelScatterZipCreator zipCreator = new ParallelScatterZipCreator(es, supp, compressionLevel); final Map<String, byte[]> entries = writeEntriesAsCallable(zipCreator, consumerSupplier.apply(zipCreator)); @@ -202,12 +146,7 @@ public class ParallelScatterZipCreatorTest { zos.setEncoding("UTF-8"); final ExecutorService es = Executors.newFixedThreadPool(1); - final ScatterGatherBackingStoreSupplier supp = new ScatterGatherBackingStoreSupplier() { - @Override - public ScatterGatherBackingStore get() throws IOException { - return new FileBasedScatterGatherBackingStore(tmp = File.createTempFile("parallelscatter", "n1")); - } - }; + final ScatterGatherBackingStoreSupplier supp = () -> new FileBasedScatterGatherBackingStore(tmp = File.createTempFile("parallelscatter", "n1")); final ParallelScatterZipCreator zipCreator = new ParallelScatterZipCreator(es, supp, compressionLevel); final Map<String, byte[]> entries = writeTestFilesAsCallable(zipCreator, consumerSupplier.apply(zipCreator)); @@ -249,21 +188,11 @@ public class ParallelScatterZipCreatorTest { for (int i = 0; i < NUMITEMS; i++){ final byte[] payloadBytes = ("content" + i).getBytes(); final ZipArchiveEntry za = createZipArchiveEntry(entries, i, payloadBytes); - final InputStreamSupplier iss = new InputStreamSupplier() { - @Override - public InputStream get() { - return new ByteArrayInputStream(payloadBytes); - } - }; + final InputStreamSupplier iss = () -> new ByteArrayInputStream(payloadBytes); if (i % 2 == 0) { zipCreator.addArchiveEntry(za, iss); } else { - final ZipArchiveEntryRequestSupplier zaSupplier = new ZipArchiveEntryRequestSupplier() { - @Override - public ZipArchiveEntryRequest get() { - return ZipArchiveEntryRequest.createZipArchiveEntryRequest(za, iss); - } - }; + final ZipArchiveEntryRequestSupplier zaSupplier = () -> ZipArchiveEntryRequest.createZipArchiveEntryRequest(za, iss); zipCreator.addArchiveEntry(zaSupplier); } } @@ -276,22 +205,12 @@ public class ParallelScatterZipCreatorTest { for (int i = 0; i < NUMITEMS; i++){ final byte[] payloadBytes = ("content" + i).getBytes(); final ZipArchiveEntry za = createZipArchiveEntry(entries, i, payloadBytes); - final InputStreamSupplier iss = new InputStreamSupplier() { - @Override - public InputStream get() { - return new ByteArrayInputStream(payloadBytes); - } - }; + final InputStreamSupplier iss = () -> new ByteArrayInputStream(payloadBytes); final Callable<ScatterZipOutputStream> callable; if (i % 2 == 0) { callable = zipCreator.createCallable(za, iss); } else { - final ZipArchiveEntryRequestSupplier zaSupplier = new ZipArchiveEntryRequestSupplier() { - @Override - public ZipArchiveEntryRequest get() { - return ZipArchiveEntryRequest.createZipArchiveEntryRequest(za, iss); - } - }; + final ZipArchiveEntryRequestSupplier zaSupplier = () -> ZipArchiveEntryRequest.createZipArchiveEntryRequest(za, iss); callable = zipCreator.createCallable(zaSupplier); } @@ -333,14 +252,11 @@ public class ParallelScatterZipCreatorTest { zipArchiveEntry.setSize(file.length()); zipArchiveEntry.setUnixMode(UnixStat.FILE_FLAG | 0664); - final InputStreamSupplier iss = new InputStreamSupplier() { - @Override - public InputStream get() { - try { - return new FileInputStream(file); - } catch (final FileNotFoundException e) { - return null; - } + final InputStreamSupplier iss = () -> { + try { + return new FileInputStream(file); + } catch (final FileNotFoundException e) { + return null; } }; @@ -348,12 +264,7 @@ public class ParallelScatterZipCreatorTest { if (filesCount % 2 == 0) { callable = zipCreator.createCallable(zipArchiveEntry, iss); } else { - final ZipArchiveEntryRequestSupplier zaSupplier = new ZipArchiveEntryRequestSupplier() { - @Override - public ZipArchiveEntryRequest get() { - return ZipArchiveEntryRequest.createZipArchiveEntryRequest(zipArchiveEntry, iss); - } - }; + final ZipArchiveEntryRequestSupplier zaSupplier = () -> ZipArchiveEntryRequest.createZipArchiveEntryRequest(zipArchiveEntry, iss); callable = zipCreator.createCallable(zaSupplier); } diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ScatterSampleTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ScatterSampleTest.java index ca6d032..c388271 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/ScatterSampleTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/ScatterSampleTest.java @@ -44,12 +44,7 @@ public class ScatterSampleTest { final ScatterSample scatterSample = new ScatterSample(); final ZipArchiveEntry archiveEntry = new ZipArchiveEntry("test1.xml"); archiveEntry.setMethod(ZipEntry.DEFLATED); - final InputStreamSupplier supp = new InputStreamSupplier() { - @Override - public InputStream get() { - return new ByteArrayInputStream("Hello".getBytes()); - } - }; + final InputStreamSupplier supp = () -> new ByteArrayInputStream("Hello".getBytes()); scatterSample.addEntry(archiveEntry, supp); try (final ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(result)) { diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ScatterZipOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ScatterZipOutputStreamTest.java index 124cf9a..a0a8ba1 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/ScatterZipOutputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/ScatterZipOutputStreamTest.java @@ -24,7 +24,6 @@ import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.File; -import java.io.InputStream; import java.util.zip.ZipEntry; import static org.apache.commons.compress.AbstractTestCase.tryHardToDelete; @@ -78,11 +77,6 @@ public class ScatterZipOutputStreamTest { } private InputStreamSupplier createPayloadSupplier(final ByteArrayInputStream payload) { - return new InputStreamSupplier() { - @Override - public InputStream get() { - return payload; - } - }; + return () -> payload; } } diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java index 7423699..6b6feee 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java @@ -372,14 +372,11 @@ public class ZipFileTest { } final AtomicInteger passedCount = new AtomicInteger(); - final Runnable run = new Runnable() { - @Override - public void run() { - for (final ZipArchiveEntry entry: Collections.list(zf.getEntries())) { - assertAllReadMethods(content.get(entry.getName()), zf, entry); - } - passedCount.incrementAndGet(); + final Runnable run = () -> { + for (final ZipArchiveEntry entry: Collections.list(zf.getEntries())) { + assertAllReadMethods(content.get(entry.getName()), zf, entry); } + passedCount.incrementAndGet(); }; final Thread t0 = new Thread(run); final Thread t1 = new Thread(run); @@ -402,14 +399,11 @@ public class ZipFileTest { } final AtomicInteger passedCount = new AtomicInteger(); - final Runnable run = new Runnable() { - @Override - public void run() { - for (final ZipArchiveEntry entry: Collections.list(zf.getEntries())) { - assertAllReadMethods(content.get(entry.getName()), zf, entry); - } - passedCount.incrementAndGet(); + final Runnable run = () -> { + for (final ZipArchiveEntry entry: Collections.list(zf.getEntries())) { + assertAllReadMethods(content.get(entry.getName()), zf, entry); } + passedCount.incrementAndGet(); }; final Thread t0 = new Thread(run); final Thread t1 = new Thread(run); diff --git a/src/test/java/org/apache/commons/compress/compressors/FramedSnappyTestCase.java b/src/test/java/org/apache/commons/compress/compressors/FramedSnappyTestCase.java index 868b8ea..ec0f38e 100644 --- a/src/test/java/org/apache/commons/compress/compressors/FramedSnappyTestCase.java +++ b/src/test/java/org/apache/commons/compress/compressors/FramedSnappyTestCase.java @@ -24,8 +24,6 @@ import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; import java.util.Random; import org.apache.commons.compress.AbstractTestCase; @@ -38,34 +36,19 @@ public final class FramedSnappyTestCase @Test public void testDefaultExtraction() throws Exception { - testUnarchive(new StreamWrapper<CompressorInputStream>() { - @Override - public CompressorInputStream wrap(final InputStream is) throws IOException { - return new FramedSnappyCompressorInputStream(is); - } - }); + testUnarchive(FramedSnappyCompressorInputStream::new); } @Test public void testDefaultExtractionViaFactory() throws Exception { - testUnarchive(new StreamWrapper<CompressorInputStream>() { - @Override - public CompressorInputStream wrap(final InputStream is) throws Exception { - return new CompressorStreamFactory() - .createCompressorInputStream(CompressorStreamFactory.SNAPPY_FRAMED, - is); - } - }); + testUnarchive(is -> new CompressorStreamFactory() + .createCompressorInputStream(CompressorStreamFactory.SNAPPY_FRAMED, + is)); } @Test public void testDefaultExtractionViaFactoryAutodetection() throws Exception { - testUnarchive(new StreamWrapper<CompressorInputStream>() { - @Override - public CompressorInputStream wrap(final InputStream is) throws Exception { - return new CompressorStreamFactory().createCompressorInputStream(is); - } - }); + testUnarchive(is -> new CompressorStreamFactory().createCompressorInputStream(is)); } private void testUnarchive(final StreamWrapper<CompressorInputStream> wrapper) throws Exception { diff --git a/src/test/java/org/apache/commons/compress/compressors/ZTestCase.java b/src/test/java/org/apache/commons/compress/compressors/ZTestCase.java index b80a4a0..5e576df 100644 --- a/src/test/java/org/apache/commons/compress/compressors/ZTestCase.java +++ b/src/test/java/org/apache/commons/compress/compressors/ZTestCase.java @@ -24,7 +24,6 @@ import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; -import java.io.IOException; import java.io.InputStream; import org.apache.commons.compress.AbstractTestCase; @@ -36,34 +35,19 @@ public final class ZTestCase extends AbstractTestCase { @Test public void testZUnarchive() throws Exception { - testUnarchive(new StreamWrapper<CompressorInputStream>() { - @Override - public CompressorInputStream wrap(final InputStream is) throws IOException { - return new ZCompressorInputStream(is); - } - }); + testUnarchive(ZCompressorInputStream::new); } @Test public void testZUnarchiveViaFactory() throws Exception { - testUnarchive(new StreamWrapper<CompressorInputStream>() { - @Override - public CompressorInputStream wrap(final InputStream is) throws Exception { - return new CompressorStreamFactory() - .createCompressorInputStream(CompressorStreamFactory.Z, is); - } - }); + testUnarchive(is -> new CompressorStreamFactory() + .createCompressorInputStream(CompressorStreamFactory.Z, is)); } @Test public void testZUnarchiveViaAutoDetection() throws Exception { - testUnarchive(new StreamWrapper<CompressorInputStream>() { - @Override - public CompressorInputStream wrap(final InputStream is) throws Exception { - return new CompressorStreamFactory() - .createCompressorInputStream(new BufferedInputStream(is)); - } - }); + testUnarchive(is -> new CompressorStreamFactory() + .createCompressorInputStream(new BufferedInputStream(is))); } @Test diff --git a/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorInputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorInputStreamTest.java index 2b91351..dbae303 100644 --- a/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorInputStreamTest.java @@ -97,32 +97,17 @@ public final class FramedLZ4CompressorInputStreamTest @Test public void readDoubledBlaLz4WithDecompressConcatenatedTrue() throws Exception { - readDoubledBlaLz4(new StreamWrapper() { - @Override - public InputStream wrap(final InputStream in) throws Exception { - return new FramedLZ4CompressorInputStream(in, true); - } - }, true); + readDoubledBlaLz4(in -> new FramedLZ4CompressorInputStream(in, true), true); } @Test public void readDoubledBlaLz4WithDecompressConcatenatedFalse() throws Exception { - readDoubledBlaLz4(new StreamWrapper() { - @Override - public InputStream wrap(final InputStream in) throws Exception { - return new FramedLZ4CompressorInputStream(in, false); - } - }, false); + readDoubledBlaLz4(in -> new FramedLZ4CompressorInputStream(in, false), false); } @Test public void readDoubledBlaLz4WithoutExplicitDecompressConcatenated() throws Exception { - readDoubledBlaLz4(new StreamWrapper() { - @Override - public InputStream wrap(final InputStream in) throws Exception { - return new FramedLZ4CompressorInputStream(in); - } - }, false); + readDoubledBlaLz4(FramedLZ4CompressorInputStream::new, false); } @Test @@ -140,35 +125,20 @@ public final class FramedLZ4CompressorInputStreamTest @Test public void readDoubledBlaLz4ViaFactoryWithDecompressConcatenatedTrue() throws Exception { - readDoubledBlaLz4(new StreamWrapper() { - @Override - public InputStream wrap(final InputStream in) throws Exception { - return new CompressorStreamFactory() - .createCompressorInputStream(CompressorStreamFactory.getLZ4Framed(), in, true); - } - }, true); + readDoubledBlaLz4(in -> new CompressorStreamFactory() + .createCompressorInputStream(CompressorStreamFactory.getLZ4Framed(), in, true), true); } @Test public void readDoubledBlaLz4ViaFactoryWithDecompressConcatenatedFalse() throws Exception { - readDoubledBlaLz4(new StreamWrapper() { - @Override - public InputStream wrap(final InputStream in) throws Exception { - return new CompressorStreamFactory() - .createCompressorInputStream(CompressorStreamFactory.getLZ4Framed(), in, false); - } - }, false); + readDoubledBlaLz4(in -> new CompressorStreamFactory() + .createCompressorInputStream(CompressorStreamFactory.getLZ4Framed(), in, false), false); } @Test public void readDoubledBlaLz4ViaFactoryWithoutExplicitDecompressConcatenated() throws Exception { - readDoubledBlaLz4(new StreamWrapper() { - @Override - public InputStream wrap(final InputStream in) throws Exception { - return new CompressorStreamFactory() - .createCompressorInputStream(CompressorStreamFactory.getLZ4Framed(), in); - } - }, false); + readDoubledBlaLz4(in -> new CompressorStreamFactory() + .createCompressorInputStream(CompressorStreamFactory.getLZ4Framed(), in), false); } @Test diff --git a/src/test/java/org/apache/commons/compress/compressors/lz77support/LZ77CompressorTest.java b/src/test/java/org/apache/commons/compress/compressors/lz77support/LZ77CompressorTest.java index af98feb..6691b82 100644 --- a/src/test/java/org/apache/commons/compress/compressors/lz77support/LZ77CompressorTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/lz77support/LZ77CompressorTest.java @@ -63,23 +63,20 @@ public class LZ77CompressorTest { private List<LZ77Compressor.Block> compress(final Parameters params, final byte[]... chunks) throws IOException { final List<LZ77Compressor.Block> blocks = new ArrayList<>(); - final LZ77Compressor c = new LZ77Compressor(params, new LZ77Compressor.Callback() { - @Override - public void accept(LZ77Compressor.Block block) { - //System.err.println(block); - if (block instanceof LZ77Compressor.LiteralBlock) { - // replace with a real copy of data so tests - // can see the results as they've been when - // the callback has been called - final LZ77Compressor.LiteralBlock b = (LZ77Compressor.LiteralBlock) block; - final int len = b.getLength(); - block = new LZ77Compressor.LiteralBlock( - Arrays.copyOfRange(b.getData(), b.getOffset(), b.getOffset() + len), - 0, len); - } - blocks.add(block); - } - }); + final LZ77Compressor c = new LZ77Compressor(params, block -> { + //System.err.println(block); + if (block instanceof LZ77Compressor.LiteralBlock) { + // replace with a real copy of data so tests + // can see the results as they've been when + // the callback has been called + final LZ77Compressor.LiteralBlock b = (LZ77Compressor.LiteralBlock) block; + final int len = b.getLength(); + block = new LZ77Compressor.LiteralBlock( + Arrays.copyOfRange(b.getData(), b.getOffset(), b.getOffset() + len), + 0, len); + } + blocks.add(block); + }); for (final byte[] chunk : chunks) { c.compress(chunk); } @@ -195,23 +192,20 @@ public class LZ77CompressorTest { @Test public void blaExampleWithPrefill() throws IOException { final List<LZ77Compressor.Block> blocks = new ArrayList<>(); - final LZ77Compressor c = new LZ77Compressor(newParameters(128), new LZ77Compressor.Callback() { - @Override - public void accept(LZ77Compressor.Block block) { - //System.err.println(block); - if (block instanceof LZ77Compressor.LiteralBlock) { - // replace with a real copy of data so tests - // can see the results as they've been when - // the callback has been called - final LZ77Compressor.LiteralBlock b = (LZ77Compressor.LiteralBlock) block; - final int len = b.getLength(); - block = new LZ77Compressor.LiteralBlock( - Arrays.copyOfRange(b.getData(), b.getOffset(), b.getOffset() + len), - 0, len); - } - blocks.add(block); - } - }); + final LZ77Compressor c = new LZ77Compressor(newParameters(128), block -> { + //System.err.println(block); + if (block instanceof LZ77Compressor.LiteralBlock) { + // replace with a real copy of data so tests + // can see the results as they've been when + // the callback has been called + final LZ77Compressor.LiteralBlock b = (LZ77Compressor.LiteralBlock) block; + final int len = b.getLength(); + block = new LZ77Compressor.LiteralBlock( + Arrays.copyOfRange(b.getData(), b.getOffset(), b.getOffset() + len), + 0, len); + } + blocks.add(block); + }); c.prefill(Arrays.copyOfRange(BLA, 0, 6)); c.compress(Arrays.copyOfRange(BLA, 6, BLA.length)); c.finish(); @@ -223,23 +217,20 @@ public class LZ77CompressorTest { @Test public void blaExampleWithShortPrefill() throws IOException { final List<LZ77Compressor.Block> blocks = new ArrayList<>(); - final LZ77Compressor c = new LZ77Compressor(newParameters(128), new LZ77Compressor.Callback() { - @Override - public void accept(LZ77Compressor.Block block) { - //System.err.println(block); - if (block instanceof LZ77Compressor.LiteralBlock) { - // replace with a real copy of data so tests - // can see the results as they've been when - // the callback has been called - final LZ77Compressor.LiteralBlock b = (LZ77Compressor.LiteralBlock) block; - final int len = b.getLength(); - block = new LZ77Compressor.LiteralBlock( - Arrays.copyOfRange(b.getData(), b.getOffset(), b.getOffset() + len), - 0, len); - } - blocks.add(block); - } - }); + final LZ77Compressor c = new LZ77Compressor(newParameters(128), block -> { + //System.err.println(block); + if (block instanceof LZ77Compressor.LiteralBlock) { + // replace with a real copy of data so tests + // can see the results as they've been when + // the callback has been called + final LZ77Compressor.LiteralBlock b = (LZ77Compressor.LiteralBlock) block; + final int len = b.getLength(); + block = new LZ77Compressor.LiteralBlock( + Arrays.copyOfRange(b.getData(), b.getOffset(), b.getOffset() + len), + 0, len); + } + blocks.add(block); + }); c.prefill(Arrays.copyOfRange(BLA, 0, 2)); c.compress(Arrays.copyOfRange(BLA, 2, BLA.length)); c.finish(); @@ -252,23 +243,20 @@ public class LZ77CompressorTest { @Test public void blaExampleWithPrefillBiggerThanWindowSize() throws IOException { final List<LZ77Compressor.Block> blocks = new ArrayList<>(); - final LZ77Compressor c = new LZ77Compressor(newParameters(4), new LZ77Compressor.Callback() { - @Override - public void accept(LZ77Compressor.Block block) { - //System.err.println(block); - if (block instanceof LZ77Compressor.LiteralBlock) { - // replace with a real copy of data so tests - // can see the results as they've been when - // the callback has been called - final LZ77Compressor.LiteralBlock b = (LZ77Compressor.LiteralBlock) block; - final int len = b.getLength(); - block = new LZ77Compressor.LiteralBlock( - Arrays.copyOfRange(b.getData(), b.getOffset(), b.getOffset() + len), - 0, len); - } - blocks.add(block); - } - }); + final LZ77Compressor c = new LZ77Compressor(newParameters(4), block -> { + //System.err.println(block); + if (block instanceof LZ77Compressor.LiteralBlock) { + // replace with a real copy of data so tests + // can see the results as they've been when + // the callback has been called + final LZ77Compressor.LiteralBlock b = (LZ77Compressor.LiteralBlock) block; + final int len = b.getLength(); + block = new LZ77Compressor.LiteralBlock( + Arrays.copyOfRange(b.getData(), b.getOffset(), b.getOffset() + len), + 0, len); + } + blocks.add(block); + }); c.prefill(Arrays.copyOfRange(BLA, 0, 6)); c.compress(Arrays.copyOfRange(BLA, 6, BLA.length)); c.finish(); @@ -282,22 +270,16 @@ public class LZ77CompressorTest { @Test(expected = IllegalStateException.class) public void cantPrefillTwice() { - final LZ77Compressor c = new LZ77Compressor(newParameters(128), new LZ77Compressor.Callback() { - @Override - public void accept(final LZ77Compressor.Block block) { - } - }); + final LZ77Compressor c = new LZ77Compressor(newParameters(128), block -> { + }); c.prefill(Arrays.copyOfRange(BLA, 0, 2)); c.prefill(Arrays.copyOfRange(BLA, 2, 4)); } @Test(expected = IllegalStateException.class) public void cantPrefillAfterCompress() throws IOException { - final LZ77Compressor c = new LZ77Compressor(newParameters(128), new LZ77Compressor.Callback() { - @Override - public void accept(final LZ77Compressor.Block block) { - } - }); + final LZ77Compressor c = new LZ77Compressor(newParameters(128), block -> { + }); c.compress(Arrays.copyOfRange(BLA, 0, 2)); c.prefill(Arrays.copyOfRange(BLA, 2, 4)); } diff --git a/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdRoundtripTest.java b/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdRoundtripTest.java index 548e1e5..bcb919d 100644 --- a/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdRoundtripTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdRoundtripTest.java @@ -37,12 +37,7 @@ public class ZstdRoundtripTest extends AbstractTestCase { @Test public void directRoundtrip() throws Exception { - roundtrip(new OutputStreamCreator() { - @Override - public ZstdCompressorOutputStream wrap(final FileOutputStream os) throws IOException { - return new ZstdCompressorOutputStream(os); - } - }); + roundtrip(ZstdCompressorOutputStream::new); } private void roundtrip(final OutputStreamCreator oc) throws IOException { @@ -88,32 +83,17 @@ public class ZstdRoundtripTest extends AbstractTestCase { @Test public void roundtripWithCustomLevel() throws Exception { - roundtrip(new OutputStreamCreator() { - @Override - public ZstdCompressorOutputStream wrap(final FileOutputStream os) throws IOException { - return new ZstdCompressorOutputStream(os, 1); - } - }); + roundtrip(os -> new ZstdCompressorOutputStream(os, 1)); } @Test public void roundtripWithCloseFrameOnFlush() throws Exception { - roundtrip(new OutputStreamCreator() { - @Override - public ZstdCompressorOutputStream wrap(final FileOutputStream os) throws IOException { - return new ZstdCompressorOutputStream(os, 3, true); - } - }); + roundtrip(os -> new ZstdCompressorOutputStream(os, 3, true)); } @Test public void roundtripWithChecksum() throws Exception { - roundtrip(new OutputStreamCreator() { - @Override - public ZstdCompressorOutputStream wrap(final FileOutputStream os) throws IOException { - return new ZstdCompressorOutputStream(os, 3, false, true); - } - }); + roundtrip(os -> new ZstdCompressorOutputStream(os, 3, false, true)); } } diff --git a/src/test/java/org/apache/commons/compress/utils/IOUtilsTest.java b/src/test/java/org/apache/commons/compress/utils/IOUtilsTest.java index 309d872..57cacd5 100644 --- a/src/test/java/org/apache/commons/compress/utils/IOUtilsTest.java +++ b/src/test/java/org/apache/commons/compress/utils/IOUtilsTest.java @@ -37,48 +37,33 @@ public class IOUtilsTest { @Test public void skipUsingSkip() throws Exception { - skip(new StreamWrapper() { - @Override - public InputStream wrap(final InputStream toWrap) { - return toWrap; - } - }); + skip(toWrap -> toWrap); } @Test public void skipUsingRead() throws Exception { - skip(new StreamWrapper() { - @Override - public InputStream wrap(final InputStream toWrap) { - return new FilterInputStream(toWrap) { - @Override - public long skip(final long s) { - return 0; - } - }; - } - }); + skip(toWrap -> new FilterInputStream(toWrap) { + @Override + public long skip(final long s) { + return 0; + } + }); } @Test public void skipUsingSkipAndRead() throws Exception { - skip(new StreamWrapper() { - @Override - public InputStream wrap(final InputStream toWrap) { - return new FilterInputStream(toWrap) { - boolean skipped; - @Override - public long skip(final long s) throws IOException { - if (!skipped) { - toWrap.skip(5); - skipped = true; - return 5; - } - return 0; - } - }; + skip(toWrap -> new FilterInputStream(toWrap) { + boolean skipped; + @Override + public long skip(final long s) throws IOException { + if (!skipped) { + toWrap.skip(5); + skipped = true; + return 5; } - }); + return 0; + } + }); } @Test