mirror of https://github.com/apache/archiva.git
more try with resources
This commit is contained in:
parent
65bcbc9d45
commit
dc91fae5fa
|
@ -725,12 +725,9 @@ public class DefaultBrowseService
|
||||||
|
|
||||||
List<Artifact> artifactDownloadInfos = new ArrayList<>();
|
List<Artifact> artifactDownloadInfos = new ArrayList<>();
|
||||||
|
|
||||||
RepositorySession session = repositorySessionFactory.createSession();
|
try (RepositorySession session = repositorySessionFactory.createSession())
|
||||||
|
|
||||||
MetadataResolver metadataResolver = session.getResolver();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
|
MetadataResolver metadataResolver = session.getResolver();
|
||||||
for ( String repoId : selectedRepos )
|
for ( String repoId : selectedRepos )
|
||||||
{
|
{
|
||||||
List<ArtifactMetadata> artifacts = new ArrayList<>(
|
List<ArtifactMetadata> artifacts = new ArrayList<>(
|
||||||
|
@ -748,13 +745,6 @@ public class DefaultBrowseService
|
||||||
throw new ArchivaRestServiceException( e.getMessage(),
|
throw new ArchivaRestServiceException( e.getMessage(),
|
||||||
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
|
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
if ( session != null )
|
|
||||||
{
|
|
||||||
session.closeQuietly();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return artifactDownloadInfos;
|
return artifactDownloadInfos;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ package org.apache.archiva.webdav.util;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -38,7 +37,7 @@ import java.util.StringTokenizer;
|
||||||
/**
|
/**
|
||||||
* MimeTypes
|
* MimeTypes
|
||||||
*/
|
*/
|
||||||
@Service("mimeTpes")
|
@Service( "mimeTpes" )
|
||||||
public class MimeTypes
|
public class MimeTypes
|
||||||
{
|
{
|
||||||
private static final String DEFAULT_MIME_TYPE = "application/octet-stream";
|
private static final String DEFAULT_MIME_TYPE = "application/octet-stream";
|
||||||
|
@ -109,39 +108,38 @@ public class MimeTypes
|
||||||
{
|
{
|
||||||
mimeMap.clear();
|
mimeMap.clear();
|
||||||
|
|
||||||
InputStreamReader reader = null;
|
try (InputStreamReader reader = new InputStreamReader( mimeStream ))
|
||||||
BufferedReader buf = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
reader = new InputStreamReader( mimeStream );
|
try (BufferedReader buf = new BufferedReader( reader ))
|
||||||
buf = new BufferedReader( reader );
|
|
||||||
String line = null;
|
|
||||||
|
|
||||||
while ( ( line = buf.readLine() ) != null )
|
|
||||||
{
|
{
|
||||||
line = line.trim();
|
|
||||||
|
|
||||||
if ( line.length() == 0 )
|
String line = null;
|
||||||
{
|
|
||||||
// empty line. skip it
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( line.startsWith( "#" ) )
|
while ( ( line = buf.readLine() ) != null )
|
||||||
{
|
{
|
||||||
// Comment. skip it
|
line = line.trim();
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
StringTokenizer tokenizer = new StringTokenizer( line );
|
if ( line.length() == 0 )
|
||||||
if ( tokenizer.countTokens() > 1 )
|
|
||||||
{
|
|
||||||
String type = tokenizer.nextToken();
|
|
||||||
while ( tokenizer.hasMoreTokens() )
|
|
||||||
{
|
{
|
||||||
String extension = tokenizer.nextToken().toLowerCase();
|
// empty line. skip it
|
||||||
this.mimeMap.put( extension, type );
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( line.startsWith( "#" ) )
|
||||||
|
{
|
||||||
|
// 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 );
|
log.error( "Unable to read mime types from input stream : " + e.getMessage(), e );
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
IOUtils.closeQuietly( buf );
|
|
||||||
IOUtils.closeQuietly( reader );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getResource()
|
public String getResource()
|
||||||
|
|
Loading…
Reference in New Issue