406768 Close inputstream and channels for 0 length resources

This commit is contained in:
Greg Wilkins 2013-04-30 14:23:26 +10:00
parent 9d32209576
commit 68b9115e07
1 changed files with 3 additions and 5 deletions

View File

@ -268,7 +268,7 @@ public class HttpOutput extends ServletOutputStream
{ {
Resource resource = (Resource)content; Resource resource = (Resource)content;
_channel.getResponse().getHttpFields().putDateField(HttpHeader.LAST_MODIFIED, resource.lastModified()); _channel.getResponse().getHttpFields().putDateField(HttpHeader.LAST_MODIFIED, resource.lastModified());
content = resource.getInputStream(); content=resource.getInputStream(); // Closed below
} }
// Process content. // Process content.
@ -279,9 +279,8 @@ public class HttpOutput extends ServletOutputStream
} }
else if (content instanceof ReadableByteChannel) else if (content instanceof ReadableByteChannel)
{ {
ReadableByteChannel channel = (ReadableByteChannel)content;
ByteBuffer buffer = _channel.getByteBufferPool().acquire(getBufferSize(), CHANNEL_BUFFER_DIRECT); ByteBuffer buffer = _channel.getByteBufferPool().acquire(getBufferSize(), CHANNEL_BUFFER_DIRECT);
try try (ReadableByteChannel channel = (ReadableByteChannel)content;)
{ {
while(channel.isOpen()) while(channel.isOpen())
{ {
@ -301,12 +300,11 @@ public class HttpOutput extends ServletOutputStream
} }
else if (content instanceof InputStream) else if (content instanceof InputStream)
{ {
InputStream in = (InputStream)content;
ByteBuffer buffer = _channel.getByteBufferPool().acquire(getBufferSize(), STREAM_BUFFER_DIRECT); ByteBuffer buffer = _channel.getByteBufferPool().acquire(getBufferSize(), STREAM_BUFFER_DIRECT);
byte[] array = buffer.array(); byte[] array = buffer.array();
int offset=buffer.arrayOffset(); int offset=buffer.arrayOffset();
int size=array.length-offset; int size=array.length-offset;
try try (InputStream in = (InputStream)content;)
{ {
while(true) while(true)
{ {