summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorThomas Becker2012-02-22 07:54:01 (EST)
committer Jesse McConnell2012-02-22 08:55:19 (EST)
commit94c979f2b2fdd20f809e948241ae2f247c75bfad (patch)
treebe795fea53f388d9567e516e8ca2f3a30f13d2d9
parent7fe545488832a7e823014f8e86a80935cc1b3ecd (diff)
downloadorg.eclipse.jetty.project-94c979f2b2fdd20f809e948241ae2f247c75bfad.zip
org.eclipse.jetty.project-94c979f2b2fdd20f809e948241ae2f247c75bfad.tar.gz
org.eclipse.jetty.project-94c979f2b2fdd20f809e948241ae2f247c75bfad.tar.bz2
372190: HttpContent.getIndirectBuffer() close InputStream
-rw-r--r--jetty-http/src/main/java/org/eclipse/jetty/http/HttpContent.java23
1 files changed, 20 insertions, 3 deletions
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpContent.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpContent.java
index 69b2f93..11d0d1c 100644
--- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpContent.java
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpContent.java
@@ -18,6 +18,8 @@ import java.io.InputStream;
import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.ByteArrayBuffer;
+import org.eclipse.jetty.util.log.Log;
+import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.resource.Resource;
/* ------------------------------------------------------------ */
@@ -41,6 +43,8 @@ public interface HttpContent
/* ------------------------------------------------------------ */
public class ResourceAsHttpContent implements HttpContent
{
+ private static final Logger LOG = Log.getLogger(ResourceAsHttpContent.class);
+
final Resource _resource;
final Buffer _mimeType;
final int _maxBuffer;
@@ -80,18 +84,31 @@ public interface HttpContent
/* ------------------------------------------------------------ */
public Buffer getIndirectBuffer()
{
+ InputStream inputStream = null;
try
{
- if (_resource.length()<=0 || _maxBuffer<_resource.length())
+ if (_resource.length() <= 0 || _maxBuffer < _resource.length())
return null;
ByteArrayBuffer buffer = new ByteArrayBuffer((int)_resource.length());
- buffer.readFrom(_resource.getInputStream(),(int)_resource.length());
+ inputStream = _resource.getInputStream();
+ buffer.readFrom(inputStream,(int)_resource.length());
return buffer;
}
- catch(IOException e)
+ catch (IOException e)
{
throw new RuntimeException(e);
}
+ finally
+ {
+ try
+ {
+ inputStream.close();
+ }
+ catch (IOException e)
+ {
+ LOG.warn("Couldn't close inputStream. Possible file handle leak",e);
+ }
+ }
}
/* ------------------------------------------------------------ */