]> source.dussan.org Git - archiva.git/commitdiff
use Files.copy from java.nio.file
authorOlivier Lamy <olamy@apache.org>
Wed, 16 Apr 2014 08:11:38 +0000 (18:11 +1000)
committerOlivier Lamy <olamy@apache.org>
Wed, 16 Apr 2014 08:11:38 +0000 (18:11 +1000)
13 files changed:
archiva-modules/archiva-base/archiva-filelock/src/test/java/org/apache/archiva/common/filelock/DefaultFileLockManagerTest.java
archiva-modules/archiva-base/archiva-filelock/src/test/java/org/apache/archiva/common/filelock/DefaultFileLockManagerTimeoutTest.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/RepositoryMetadataWriter.java
archiva-modules/archiva-base/archiva-xml-tools/src/main/java/org/apache/archiva/xml/XMLReader.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/api/DefaultFileUploadService.java
archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactsTest.java
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResource.java
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/MimeTypes.java
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java
archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java

index 40c47442fd7a0188c6bcc6fe0dae1695fa4f1c0b..e72704e35bb8f45267b2e9c7660ebb1cb192ffec 100644 (file)
@@ -21,8 +21,6 @@ package org.apache.archiva.common.filelock;
 
 import edu.umd.cs.mtc.MultithreadedTestCase;
 import edu.umd.cs.mtc.TestFramework;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -35,11 +33,14 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 import javax.inject.Inject;
 import javax.inject.Named;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.concurrent.atomic.AtomicInteger;
 
+//import org.apache.commons.io.IOUtils;
+
 /**
  * @author Olivier Lamy
  */
