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-webdav | |
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-webdav')
2 files changed, 10 insertions, 58 deletions
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResource.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResource.java index 6961d2206..c1c73eee8 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResource.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResource.java @@ -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(); diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/MimeTypes.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/MimeTypes.java index f437efb03..482b79902 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/MimeTypes.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/MimeTypes.java @@ -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 ) |