use java7 auto close

This commit is contained in:
Sebastian Sdorra
2014-10-10 20:32:59 +02:00
parent 63ab9e0701
commit f9fab87480
2 changed files with 8 additions and 21 deletions

View File

@@ -30,6 +30,7 @@
*/
package sonia.scm.resources;
//~--- non-JDK imports --------------------------------------------------------
@@ -103,13 +104,13 @@ public abstract class AbstractResourceServlet extends HttpServlet
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
throws ServletException, IOException
{
String uri = HttpUtil.getStrippedURI(request);
ResourceType type = getType();
String nameSeparator = HttpUtil.SEPARATOR_PATH.concat(
type.getExtension()).concat(
HttpUtil.SEPARATOR_PATH);
type.getExtension()).concat(
HttpUtil.SEPARATOR_PATH);
int index = uri.indexOf(nameSeparator);
if (index > 0)
@@ -147,25 +148,18 @@ public abstract class AbstractResourceServlet extends HttpServlet
* @throws IOException
*/
private void printResource(HttpServletResponse response, Resource resource)
throws IOException
throws IOException
{
response.setContentType(resource.getType().getContentType());
OutputStream output = null;
try
try (OutputStream output = response.getOutputStream())
{
output = response.getOutputStream();
resource.copyTo(output);
}
finally
{
IOUtil.close(output);
}
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private ResourceManager resourceManager;
private final ResourceManager resourceManager;
}

View File

@@ -37,7 +37,6 @@ package sonia.scm.resources;
import sonia.scm.plugin.PluginLoader;
import sonia.scm.util.ChecksumUtil;
import sonia.scm.util.IOUtil;
//~--- JDK imports ------------------------------------------------------------
@@ -72,19 +71,13 @@ public final class DefaultResource extends AbstractResource
super(pluginLoader, resources, resourceHandlers);
this.type = type;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try
try (ByteArrayOutputStream baos = new ByteArrayOutputStream())
{
appendResources(baos);
this.content = baos.toByteArray();
this.name = ChecksumUtil.createChecksum(this.content).concat(".").concat(
type.getExtension());
}
finally
{
IOUtil.close(baos);
}
}
//~--- methods --------------------------------------------------------------