Skip to content

Commit

Permalink
[MSHARED-1395] Remove dependency on commons-io
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed May 10, 2024
1 parent 7231d5a commit 7f4dfb5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,6 @@
<version>${slf4jVersion}</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.16.1</version>
</dependency>

<!-- testing support -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand All @@ -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<String> constantPoolClassRefs = ConstantPoolParser.getConstantPoolClassReferences(byteCode);
Expand Down Expand Up @@ -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();
}

/**
* <p>getDependencies.</p>
*
Expand Down

0 comments on commit 7f4dfb5

Please sign in to comment.