mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 15:05:44 +01:00
use java7 auto close
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.resources;
|
package sonia.scm.resources;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
@@ -103,13 +104,13 @@ public abstract class AbstractResourceServlet extends HttpServlet
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||||
throws ServletException, IOException
|
throws ServletException, IOException
|
||||||
{
|
{
|
||||||
String uri = HttpUtil.getStrippedURI(request);
|
String uri = HttpUtil.getStrippedURI(request);
|
||||||
ResourceType type = getType();
|
ResourceType type = getType();
|
||||||
String nameSeparator = HttpUtil.SEPARATOR_PATH.concat(
|
String nameSeparator = HttpUtil.SEPARATOR_PATH.concat(
|
||||||
type.getExtension()).concat(
|
type.getExtension()).concat(
|
||||||
HttpUtil.SEPARATOR_PATH);
|
HttpUtil.SEPARATOR_PATH);
|
||||||
int index = uri.indexOf(nameSeparator);
|
int index = uri.indexOf(nameSeparator);
|
||||||
|
|
||||||
if (index > 0)
|
if (index > 0)
|
||||||
@@ -147,25 +148,18 @@ public abstract class AbstractResourceServlet extends HttpServlet
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private void printResource(HttpServletResponse response, Resource resource)
|
private void printResource(HttpServletResponse response, Resource resource)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
response.setContentType(resource.getType().getContentType());
|
response.setContentType(resource.getType().getContentType());
|
||||||
|
|
||||||
OutputStream output = null;
|
try (OutputStream output = response.getOutputStream())
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
output = response.getOutputStream();
|
|
||||||
resource.copyTo(output);
|
resource.copyTo(output);
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
IOUtil.close(output);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private ResourceManager resourceManager;
|
private final ResourceManager resourceManager;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ package sonia.scm.resources;
|
|||||||
|
|
||||||
import sonia.scm.plugin.PluginLoader;
|
import sonia.scm.plugin.PluginLoader;
|
||||||
import sonia.scm.util.ChecksumUtil;
|
import sonia.scm.util.ChecksumUtil;
|
||||||
import sonia.scm.util.IOUtil;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -72,19 +71,13 @@ public final class DefaultResource extends AbstractResource
|
|||||||
super(pluginLoader, resources, resourceHandlers);
|
super(pluginLoader, resources, resourceHandlers);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
try (ByteArrayOutputStream baos = new ByteArrayOutputStream())
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
appendResources(baos);
|
appendResources(baos);
|
||||||
this.content = baos.toByteArray();
|
this.content = baos.toByteArray();
|
||||||
this.name = ChecksumUtil.createChecksum(this.content).concat(".").concat(
|
this.name = ChecksumUtil.createChecksum(this.content).concat(".").concat(
|
||||||
type.getExtension());
|
type.getExtension());
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
IOUtil.close(baos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user