From 7f4dfb5320b987e6db91b3b5c4c9cb0d3c8b0963 Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Fri, 10 May 2024 08:55:11 +0200 Subject: [PATCH] [MSHARED-1395] Remove dependency on commons-io --- pom.xml | 6 ------ .../analyzer/asm/DependencyClassFileVisitor.java | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 7df05e54..72068c44 100644 --- a/pom.xml +++ b/pom.xml @@ -110,12 +110,6 @@ ${slf4jVersion} - - commons-io - commons-io - 2.16.1 - - org.junit.jupiter diff --git a/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/DependencyClassFileVisitor.java b/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/DependencyClassFileVisitor.java index 8f701164..20485b44 100644 --- a/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/DependencyClassFileVisitor.java +++ b/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/DependencyClassFileVisitor.java @@ -18,11 +18,11 @@ */ package org.apache.maven.shared.dependency.analyzer.asm; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Set; -import org.apache.commons.io.IOUtils; import org.apache.maven.shared.dependency.analyzer.ClassFileVisitor; import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.ClassReader; @@ -41,6 +41,8 @@ * @see #getDependencies() */ public class DependencyClassFileVisitor implements ClassFileVisitor { + private static final int BUF_SIZE = 8192; + private final ResultCollector resultCollector = new ResultCollector(); private final Logger logger = LoggerFactory.getLogger(getClass()); @@ -54,7 +56,7 @@ public DependencyClassFileVisitor() {} @Override public void visitClass(String className, InputStream in) { try { - byte[] byteCode = IOUtils.toByteArray(in); + byte[] byteCode = toByteArray(in); ClassReader reader = new ClassReader(byteCode); final Set constantPoolClassRefs = ConstantPoolParser.getConstantPoolClassReferences(byteCode); @@ -82,6 +84,16 @@ public void visitClass(String className, InputStream in) { } } + private byte[] toByteArray(InputStream in) throws IOException { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + byte[] buffer = new byte[BUF_SIZE]; + int i; + while ((i = in.read(buffer)) > 0) { + out.write(buffer, 0, i); + } + return out.toByteArray(); + } + /** *

getDependencies.

*