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<>(
throw new ArchivaRestServiceException( e.getMessage(),
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
}
- finally
- {
- if ( session != null )
- {
- session.closeQuietly();
- }
- }
return artifactDownloadInfos;
}
* under the License.
*/
-import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* MimeTypes
*/
-@Service("mimeTpes")
+@Service( "mimeTpes" )
public class MimeTypes
{
private static final String DEFAULT_MIME_TYPE = "application/octet-stream";
{
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 );
+ }
}
}
}
{
log.error( "Unable to read mime types from input stream : " + e.getMessage(), e );
}
- finally
- {
- IOUtils.closeQuietly( buf );
- IOUtils.closeQuietly( reader );
- }
}
public String getResource()