398467 Servlet 3.1 Non Blocking IO

completed removal of HttpOutput.closeIfAllContentWritten
This commit is contained in:
Greg Wilkins 2013-05-30 09:09:47 +10:00
parent 6f0195e0de
commit c961d65697
4 changed files with 28 additions and 15 deletions

View File

@ -48,9 +48,13 @@ public class EncodingHttpWriter extends HttpWriter
@Override
public void write (char[] s,int offset, int length) throws IOException
{
HttpOutput out = _out;
if (length==0)
_out.closeIfAllContentWritten();
{
if (_out.isAllContentWritten())
close();
}
while (length > 0)
{
_bytes.reset();
@ -58,7 +62,7 @@ public class EncodingHttpWriter extends HttpWriter
_converter.write(s, offset, chars);
_converter.flush();
_bytes.writeTo(_out);
_bytes.writeTo(out);
length-=chars;
offset+=chars;
}

View File

@ -23,7 +23,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
import java.util.concurrent.TimeoutException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletOutputStream;
@ -154,15 +153,15 @@ public class HttpOutput extends ServletOutputStream
_channel.write(BufferUtil.EMPTY_BUFFER, false);
}
public boolean closeIfAllContentWritten() throws IOException
public boolean isAllContentWritten()
{
Response response=_channel.getResponse();
if (response.isAllContentWritten(_written))
{
response.closeOutput();
return true;
}
return false;
return response.isAllContentWritten(_written);
}
public void closeOutput() throws IOException
{
_channel.getResponse().closeOutput();
}
@Override
@ -231,12 +230,16 @@ public class HttpOutput extends ServletOutputStream
BufferUtil.append(_aggregate, (byte)b);
_written++;
boolean complete=_channel.getResponse().isAllContentWritten(_written);
// Check if all written or full
if (!closeIfAllContentWritten() && BufferUtil.isFull(_aggregate))
if (complete || BufferUtil.isFull(_aggregate))
{
BlockingCallback callback = _channel.getWriteBlockingCallback();
_channel.write(_aggregate, false, callback);
callback.block();
if (complete)
closed();
}
}

View File

@ -36,7 +36,10 @@ public class Iso88591HttpWriter extends HttpWriter
{
HttpOutput out = _out;
if (length==0)
out.closeIfAllContentWritten();
{
if (_out.isAllContentWritten())
close();
}
if (length==1)
{

View File

@ -44,8 +44,11 @@ public class Utf8HttpWriter extends HttpWriter
{
HttpOutput out = _out;
if (length==0)
out.closeIfAllContentWritten();
{
if (_out.isAllContentWritten())
close();
}
while (length > 0)
{
_bytes.reset();