aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-web/archiva-rest
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2014-04-16 18:11:38 +1000
committerOlivier Lamy <olamy@apache.org>2014-04-16 18:11:38 +1000
commitec1e655c9d996f20bd231b21505a6df865d8a1f7 (patch)
tree83a6e56ba6b0e2a0f9e0bd97c2ddd1b05b5d90aa /archiva-modules/archiva-web/archiva-rest
parent767e00c182085b193c9f2481a815e90c5c054095 (diff)
downloadarchiva-ec1e655c9d996f20bd231b21505a6df865d8a1f7.tar.gz
archiva-ec1e655c9d996f20bd231b21505a6df865d8a1f7.zip
use Files.copy from java.nio.file
Diffstat (limited to 'archiva-modules/archiva-web/archiva-rest')
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java4
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java19
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java30
3 files changed, 13 insertions, 40 deletions
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java
index c98b5f9d2..c929ff106 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java
@@ -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 );
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java
index 795aaf169..b7cb60d34 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java
@@ -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 );
- }
}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
index a623d82fe..4fdb5f646 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
@@ -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 )
{