Mercurial Hosting > luan
diff src/org/eclipse/jetty/server/AbstractHttpConnection.java @ 1010:2712133d5bce
simplify Buffer code
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 23 Oct 2016 22:23:50 -0600 |
parents | 945568ee77ac |
children | 6939226e0ac4 |
line wrap: on
line diff
--- a/src/org/eclipse/jetty/server/AbstractHttpConnection.java Sun Oct 23 21:28:56 2016 -0600 +++ b/src/org/eclipse/jetty/server/AbstractHttpConnection.java Sun Oct 23 22:23:50 2016 -0600 @@ -817,62 +817,37 @@ writer.print(s); } - public void sendContent(Object content) throws IOException + public final void sendContent(InputStream in) throws IOException { - Resource resource=null; - if (_closed) throw new IOException("Closed"); if (_generator.isWritten()) throw new IllegalStateException("!empty"); - if (content instanceof Resource) + try { - resource=(Resource)content; - _responseFields.putDateField(HttpHeaders.LAST_MODIFIED_BUFFER, resource.lastModified()); - content=resource.getInputStream(); - } - - // Process content. - if (content instanceof Buffer) - { - _generator.addContent((Buffer) content, HttpGenerator.LAST); - commitResponse(HttpGenerator.LAST); - } - else if (content instanceof InputStream) - { - InputStream in = (InputStream)content; + int max = _generator.prepareUncheckedAddContent(); + Buffer buffer = _generator.getUncheckedBuffer(); - try - { - int max = _generator.prepareUncheckedAddContent(); - Buffer buffer = _generator.getUncheckedBuffer(); - - int len=buffer.readFrom(in,max); + int len = buffer.readFrom(in,max); - while (len>=0) - { - _generator.completeUncheckedAddContent(); - _out.flush(); - - max = _generator.prepareUncheckedAddContent(); - buffer = _generator.getUncheckedBuffer(); - len=buffer.readFrom(in,max); - } + while (len>=0) + { _generator.completeUncheckedAddContent(); _out.flush(); + + max = _generator.prepareUncheckedAddContent(); + buffer = _generator.getUncheckedBuffer(); + len=buffer.readFrom(in,max); } - finally - { - if (resource!=null) - resource.release(); - else - in.close(); - } + _generator.completeUncheckedAddContent(); + _out.flush(); } - else - throw new IllegalArgumentException("unknown content type?"); + finally + { + in.close(); + } } }