correctly close inputstream
Signed-off-by: olivier lamy <olamy@apache.org>
diff --git a/indexer-core/src/main/java/org/apache/maven/index/locator/ArtifactLocator.java b/indexer-core/src/main/java/org/apache/maven/index/locator/ArtifactLocator.java
index d27d2a6..f4feb34 100644
--- a/indexer-core/src/main/java/org/apache/maven/index/locator/ArtifactLocator.java
+++ b/indexer-core/src/main/java/org/apache/maven/index/locator/ArtifactLocator.java
@@ -22,6 +22,8 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
import org.apache.maven.index.artifact.ArtifactPackagingMapper;
import org.apache.maven.index.artifact.Gav;
@@ -48,16 +50,19 @@
public File locate( File source, GavCalculator gavCalculator, Gav gav )
{
// if we don't have this data, nothing we can do
- if ( source == null || !source.exists() || gav == null || gav.getArtifactId() == null
+ if ( source == null //
+ || !source.exists() //
+ || gav == null //
+ || gav.getArtifactId() == null //
|| gav.getVersion() == null )
{
return null;
}
- try
+ try (InputStream inputStream = Files.newInputStream( source.toPath() ))
{
// need to read the pom model to get packaging
- final Model model = new MavenXpp3Reader().read( new FileInputStream( source ), false );
+ final Model model = new MavenXpp3Reader().read( inputStream, false );
if ( model == null )
{