From 3db882dfcd422363cc4d65f553060733412425cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=9A=D1=83=D1=80=D1=82=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Wed, 25 Jan 2023 20:42:58 +0200 Subject: [PATCH] Reduce 3rd party IOUtil usage Java provides API which is most likely more optimized too. --- .../tycho/p2maven/transport/TychoRepositoryTransport.java | 3 +-- .../tycho/artifactcomparator/ComparatorInputStream.java | 4 +--- .../eclipse/tycho/test/product/Tycho188P2EnabledRcpTest.java | 4 +--- .../java/org/eclipse/tycho/plugins/tar/TarGzArchiver.java | 3 +-- .../java/org/eclipse/tycho/plugins/tar/TarGzArchiverTest.java | 3 +-- 5 files changed, 5 insertions(+), 12 deletions(-) diff --git a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/TychoRepositoryTransport.java b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/TychoRepositoryTransport.java index b88d3d0d00..89dc8e7eca 100644 --- a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/TychoRepositoryTransport.java +++ b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/TychoRepositoryTransport.java @@ -29,7 +29,6 @@ import java.util.concurrent.atomic.LongAdder; import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.Logger; @@ -99,7 +98,7 @@ public IStatus download(URI toDownload, OutputStream target, IProgressMonitor mo try { DownloadStatusOutputStream statusOutputStream = new DownloadStatusOutputStream(target, "Download of " + toDownload); - IOUtils.copy(stream(toDownload, monitor), statusOutputStream); + stream(toDownload, monitor).transferTo(statusOutputStream); DownloadStatus downloadStatus = statusOutputStream.getStatus(); if (cacheConfig.isInteractive()) { logger.info( diff --git a/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/artifactcomparator/ComparatorInputStream.java b/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/artifactcomparator/ComparatorInputStream.java index 3c11c3301e..fbe62dd660 100644 --- a/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/artifactcomparator/ComparatorInputStream.java +++ b/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/artifactcomparator/ComparatorInputStream.java @@ -18,8 +18,6 @@ import java.nio.charset.Charset; import java.util.Arrays; -import org.apache.commons.io.IOUtils; - /** * Input stream to carry some important information for comparison and allows direct access to the * underlying buffer. @@ -32,7 +30,7 @@ public class ComparatorInputStream extends ByteArrayInputStream { private final byte[] content; public ComparatorInputStream(InputStream stream) throws IOException { - this(IOUtils.toByteArray(stream)); + this(stream.readAllBytes()); } public ComparatorInputStream(byte[] content) { diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/product/Tycho188P2EnabledRcpTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/product/Tycho188P2EnabledRcpTest.java index 73f46e092a..63546b8895 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/product/Tycho188P2EnabledRcpTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/product/Tycho188P2EnabledRcpTest.java @@ -28,7 +28,6 @@ import java.util.Set; import org.apache.maven.it.Verifier; -import org.codehaus.plexus.util.IOUtil; import org.eclipse.tycho.TargetEnvironment; import org.eclipse.tycho.test.AbstractTychoIntegrationTest; import org.eclipse.tycho.test.util.ArchiveContentUtil; @@ -258,8 +257,7 @@ static private void assertTotalZipArtifacts(final Verifier verifier, final int e public static Properties openPropertiesFromZip(File zipFile, String propertyFile) throws Exception { Properties configIni = new Properties(); - configIni.load( - new ByteArrayInputStream(IOUtil.toByteArray(ArchiveContentUtil.getFileContent(zipFile, propertyFile)))); + configIni.load(new ByteArrayInputStream(ArchiveContentUtil.getFileContent(zipFile, propertyFile).getBytes())); return configIni; } diff --git a/tycho-p2/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/tar/TarGzArchiver.java b/tycho-p2/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/tar/TarGzArchiver.java index a92b9a8270..ab42871b17 100644 --- a/tycho-p2/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/tar/TarGzArchiver.java +++ b/tycho-p2/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/tar/TarGzArchiver.java @@ -30,7 +30,6 @@ import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; -import org.apache.commons.compress.utils.IOUtils; import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugin.logging.SystemStreamLog; @@ -163,7 +162,7 @@ private PosixFileAttributes getAttributes(File source) { private static void copyFileContentToTarStream(File source, TarArchiveOutputStream tarStream) throws IOException { try (BufferedInputStream sourceStream = new BufferedInputStream(new FileInputStream(source))) { - IOUtils.copy(sourceStream, tarStream); + sourceStream.transferTo(tarStream); } } diff --git a/tycho-p2/tycho-p2-director-plugin/src/test/java/org/eclipse/tycho/plugins/tar/TarGzArchiverTest.java b/tycho-p2/tycho-p2-director-plugin/src/test/java/org/eclipse/tycho/plugins/tar/TarGzArchiverTest.java index 4b42070b94..94db68ef92 100644 --- a/tycho-p2/tycho-p2-director-plugin/src/test/java/org/eclipse/tycho/plugins/tar/TarGzArchiverTest.java +++ b/tycho-p2/tycho-p2-director-plugin/src/test/java/org/eclipse/tycho/plugins/tar/TarGzArchiverTest.java @@ -36,7 +36,6 @@ import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; -import org.apache.commons.compress.utils.IOUtils; import org.junit.Assume; import org.junit.Before; import org.junit.Rule; @@ -226,7 +225,7 @@ private byte[] getTarEntry(String name) throws IOException { while ((tarEntry = tarStream.getNextTarEntry()) != null) { if (name.equals(tarEntry.getName())) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - IOUtils.copy(tarStream, baos); + tarStream.transferTo(baos); return baos.toByteArray(); } }