@@ -89,7 +90,7 @@ public class DefaultFileLockManagerTest
             try
             {
                 lock.getFile().delete();
-                FileUtils.copyFile( largeJar, lock.getFile() );
+                Files.copy( largeJar.toPath(), lock.getFile().toPath() );
             }
             finally
             {
@@ -107,7 +108,7 @@ public class DefaultFileLockManagerTest
             try
             {
                 lock.getFile().delete();
-                FileUtils.copyFile( largeJar, lock.getFile() );
+                Files.copy( largeJar.toPath(), lock.getFile().toPath() );
             }
             finally
             {
@@ -124,8 +125,8 @@ public class DefaultFileLockManagerTest
             Lock lock = fileLockManager.readFileLock( this.file );
             try
             {
-                IOUtils.copy( new FileInputStream( lock.getFile() ),
-                              new FileOutputStream( File.createTempFile( "foo", ".jar" ) ) );
+                Files.copy( Paths.get( lock.getFile().getPath() ),
+                            new FileOutputStream( File.createTempFile( "foo", ".jar" ) ) );
             }
             finally
             {
@@ -143,7 +144,7 @@ public class DefaultFileLockManagerTest
             try
             {
                 lock.getFile().delete();
-                FileUtils.copyFile( largeJar, lock.getFile() );
+                Files.copy( largeJar.toPath(), lock.getFile().toPath() );
             }
             finally
             {
@@ -161,7 +162,7 @@ public class DefaultFileLockManagerTest
             try
             {
                 lock.getFile().delete();
-                FileUtils.copyFile( largeJar, lock.getFile() );
+                Files.copy( largeJar.toPath(), lock.getFile().toPath() );
             }
             finally
             {
@@ -178,8 +179,8 @@ public class DefaultFileLockManagerTest
             Lock lock = fileLockManager.readFileLock( this.file );
             try
             {
-                IOUtils.copy( new FileInputStream( lock.getFile() ),
-                              new FileOutputStream( File.createTempFile( "foo", ".jar" ) ) );
+                Files.copy( lock.getFile().toPath(),
+                            new FileOutputStream( File.createTempFile( "foo", ".jar" ) ) );
             }
             finally
             {
@@ -197,7 +198,7 @@ public class DefaultFileLockManagerTest
             try
             {
                 lock.getFile().delete();
-                FileUtils.copyFile( largeJar, lock.getFile() );
+                Files.copy( largeJar.toPath(), lock.getFile().toPath() );
             }
             finally
             {
@@ -214,8 +215,7 @@ public class DefaultFileLockManagerTest
             Lock lock = fileLockManager.readFileLock( this.file );
             try
             {
-                IOUtils.copy( new FileInputStream( lock.getFile() ),
-                              new FileOutputStream( File.createTempFile( "foo", ".jar" ) ) );
+                Files.copy( lock.getFile().toPath(), new FileOutputStream( File.createTempFile( "foo", ".jar" ) ) );
             }
             finally
             {
@@ -233,7 +233,7 @@ public class DefaultFileLockManagerTest
             try
             {
                 lock.getFile().delete();
-                FileUtils.copyFile( largeJar, lock.getFile() );
+                Files.copy( largeJar.toPath(), lock.getFile().toPath() );
             }
             finally
             {
@@ -250,8 +250,8 @@ public class DefaultFileLockManagerTest
             Lock lock = fileLockManager.readFileLock( this.file );
             try
             {
-                IOUtils.copy( new FileInputStream( lock.getFile() ),
-                              new FileOutputStream( File.createTempFile( "foo", ".jar" ) ) );
+                Files.copy( lock.getFile().toPath(),
+                            new FileOutputStream( File.createTempFile( "foo", ".jar" ) ) );
             }
             finally
             {
index acf7fe66e634db357fa9032e49a46ab1d706b338..281d1310547fd6d5fecc86bba61a33d78c5fbe7b 100644 (file)
@@ -19,11 +19,6 @@ package org.apache.archiva.common.filelock;
  * under the License.
  */
 
-import edu.umd.cs.mtc.MultithreadedTestCase;
-import edu.umd.cs.mtc.TestFramework;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -35,10 +30,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 import javax.inject.Inject;
 import javax.inject.Named;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.concurrent.atomic.AtomicInteger;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
 
 /**
  * @author Olivier Lamy
@@ -64,18 +57,20 @@ public class DefaultFileLockManagerTimeoutTest
         fileLockManager.clearLockFiles();
     }
 
-    @Test( expected = FileLockTimeoutException.class )
+    @Test(expected = FileLockTimeoutException.class)
     public void testTimeout()
         throws Throwable
     {
 
         File file = new File( System.getProperty( "buildDirectory" ), "foo.txt" );
 
+        Files.deleteIfExists( file.toPath() );
+
         File largeJar = new File( System.getProperty( "basedir" ), "src/test/cassandra-all-2.0.3.jar" );
 
         Lock lock = fileLockManager.writeFileLock( file );
 
-        FileUtils.copyFile( largeJar, lock.getFile() );
+        Files.copy( largeJar.toPath(), lock.getFile().toPath(), StandardCopyOption.REPLACE_EXISTING );
 
         lock = fileLockManager.writeFileLock( file );
 
index ab47e78c1c4e0cfdfd4c49ac8ae87cb5820ae0a7..0eb06b225c150d174855db9f911890faa64452fd 100644 (file)
@@ -25,7 +25,6 @@ import org.apache.archiva.xml.XMLException;
 import org.apache.archiva.xml.XMLWriter;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.dom4j.Document;
 import org.dom4j.DocumentHelper;
@@ -35,6 +34,7 @@ import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Writer;
+import java.nio.file.Files;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Iterator;
@@ -49,10 +49,8 @@ public class RepositoryMetadataWriter
         throws RepositoryMetadataException
     {
         boolean thrown = false;
-        FileWriter writer = null;
-        try
+        try (FileWriter writer = new FileWriter( outputFile ))
         {
-            writer = new FileWriter( outputFile );
             write( metadata, writer );
             writer.flush();
         }
@@ -64,7 +62,6 @@ public class RepositoryMetadataWriter
         }
         finally
         {
-            IOUtils.closeQuietly( writer );
             if ( thrown )
             {
                 FileUtils.deleteQuietly( outputFile );
index 43cb09c4b145a8e6e8581473b382baf1b9d9047e..603fc884e275e4b32d38621fb3be241d62f3a1cd 100644 (file)
@@ -19,7 +19,6 @@ package org.apache.archiva.xml;
  * under the License.
  */
 
-import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.dom4j.Attribute;
 import org.dom4j.Document;
@@ -44,9 +43,7 @@ import java.util.List;
 import java.util.Map;
 
 /**
- * XMLReader - a set of common xml utility methods for reading content out of an xml file. 
- *
- *
+ * XMLReader - a set of common xml utility methods for reading content out of an xml file.
  */
 public class XMLReader
 {
@@ -98,12 +95,10 @@ public class XMLReader
         this.documentType = type;
         this.xmlUrl = url;
 
-        InputStream in = null;
         SAXReader reader = new SAXReader();
-        
-        try
+
+        try (InputStream in = url.openStream())
         {
-            in = url.openStream();
             InputStreamReader inReader = new InputStreamReader( in, "UTF-8" );
             LatinEntityResolutionReader latinReader = new LatinEntityResolutionReader( inReader );
             this.document = reader.read( latinReader );
@@ -116,10 +111,6 @@ public class XMLReader
         {
             throw new XMLException( "Unable to open stream to " + url + ": " + e.getMessage(), e );
         }
-        finally
-        {
-            IOUtils.closeQuietly( in );
-        }
 
         Element root = this.document.getRootElement();
         if ( root == null )
@@ -129,8 +120,9 @@ public class XMLReader
 
         if ( !StringUtils.equals( root.getName(), documentType ) )
         {
-            throw new XMLException( "Invalid " + documentType + " xml: Unexpected root element <" + root.getName()
-                + ">, expected <" + documentType + ">" );
+            throw new XMLException(
+                "Invalid " + documentType + " xml: Unexpected root element <" + root.getName() + ">, expected <"
+                    + documentType + ">" );
         }
     }
 
@@ -164,7 +156,7 @@ public class XMLReader
         {
             // Unknown evaluated type.
             throw new XMLException( ".getElement( Expr: " + xpathExpr + " ) resulted in non-Element type -> ("
-                + evaluated.getClass().getName() + ") " + evaluated );
+                                        + evaluated.getClass().getName() + ") " + evaluated );
         }
     }
 
@@ -246,8 +238,8 @@ public class XMLReader
         else
         {
             // Unknown evaluated type.
-            throw new XMLException( ".getElementText( Node, Expr: " + xpathExpr
-                + " ) resulted in non-Element type -> (" + evaluated.getClass().getName() + ") " + evaluated );
+            throw new XMLException( ".getElementText( Node, Expr: " + xpathExpr + " ) resulted in non-Element type -> ("
+                                        + evaluated.getClass().getName() + ") " + evaluated );
         }
     }
 
@@ -271,7 +263,7 @@ public class XMLReader
         {
             // Unknown evaluated type.
             throw new XMLException( ".getElementText( Expr: " + xpathExpr + " ) resulted in non-Element type -> ("
-                + evaluated.getClass().getName() + ") " + evaluated );
+                                        + evaluated.getClass().getName() + ") " + evaluated );
         }
     }
 
@@ -306,7 +298,7 @@ public class XMLReader
         {
             // Unknown evaluated type.
             throw new XMLException( ".getElementList( Expr: " + xpathExpr + " ) resulted in non-List type -> ("
-                + evaluated.getClass().getName() + ") " + evaluated );
+                                        + evaluated.getClass().getName() + ") " + evaluated );
         }
     }
 
index c98b5f9d2bd2b4d3d89974118b308782c264a5f2..c929ff10632092656bc20107978606ffd2dfbdbd 100644 (file)
@@ -786,15 +786,13 @@ public class DefaultBrowseService
                     // zip entry of the path -> path must a real file entry of the archive
                     JarFile jarFile = new JarFile( file );
                     ZipEntry zipEntry = jarFile.getEntry( path );
-                    InputStream inputStream = jarFile.getInputStream( zipEntry );
-                    try
+                    try (InputStream inputStream = jarFile.getInputStream( zipEntry ))
                     {
                         return new ArtifactContent( IOUtils.toString( inputStream ), repoId );
                     }
                     finally
                     {
                         closeQuietly( jarFile );
-                        IOUtils.closeQuietly( inputStream );
                     }
                 }
                 return new ArtifactContent( FileUtils.readFileToString( file ), repoId );
index 795aaf1690e2cbbfa85b579fd9a8b82abea2aa40..b7cb60d348e5684f989e129368fb37930402bde2 100644 (file)
@@ -23,7 +23,6 @@ import org.apache.archiva.redback.rest.api.services.RedbackServiceException;
 import org.apache.archiva.redback.rest.api.services.UtilServices;
 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
 import org.apache.archiva.rest.api.services.CommonServices;
-import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -42,7 +41,7 @@ import java.util.concurrent.ConcurrentHashMap;
 /**
  * @author Olivier Lamy
  */
-@Service( "commonServices#rest" )
+@Service("commonServices#rest")
 public class DefaultCommonServices
     implements CommonServices
 {
@@ -121,11 +120,9 @@ public class DefaultCommonServices
     private void loadResource( final Properties finalProperties, String resourceName, String locale )
         throws IOException
     {
-        InputStream is = null;
         Properties properties = new Properties();
-        try
+        try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( resourceName ))
         {
-            is = Thread.currentThread().getContextClassLoader().getResourceAsStream( resourceName );
             if ( is != null )
             {
                 properties.load( is );
@@ -139,10 +136,6 @@ public class DefaultCommonServices
                 }
             }
         }
-        finally
-        {
-            IOUtils.closeQuietly( is );
-        }
     }
 
     @Override
@@ -181,10 +174,8 @@ public class DefaultCommonServices
     private void loadFromString( String propsStr, Properties properties )
         throws ArchivaRestServiceException
     {
-        InputStream inputStream = null;
-        try
+        try (InputStream inputStream = new ByteArrayInputStream( propsStr.getBytes() ))
         {
-            inputStream = new ByteArrayInputStream( propsStr.getBytes() );
             properties.load( inputStream );
         }
         catch ( IOException e )
@@ -192,10 +183,6 @@ public class DefaultCommonServices
             throw new ArchivaRestServiceException( e.getMessage(),
                                                    Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
         }
-        finally
-        {
-            IOUtils.closeQuietly( inputStream );
-        }
     }
 
 
index a623d82fe20b606026aed9ac67c931446f43f273..4fdb5f6460b7629575e70c43b668d6a9ac787280 100644 (file)
@@ -78,7 +78,6 @@ import org.apache.archiva.security.ArchivaSecurityException;
 import org.apache.archiva.security.common.ArchivaRoleConstants;
 import org.apache.archiva.xml.XMLException;
 import org.apache.commons.io.FilenameUtils;
-import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.maven.index.context.IndexingContext;
 import org.slf4j.Logger;
@@ -89,9 +88,8 @@ import javax.inject.Inject;
 import javax.inject.Named;
 import javax.ws.rs.core.Response;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
+import java.nio.file.Files;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -107,7 +105,7 @@ import java.util.TimeZone;
  * @author Olivier Lamy
  * @since 1.4-M1
  */
-@Service( "repositoriesService#rest" )
+@Service("repositoriesService#rest")
 public class DefaultRepositoriesService
     extends AbstractRestService
     implements RepositoriesService
@@ -115,7 +113,7 @@ public class DefaultRepositoriesService
     private Logger log = LoggerFactory.getLogger( getClass() );
 
     @Inject
-    @Named( value = "taskExecutor#indexing" )
+    @Named(value = "taskExecutor#indexing")
     private ArchivaIndexingTaskExecutor archivaIndexingTaskExecutor;
 
     @Inject
@@ -134,14 +132,14 @@ public class DefaultRepositoriesService
     private RepositoryContentFactory repositoryFactory;
 
     @Inject
-    @Named( value = "archivaTaskScheduler#repository" )
+    @Named(value = "archivaTaskScheduler#repository")
     private ArchivaTaskScheduler scheduler;
 
     @Inject
     private DownloadRemoteIndexScheduler downloadRemoteIndexScheduler;
 
     @Inject
-    @Named( value = "repositorySessionFactory" )
+    @Named(value = "repositorySessionFactory")
     protected RepositorySessionFactory repositorySessionFactory;
 
     @Inject
@@ -154,7 +152,7 @@ public class DefaultRepositoriesService
      * Cache used for namespaces
      */
     @Inject
-    @Named( value = "cache#namespaces" )
+    @Named(value = "cache#namespaces")
     private Cache<String, Collection<String>> namespacesCache;
 
     private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[]{ ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 };
@@ -423,7 +421,8 @@ public class DefaultRepositoriesService
             {
                 throw new ArchivaRestServiceException(
                     "artifact already exists in target repo: " + artifactTransferRequest.getTargetRepositoryId()
-                        + " and redeployment blocked", null );
+                        + " and redeployment blocked", null
+                );
             }
             else
             {
@@ -531,18 +530,7 @@ public class DefaultRepositoriesService
     private void copyFile( File sourceFile, File targetPath, String targetFilename, boolean fixChecksums )
         throws IOException
     {
-        FileOutputStream out = new FileOutputStream( new File( targetPath, targetFilename ) );
-        FileInputStream input = new FileInputStream( sourceFile );
-
-        try
-        {
-            IOUtils.copy( input, out );
-        }
-        finally
-        {
-            IOUtils.closeQuietly( out );
-            IOUtils.closeQuietly( input );
-        }
+        Files.copy( sourceFile.toPath(), new File( targetPath, targetFilename ).toPath() );
 
         if ( fixChecksums )
         {
index 2bbaf4b06bec265219892f3cfbd8a82dacca749f..c232e03fa534ac4b1ed8aea043ae2db9812a1740 100644 (file)
@@ -60,17 +60,16 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 
-
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Response;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.nio.file.Files;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -540,15 +539,11 @@ public class DefaultFileUploadService
 
         File pomFile = new File( targetPath, filename );
         MavenXpp3Writer writer = new MavenXpp3Writer();
-        FileWriter w = new FileWriter( pomFile );
-        try
+
+        try (FileWriter w = new FileWriter( pomFile ))
         {
             writer.write( w, projectModel );
         }
-        finally
-        {
-            IOUtils.closeQuietly( w );
-        }
 
         return pomFile;
     }
@@ -581,20 +576,8 @@ public class DefaultFileUploadService
     private void copyFile( File sourceFile, File targetPath, String targetFilename, boolean fixChecksums )
         throws IOException
     {
-        FileOutputStream out = null;
-        FileInputStream input = null;
 
-        try
-        {
-            out = new FileOutputStream( new File( targetPath, targetFilename ) );
-            input = new FileInputStream( sourceFile );
-            IOUtils.copy( input, out );
-        }
-        finally
-        {
-            IOUtils.closeQuietly( out );
-            IOUtils.closeQuietly( input );
-        }
+        Files.copy( sourceFile.toPath(), new File( targetPath, targetFilename ).toPath() );
 
         if ( fixChecksums )
         {
index 3192fce544c2e37a68c3fe8e34ea57bdc91d8fb4..b009e8c718a6c8c18049430f908f704fa3d7909a 100644 (file)
@@ -21,7 +21,7 @@ package org.apache.archiva.remotedownload;
 import org.apache.archiva.admin.model.beans.RemoteRepository;
 import org.apache.archiva.redback.rest.api.services.RoleManagementService;
 import org.apache.archiva.security.common.ArchivaRoleConstants;
-import org.apache.commons.compress.utils.IOUtils;
+import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
 import org.apache.commons.io.FileUtils;
 import org.apache.maven.wagon.providers.http.HttpWagon;
 import org.apache.maven.wagon.repository.Repository;
@@ -42,12 +42,11 @@ import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
+import java.nio.file.Files;
 import java.util.List;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
-import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
 
 /**
  * @author Olivier Lamy
@@ -85,8 +84,9 @@ public class DownloadArtifactsTest
     protected String getSpringConfigLocation()
     {
         return "classpath*:META-INF/spring-context.xml classpath*:spring-context-test-common.xml classpath*:spring-context-artifacts-download.xml";
-    }    @Override
+    }
 
+    @Override
 
     @Before
     public void startServer()
@@ -182,8 +182,6 @@ public class DownloadArtifactsTest
     }
 
 
-
-
     public static class RedirectServlet
         extends HttpServlet
     {
@@ -212,7 +210,7 @@ public class DownloadArtifactsTest
             throws ServletException, IOException
         {
             File jar = new File( System.getProperty( "basedir" ), "src/test/junit-4.9.jar" );
-            IOUtils.copy( new FileInputStream( jar ), resp.getOutputStream() );
+            Files.copy( jar.toPath(), resp.getOutputStream() );
 
         }
     }
index 6961d2206d097635dc6f63939a80c7d3e36320b1..c1c73eee875de9753edd53914dcf235f7ee44443 100644 (file)
@@ -65,9 +65,10 @@ import org.slf4j.LoggerFactory;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -134,7 +135,8 @@ public class ArchivaDavResource
     public ArchivaDavResource( String localResource, String logicalResource, ManagedRepository repository,
                                String remoteAddr, String principal, DavSession session,
                                ArchivaDavResourceLocator locator, DavResourceFactory factory, MimeTypes mimeTypes,
-                               List<AuditListener> auditListeners, RepositoryArchivaTaskScheduler scheduler , FileLockManager fileLockManager )
+                               List<AuditListener> auditListeners, RepositoryArchivaTaskScheduler scheduler,
+                               FileLockManager fileLockManager )
     {
         this( localResource, logicalResource, repository, session, locator, factory, mimeTypes, auditListeners,
               scheduler, fileLockManager );
@@ -218,18 +220,10 @@ public class ArchivaDavResource
             if ( !isCollection() && outputContext.hasStream() )
             {
                 Lock lock = fileLockManager.readFileLock( localResource );
-                FileInputStream is = null;
-                try
+                try (InputStream is = Files.newInputStream( lock.getFile().toPath() ))
                 {
-                    // Write content to stream
-                    is = new FileInputStream( lock.getFile() );
                     IOUtils.copy( is, outputContext.getOutputStream() );
                 }
-                finally
-                {
-                    IOUtils.closeQuietly( is );
-                    fileLockManager.release( lock );
-                }
             }
             else if ( outputContext.hasStream() )
             {
@@ -283,7 +277,7 @@ public class ArchivaDavResource
         return null;
     }
 
-    @SuppressWarnings ("unchecked")
+    @SuppressWarnings("unchecked")
     @Override
     public MultiStatusResponse alterProperties( List changeList )
         throws DavException
@@ -325,20 +319,14 @@ public class ArchivaDavResource
 
         if ( isCollection() && inputContext.hasStream() ) // New File
         {
-            FileOutputStream stream = null;
-            try
+            try (OutputStream stream = Files.newOutputStream( localFile.toPath() ))
             {
-                stream = new FileOutputStream( localFile );
                 IOUtils.copy( inputContext.getInputStream(), stream );
             }
             catch ( IOException e )
             {
                 throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
             }
-            finally
-            {
-                IOUtils.closeQuietly( stream );
-            }
 
             // TODO: a bad deployment shouldn't delete an existing file - do we need to write to a temporary location first?
             long expectedContentLength = inputContext.getContentLength();
index f437efb036cf778c676eb4994e90903c97a61a22..482b799022da74dcc6ed0009911aa18100e470d1 100644 (file)
@@ -27,9 +27,6 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.PostConstruct;
 import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -40,10 +37,8 @@ import java.util.StringTokenizer;
 
 /**
  * MimeTypes
- *
- *
  */
-@Service( "mimeTpes" )
+@Service("mimeTpes")
 public class MimeTypes
 {
     private static final String DEFAULT_MIME_TYPE = "application/octet-stream";
@@ -88,30 +83,6 @@ public class MimeTypes
         load( resource );
     }
 
-    public void load( File file )
-    {
-        if ( !file.exists() || !file.isFile() || !file.canRead() )
-        {
-            log.error( "Unable to load mime types from file " + file.getAbsolutePath() + " : not a readable file." );
-            return;
-        }
-
-        FileInputStream fis = null;
-
-        try
-        {
-            fis = new FileInputStream( file );
-        }
-        catch ( FileNotFoundException e )
-        {
-            log.error( "Unable to load mime types from file " + file.getAbsolutePath() + " : " + e.getMessage(), e );
-        }
-        finally
-        {
-            IOUtils.closeQuietly( fis );
-        }
-    }
-
     public void load( String resourceName )
     {
         ClassLoader cloader = this.getClass().getClassLoader();
@@ -124,21 +95,14 @@ public class MimeTypes
             throw new IllegalStateException( "Unable to find resource " + resourceName );
         }
 
-        InputStream mimeStream = null;
-
-        try
+        try (InputStream mimeStream = mimeURL.openStream())
         {
-            mimeStream = mimeURL.openStream();
             load( mimeStream );
         }
         catch ( IOException e )
         {
             log.error( "Unable to load mime map " + resourceName + " : " + e.getMessage(), e );
         }
-        finally
-        {
-            IOUtils.closeQuietly( mimeStream );
-        }
     }
 
     public void load( InputStream mimeStream )
index c85518a42fdb7098ddcb424bd9cb77e4bfd8548e..c7303cef5dce230360df89956ca8e9f03a4b5d8a 100644 (file)
@@ -573,8 +573,6 @@ public class Maven2RepositoryStorage
         // scan all directories in the namespace, and only include those that are known to be projects
         List<String> projects = new ArrayList<>();
 
-
-
         File[] files = dir.listFiles( new DirectoryFilter( filter ) );
         if ( files != null )
         {
index d4b3c6fed80a001244b5c2d5d4e6564ed2e0b479..15129c9a4b49fb0e0358f87e33962495a7daf99d 100644 (file)
@@ -37,15 +37,15 @@ import org.apache.archiva.metadata.model.Scm;
 import org.apache.archiva.metadata.repository.MetadataRepository;
 import org.apache.archiva.metadata.repository.MetadataRepositoryException;
 import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -61,6 +61,8 @@ import java.util.Properties;
 import java.util.Set;
 import java.util.StringTokenizer;
 
+//import org.apache.commons.io.IOUtils;
+
 public class FileMetadataRepository
     implements MetadataRepository
 {
@@ -575,7 +577,7 @@ public class FileMetadataRepository
     }
 
     @Override
-    public <T>T obtainAccess( Class<T> aClass )
+    public <T> T obtainAccess( Class<T> aClass )
     {
         throw new IllegalArgumentException(
             "Access using " + aClass + " is not supported on the file metadata storage" );
@@ -647,7 +649,8 @@ public class FileMetadataRepository
 
         File directory = new File( getDirectory( artifactMetadata.getRepositoryId() ),
                                    artifactMetadata.getNamespace() + "/" + artifactMetadata.getProject() + "/"
-                                       + baseVersion );
+                                       + baseVersion
+        );
 
         Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY );
 
@@ -870,16 +873,11 @@ public class FileMetadataRepository
         throws IOException
     {
         Properties properties = new Properties();
-        FileInputStream in = null;
-        try
+        try (InputStream in = Files.newInputStream( new File( directory, propertiesKey + ".properties" ).toPath() ))
         {
-            in = new FileInputStream( new File( directory, propertiesKey + ".properties" ) );
+
             properties.load( in );
         }
-        finally
-        {
-            IOUtils.closeQuietly( in );
-        }
         return properties;
     }
 
@@ -1240,15 +1238,10 @@ public class FileMetadataRepository
         throws IOException
     {
         directory.mkdirs();
-        FileOutputStream os = new FileOutputStream( new File( directory, propertiesKey + ".properties" ) );
-        try
+        try (OutputStream os = Files.newOutputStream( new File( directory, propertiesKey + ".properties" ).toPath() ))
         {
             properties.store( os, null );
         }
-        finally
-        {
-            IOUtils.closeQuietly( os );
-        }
     }
 
     private static class ArtifactComparator