diff options
author | Olivier Lamy <olamy@apache.org> | 2014-04-16 18:11:38 +1000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2014-04-16 18:11:38 +1000 |
commit | ec1e655c9d996f20bd231b21505a6df865d8a1f7 (patch) | |
tree | 83a6e56ba6b0e2a0f9e0bd97c2ddd1b05b5d90aa /archiva-modules/archiva-web/archiva-web-common | |
parent | 767e00c182085b193c9f2481a815e90c5c054095 (diff) | |
download | archiva-ec1e655c9d996f20bd231b21505a6df865d8a1f7.tar.gz archiva-ec1e655c9d996f20bd231b21505a6df865d8a1f7.zip |
use Files.copy from java.nio.file
Diffstat (limited to 'archiva-modules/archiva-web/archiva-web-common')
2 files changed, 9 insertions, 28 deletions
diff --git a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/api/DefaultFileUploadService.java b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/api/DefaultFileUploadService.java index 2bbaf4b06..c232e03fa 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/api/DefaultFileUploadService.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/api/DefaultFileUploadService.java @@ -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 ) { diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactsTest.java b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactsTest.java index 3192fce54..b009e8c71 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactsTest.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactsTest.java @@ -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() ); } } |