Mercurial Hosting > luan
diff src/org/eclipse/jetty/server/AbstractHttpConnection.java @ 985:8fef34f665e7
remove HttpOutput
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 16 Oct 2016 23:47:23 -0600 |
parents | 23ec25435b8c |
children | 83cc6e05a58f |
line wrap: on
line diff
--- a/src/org/eclipse/jetty/server/AbstractHttpConnection.java Sun Oct 16 23:11:15 2016 -0600 +++ b/src/org/eclipse/jetty/server/AbstractHttpConnection.java Sun Oct 16 23:47:23 2016 -0600 @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; +import java.io.Writer; import javax.servlet.DispatcherType; import javax.servlet.RequestDispatcher; @@ -46,9 +47,11 @@ import org.eclipse.jetty.io.Buffer; import org.eclipse.jetty.io.BufferCache.CachedBuffer; import org.eclipse.jetty.io.Buffers; +import org.eclipse.jetty.io.ByteArrayBuffer; import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.EofException; import org.eclipse.jetty.io.RuntimeIOException; +import org.eclipse.jetty.util.ByteArrayOutputStream2; import org.eclipse.jetty.util.QuotedStringTokenizer; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.URIUtil; @@ -715,12 +718,83 @@ } - public final class Output extends HttpOutput + public final class Output extends ServletOutputStream { - Output() + private boolean _closed; + private ByteArrayBuffer _onebyte; + + // These are held here for reuse by Writer + String _characterEncoding; + Writer _converter; + char[] _chars; + ByteArrayOutputStream2 _bytes; + + public final void reopen() + { + _closed = false; + } + + @Override + public final void write(byte[] b, int off, int len) throws IOException + { + write(new ByteArrayBuffer(b,off,len)); + } + + @Override + public final void write(byte[] b) throws IOException + { + write(new ByteArrayBuffer(b)); + } + + @Override + public final void write(int b) throws IOException { - super(AbstractHttpConnection.this); + if (_onebyte==null) + _onebyte = new ByteArrayBuffer(1); + else + _onebyte.clear(); + _onebyte.put((byte)b); + write(_onebyte); } + + private void write(Buffer buffer) throws IOException + { + if (_closed) + throw new IOException("Closed"); + if (!_generator.isOpen()) + throw new EofException(); + + // Block until we can add _content. + while (_generator.isBufferFull()) + { + _generator.blockForOutput(getMaxIdleTime()); + if (_closed) + throw new IOException("Closed"); + if (!_generator.isOpen()) + throw new EofException(); + } + + // Add the _content + _generator.addContent(buffer, HttpGenerator.MORE); + + // Have to flush and complete headers? + + if (_generator.isAllContentWritten()) + { + flush(); + close(); + } + else if (_generator.isBufferFull()) + commitResponse(HttpGenerator.MORE); + + // Block until our buffer is free + while (buffer.length() > 0 && _generator.isOpen()) + { + _generator.blockForOutput(getMaxIdleTime()); + } + } + + /* ------------------------------------------------------------ */ /* @@ -729,15 +803,15 @@ @Override public void close() throws IOException { - if (isClosed()) + if (_closed) return; - if (!super._generator.isCommitted()) + if (!_generator.isCommitted()) commitResponse(HttpGenerator.LAST); else flushResponse(); - super.close(); + _closed = true; } @@ -748,9 +822,9 @@ @Override public void flush() throws IOException { - if (!super._generator.isCommitted()) + if (!_generator.isCommitted()) commitResponse(HttpGenerator.MORE); - super.flush(); + _generator.flush(getMaxIdleTime()); } /* ------------------------------------------------------------ */ @@ -760,25 +834,25 @@ @Override public void print(String s) throws IOException { - if (isClosed()) + if (_closed) throw new IOException("Closed"); - PrintWriter writer=getPrintWriter(null); + PrintWriter writer = getPrintWriter(null); writer.print(s); } public void sendResponse(Buffer response) throws IOException { - super._generator.sendResponse(response); + _generator.sendResponse(response); } public void sendContent(Object content) throws IOException { Resource resource=null; - if (isClosed()) + if (_closed) throw new IOException("Closed"); - if (super._generator.isWritten()) + if (_generator.isWritten()) throw new IllegalStateException("!empty"); if (content instanceof Resource) @@ -791,7 +865,7 @@ // Process content. if (content instanceof Buffer) { - super._generator.addContent((Buffer) content, HttpGenerator.LAST); + _generator.addContent((Buffer) content, HttpGenerator.LAST); commitResponse(HttpGenerator.LAST); } else if (content instanceof InputStream) @@ -800,21 +874,21 @@ try { - int max = super._generator.prepareUncheckedAddContent(); - Buffer buffer = super._generator.getUncheckedBuffer(); + int max = _generator.prepareUncheckedAddContent(); + Buffer buffer = _generator.getUncheckedBuffer(); int len=buffer.readFrom(in,max); while (len>=0) { - super._generator.completeUncheckedAddContent(); + _generator.completeUncheckedAddContent(); _out.flush(); - max = super._generator.prepareUncheckedAddContent(); - buffer = super._generator.getUncheckedBuffer(); + max = _generator.prepareUncheckedAddContent(); + buffer = _generator.getUncheckedBuffer(); len=buffer.readFrom(in,max); } - super._generator.completeUncheckedAddContent(); + _generator.completeUncheckedAddContent(); _out.flush(); } finally