]> source.dussan.org Git - archiva.git/commitdiff
more try with resources
authorOlivier Lamy <olamy@apache.org>
Wed, 16 Apr 2014 13:00:24 +0000 (23:00 +1000)
committerOlivier Lamy <olamy@apache.org>
Wed, 16 Apr 2014 13:00:24 +0000 (23:00 +1000)
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/MimeTypes.java

index c929ff10632092656bc20107978606ffd2dfbdbd..066105e209f93a51270f773d7321b23d847ee138 100644 (file)
@@ -725,12 +725,9 @@ public class DefaultBrowseService
 
         List<Artifact> artifactDownloadInfos = new ArrayList<>();
 
-        RepositorySession session = repositorySessionFactory.createSession();
-
-        MetadataResolver metadataResolver = session.getResolver();
-
-        try
+        try (RepositorySession session = repositorySessionFactory.createSession())
         {
+            MetadataResolver metadataResolver = session.getResolver();
             for ( String repoId : selectedRepos )
             {
                 List<ArtifactMetadata> artifacts = new ArrayList<>(
@@ -748,13 +745,6 @@ public class DefaultBrowseService
             throw new ArchivaRestServiceException( e.getMessage(),
                                                    Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
         }
-        finally
-        {
-            if ( session != null )
-            {
-                session.closeQuietly();
-            }
-        }
 
         return artifactDownloadInfos;
     }
index 482b799022da74dcc6ed0009911aa18100e470d1..092c4b10080c2496e8d85136463004fb39a1acd7 100644 (file)
@@ -19,7 +19,6 @@ package org.apache.archiva.webdav.util;
  * under the License.
  */
 
-import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -38,7 +37,7 @@ import java.util.StringTokenizer;
 /**
  * MimeTypes
  */
-@Service("mimeTpes")
+@Service( "mimeTpes" )
 public class MimeTypes
 {
     private static final String DEFAULT_MIME_TYPE = "application/octet-stream";
@@ -109,39 +108,38 @@ public class MimeTypes
     {
         mimeMap.clear();
 
-        InputStreamReader reader = null;
-        BufferedReader buf = null;
-
-        try
+        try (InputStreamReader reader = new InputStreamReader( mimeStream ))
         {
-            reader = new InputStreamReader( mimeStream );
-            buf = new BufferedReader( reader );
-            String line = null;
-
-            while ( ( line = buf.readLine() ) != null )
+            try (BufferedReader buf = new BufferedReader( reader ))
             {
-                line = line.trim();
 
-                if ( line.length() == 0 )
-                {
-                    // empty line. skip it
-                    continue;
-                }
+                String line = null;
 
-                if ( line.startsWith( "#" ) )
+                while ( ( line = buf.readLine() ) != null )
                 {
-                    // Comment. skip it
-                    continue;
-                }
+                    line = line.trim();
 
-                StringTokenizer tokenizer = new StringTokenizer( line );
-                if ( tokenizer.countTokens() > 1 )
-                {
-                    String type = tokenizer.nextToken();
-                    while ( tokenizer.hasMoreTokens() )
+                    if ( line.length() == 0 )
+                    {
+                        // empty line. skip it
+                        continue;
+                    }
+
+                    if ( line.startsWith( "#" ) )
                     {
-                        String extension = tokenizer.nextToken().toLowerCase();
-                        this.mimeMap.put( extension, type );
+                        // Comment. skip it
+                        continue;
+                    }
+
+                    StringTokenizer tokenizer = new StringTokenizer( line );
+                    if ( tokenizer.countTokens() > 1 )
+                    {
+                        String type = tokenizer.nextToken();
+                        while ( tokenizer.hasMoreTokens() )
+                        {
+                            String extension = tokenizer.nextToken().toLowerCase();
+                            this.mimeMap.put( extension, type );
+                        }
                     }
                 }
             }
@@ -150,11 +148,6 @@ public class MimeTypes
         {
             log.error( "Unable to read mime types from input stream : " + e.getMessage(), e );
         }
-        finally
-        {
-            IOUtils.closeQuietly( buf );
-            IOUtils.closeQuietly( reader );
-        }
     }
 
     public String getResource()