Mercurial Hosting > luan
changeset 1048:2b769da7f67d
remove Buffer
line wrap: on
line diff
diff -r 1accf965d51a -r 2b769da7f67d src/org/eclipse/jetty/http/AbstractGenerator.java --- a/src/org/eclipse/jetty/http/AbstractGenerator.java Mon Nov 07 22:51:09 2016 -0700 +++ b/src/org/eclipse/jetty/http/AbstractGenerator.java Mon Nov 07 23:15:42 2016 -0700 @@ -20,7 +20,7 @@ import java.io.IOException; -import org.eclipse.jetty.io.Buffer; +import org.eclipse.jetty.io.JBuffer; import org.eclipse.jetty.io.Buffers; import org.eclipse.jetty.io.BufferUtil; import org.eclipse.jetty.io.EndPoint; @@ -59,8 +59,8 @@ int _status = 0; int _version = HttpVersions.HTTP_1_1_ORDINAL; - Buffer _reason; - Buffer _method; + JBuffer _reason; + JBuffer _method; String _uri; long _contentWritten = 0; @@ -70,9 +70,9 @@ boolean _noContent = false; Boolean _persistent = null; - Buffer _header; // Buffer for HTTP header (and maybe small _content) - Buffer _buffer; // Buffer for copy of passed _content - Buffer _content; // Buffer passed to addContent + JBuffer _header; // JBuffer for HTTP header (and maybe small _content) + JBuffer _buffer; // JBuffer for copy of passed _content + JBuffer _content; // JBuffer passed to addContent /* ------------------------------------------------------------------------------- */ @@ -94,12 +94,12 @@ * * @param content * @param last - * @throws IllegalArgumentException if <code>content</code> is {@link Buffer#isImmutable immutable}. + * @throws IllegalArgumentException if <code>content</code> is {@link JBuffer#isImmutable immutable}. * @throws IllegalStateException If the request is not expecting any more content, * or if the buffers are full and cannot be flushed. * @throws IOException if there is a problem flushing the buffers. */ - public abstract void addContent(Buffer content, boolean last) throws IOException; + public abstract void addContent(JBuffer content, boolean last) throws IOException; abstract boolean isRequest(); @@ -133,7 +133,7 @@ return _buffer.capacity(); } - public final Buffer getUncheckedBuffer() + public final JBuffer getUncheckedBuffer() { return _buffer; } @@ -294,8 +294,8 @@ // block until everything is flushed long now=System.currentTimeMillis(); long end=now+maxIdleTime; - Buffer content = _content; - Buffer buffer = _buffer; + JBuffer content = _content; + JBuffer buffer = _buffer; if (content!=null && content.remaining()>0 || buffer!=null && buffer.remaining()>0 || isBufferFull()) { flushBuffer();
diff -r 1accf965d51a -r 2b769da7f67d src/org/eclipse/jetty/http/HttpFields.java --- a/src/org/eclipse/jetty/http/HttpFields.java Mon Nov 07 22:51:09 2016 -0700 +++ b/src/org/eclipse/jetty/http/HttpFields.java Mon Nov 07 23:15:42 2016 -0700 @@ -39,7 +39,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import org.eclipse.jetty.io.Buffer; +import org.eclipse.jetty.io.JBuffer; import org.eclipse.jetty.io.BufferUtil; import org.eclipse.jetty.util.LazyList; import org.eclipse.jetty.util.QuotedStringTokenizer; @@ -943,7 +943,7 @@ _next = null; } - public void putTo(Buffer buffer) throws IOException + public void putTo(JBuffer buffer) throws IOException { byte[] nameBytes = StringUtil.getBytes(_name); if (getNameOrdinal() >=0 )
diff -r 1accf965d51a -r 2b769da7f67d src/org/eclipse/jetty/http/HttpGenerator.java --- a/src/org/eclipse/jetty/http/HttpGenerator.java Mon Nov 07 22:51:09 2016 -0700 +++ b/src/org/eclipse/jetty/http/HttpGenerator.java Mon Nov 07 23:15:42 2016 -0700 @@ -22,7 +22,7 @@ import java.io.InterruptedIOException; import java.util.Arrays; -import org.eclipse.jetty.io.Buffer; +import org.eclipse.jetty.io.JBuffer; import org.eclipse.jetty.io.BufferUtil; import org.eclipse.jetty.io.Buffers; import org.eclipse.jetty.io.EndPoint; @@ -126,12 +126,12 @@ * * @param content * @param last - * @throws IllegalArgumentException if <code>content</code> is {@link Buffer#isImmutable immutable}. + * @throws IllegalArgumentException if <code>content</code> is {@link JBuffer#isImmutable immutable}. * @throws IllegalStateException If the request is not expecting any more content, * or if the buffers are full and cannot be flushed. * @throws IOException if there is a problem flushing the buffers. */ - public void addContent(Buffer content, boolean last) throws IOException + public void addContent(JBuffer content, boolean last) throws IOException { if (_noContent) throw new IllegalStateException("NO CONTENT"); @@ -154,7 +154,7 @@ { if (_bufferChunked) { - Buffer nc = _buffers.getBuffer(_content.remaining()+CHUNK_SPACE+content.remaining()); + JBuffer nc = _buffers.getBuffer(_content.remaining()+CHUNK_SPACE+content.remaining()); nc.put(_content); nc.put(HttpTokens.CRLF); BufferUtil.putHexInt(nc, content.remaining()); @@ -164,7 +164,7 @@ } else { - Buffer nc = _buffers.getBuffer(_content.remaining()+content.remaining()); + JBuffer nc = _buffers.getBuffer(_content.remaining()+content.remaining()); nc.put(_content); nc.put(content); content=nc; @@ -214,7 +214,7 @@ return -1; // Handle any unfinished business? - Buffer content = _content; + JBuffer content = _content; if (content != null && content.remaining()>0 || _bufferChunked) { flushBuffer(); @@ -983,9 +983,9 @@ @Override public String toString() { - Buffer header=_header; - Buffer buffer=_buffer; - Buffer content=_content; + JBuffer header=_header; + JBuffer buffer=_buffer; + JBuffer content=_content; return String.format("%s{s=%d,h=%d,b=%d,c=%d}", getClass().getSimpleName(), _state,
diff -r 1accf965d51a -r 2b769da7f67d src/org/eclipse/jetty/http/HttpParser.java --- a/src/org/eclipse/jetty/http/HttpParser.java Mon Nov 07 22:51:09 2016 -0700 +++ b/src/org/eclipse/jetty/http/HttpParser.java Mon Nov 07 23:15:42 2016 -0700 @@ -20,7 +20,7 @@ import java.io.IOException; -import org.eclipse.jetty.io.Buffer; +import org.eclipse.jetty.io.JBuffer; import org.eclipse.jetty.io.BufferUtil; import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.EofException; @@ -56,9 +56,9 @@ private final EventHandler _handler; private final EndPoint _endp; - public final Buffer _header; // Buffer for header data (and small _content) - private final Buffer _body; // Buffer for large content - private Buffer _buffer; // The current buffer in use (either _header or _content) + public final JBuffer _header; // JBuffer for header data (and small _content) + private final JBuffer _body; // JBuffer for large content + private JBuffer _buffer; // The current buffer in use (either _header or _content) private int _mark = -1; private String _cached; private String _tok0 = ""; // Saved token: header name, request method or response version @@ -67,7 +67,7 @@ private int _responseStatus; // If >0 then we are parsing a response private boolean _persistent; - private Buffer _contentView = BufferUtil.EMPTY_BUFFER; // View of the content in the buffer for {@link Input} + private JBuffer _contentView = BufferUtil.EMPTY_BUFFER; // View of the content in the buffer for {@link Input} private int _state = STATE_START; private byte _eol; private int _length; @@ -77,7 +77,7 @@ private int _chunkPosition; private boolean _headResponse; - public HttpParser(Buffer headerBuffer,Buffer bodyBuffer, EndPoint endp, EventHandler handler) + public HttpParser(JBuffer headerBuffer,JBuffer bodyBuffer, EndPoint endp, EventHandler handler) { _header = headerBuffer; _body = bodyBuffer; @@ -89,8 +89,8 @@ _mark = _buffer.getIndex() - 1; } - private Buffer sliceFromMark() { - Buffer buf = _buffer.sliceFrom(_mark); + private JBuffer sliceFromMark() { + JBuffer buf = _buffer.sliceFrom(_mark); _mark = -1; return buf; } @@ -234,7 +234,7 @@ { if (_buffer.remaining()>0 && !_headResponse) { - Buffer chunk = _buffer.get(_buffer.remaining()); + JBuffer chunk = _buffer.get(_buffer.remaining()); _contentPosition += chunk.remaining(); _contentView = chunk; _handler.content(); // May recurse here @@ -781,7 +781,7 @@ { case STATE_EOF_CONTENT: { - Buffer chunk = _buffer.get(_buffer.remaining()); + JBuffer chunk = _buffer.get(_buffer.remaining()); _contentPosition += chunk.remaining(); _contentView = chunk; _handler.content(); // May recurse here @@ -806,7 +806,7 @@ length=(int)remaining; } - Buffer chunk = _buffer.get(length); + JBuffer chunk = _buffer.get(length); _contentPosition += chunk.remaining(); _contentView = chunk; _handler.content(); // May recurse here @@ -897,7 +897,7 @@ } else if (length > remaining) length=remaining; - Buffer chunk = _buffer.get(length); + JBuffer chunk = _buffer.get(length); _contentPosition += chunk.remaining(); _chunkPosition += chunk.remaining(); _contentView = chunk; @@ -1005,7 +1005,7 @@ _contentLength); } - public Buffer blockForContent(long maxIdleTime) throws IOException + public JBuffer blockForContent(long maxIdleTime) throws IOException { if (_contentView.remaining()>0) return _contentView;
diff -r 1accf965d51a -r 2b769da7f67d src/org/eclipse/jetty/http/MimeTypes.java --- a/src/org/eclipse/jetty/http/MimeTypes.java Mon Nov 07 22:51:09 2016 -0700 +++ b/src/org/eclipse/jetty/http/MimeTypes.java Mon Nov 07 23:15:42 2016 -0700 @@ -25,7 +25,6 @@ import java.util.MissingResourceException; import java.util.ResourceBundle; -import org.eclipse.jetty.io.Buffer; import org.eclipse.jetty.io.StringCache; import org.eclipse.jetty.util.StringUtil; import org.slf4j.Logger;
diff -r 1accf965d51a -r 2b769da7f67d src/org/eclipse/jetty/io/Buffer.java --- a/src/org/eclipse/jetty/io/Buffer.java Mon Nov 07 22:51:09 2016 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,265 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. -// ------------------------------------------------------------------------ -// All rights reserved. This program and the accompanying materials -// are made available under the terms of the Eclipse Public License v1.0 -// and Apache License v2.0 which accompanies this distribution. -// -// The Eclipse Public License is available at -// http://www.eclipse.org/legal/epl-v10.html -// -// The Apache License v2.0 is available at -// http://www.opensource.org/licenses/apache2.0.php -// -// You may elect to redistribute this code under either of these licenses. -// ======================================================================== -// - -package org.eclipse.jetty.io; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.charset.Charset; - - -/** - * Byte Buffer interface. - * - * This is a byte buffer that is designed to work like a FIFO for bytes. Puts and Gets operate on different - * pointers into the buffer and the valid _content of the buffer is always between the getIndex and the putIndex. - * - * This buffer interface is designed to be similar, but not dependent on the java.nio buffers, which may - * be used to back an implementation of this Buffer. The main difference is that NIO buffer after a put have - * their valid _content before the position and a flip is required to access that data. - * - * For this buffer it is always true that: - * markValue <= getIndex <= putIndex <= capacity - * - * - * @version 1.0 - */ -public interface Buffer -{ - public final static int - READONLY=1, // indexes may be changed, but not content - READWRITE=2; // anything can be changed - - /** - * Get the underlying array, if one exists. - * @return a <code>byte[]</code> backing this buffer or null if none exists. - */ - byte[] array(); - - /** - * Get the underlying buffer. If this buffer wraps a backing buffer. - * @return The root backing buffer or this if there is no backing buffer; - */ - Buffer buffer(); - - /** - * - * The capacity of the buffer. This is the maximum putIndex that may be set. - * @return an <code>int</code> value - */ - int capacity(); - - /** - * the space remaining in the buffer. - * @return capacity - putIndex - */ - int space(); - - /** - * Clear the buffer. getIndex=0, putIndex=0. - */ - void clear(); - - /** - * Compact the buffer by discarding bytes before the postion (or mark if set). - * Bytes from the getIndex (or mark) to the putIndex are moved to the beginning of - * the buffer and the values adjusted accordingly. - */ - void compact(); - - /** - * Get the byte at the current getIndex and increment it. - * @return The <code>byte</code> value from the current getIndex. - */ - byte get(); - - /** - * Get bytes from the current postion and put them into the passed byte array. - * The getIndex is incremented by the number of bytes copied into the array. - * @param b The byte array to fill. - * @param offset Offset in the array. - * @param length The max number of bytes to read. - * @return The number of bytes actually read. - */ - int get(byte[] b, int offset, int length); - - /** - * - * @param length an <code>int</code> value - * @return a <code>Buffer</code> value - */ - Buffer get(int length); - - /** - * The index within the buffer that will next be read or written. - * @return an <code>int</code> value >=0 <= putIndex() - */ - int getIndex(); - - /** - * @return true of putIndex > getIndex - */ - boolean hasRemaining(); - - /** - * - * @return a <code>boolean</code> value true if the buffer is readonly. The buffer indexes may - * be modified, but the buffer contents may not. For example a View onto an immutable Buffer will be - * read only. - */ - boolean isReadOnly(); - - /** - * The number of bytes from the getIndex to the putIndex - * @return an <code>int</code> == putIndex()-getIndex() - */ - int remaining(); - - /** - * Get the byte at the current getIndex without incrementing the getIndex. - * @return The <code>byte</code> value from the current getIndex. - */ - byte peek(); - - /** - * Get the byte at a specific index in the buffer. - * @param index an <code>int</code> value - * @return a <code>byte</code> value - */ - byte peek(int index); - - String toString(int index, int length); - - /** - * - * @param index an <code>int</code> value - * @param b The byte array to peek into - * @param offset The offset into the array to start peeking - * @param length an <code>int</code> value - * @return The number of bytes actually peeked - */ - int peek(int index, byte[] b, int offset, int length); - - /** - * Put the contents of the buffer at the specific index. - * @param index an <code>int</code> value - * @param src a <code>Buffer</code>. If the source buffer is not modified - - * @return The number of bytes actually poked - */ - int poke(int index, Buffer src); - - /** - * Put a specific byte to a specific getIndex. - * @param index an <code>int</code> value - * @param b a <code>byte</code> value - */ - void poke(int index, byte b); - - /** - * Put a specific byte to a specific getIndex. - * @param index an <code>int</code> value - * @param b a <code>byte array</code> value - * @return The number of bytes actually poked - */ - int poke(int index, byte b[], int offset, int length); - - /** - * Write the bytes from the source buffer to the current getIndex. - * @param src The source <code>Buffer</code> it is not modified. - * @return The number of bytes actually poked - */ - int put(Buffer src); - - /** - * Put a byte to the current getIndex and increment the getIndex. - * @param b a <code>byte</code> value - */ - void put(byte b); - - /** - * Put a byte to the current getIndex and increment the getIndex. - * @param b a <code>byte</code> value - * @return The number of bytes actually poked - */ - int put(byte[] b,int offset, int length); - - /** - * Put a byte to the current getIndex and increment the getIndex. - * @param b a <code>byte</code> value - * @return The number of bytes actually poked - */ - int put(byte[] b); - - /** - * The index of the first element that should not be read. - * @return an <code>int</code> value >= getIndex() - */ - int putIndex(); - - /** - * Set the buffers start getIndex. - * @param newStart an <code>int</code> value - */ - void setGetIndex(int newStart); - - /** - * - * @param newLimit an <code>int</code> value - */ - void setPutIndex(int newLimit); - - /** - * Skip _content. The getIndex is updated by min(remaining(), n) - * @param n The number of bytes to skip - * @return the number of bytes skipped. - */ - int skip(int n); - - /** - * - * @return a volitile <code>Buffer</code> from the postion to the putIndex. - */ - Buffer slice(); - - public Buffer sliceFrom(int index); - - /** - * - * @return a <code>String</code> value describing the state and contents of the buffer. - */ - String toDetailString(); - - /* ------------------------------------------------------------ */ - /** Read the buffer's contents from the input stream - * @param in input stream - * @param max maximum number of bytes that may be read - * @return actual number of bytes read or -1 for EOF - */ - int readFrom(InputStream in, int max) throws IOException; - - - String toString(String charset); - - - // like ByteBuffer - Buffer duplicate(); - - public byte[] asArray(); -}
diff -r 1accf965d51a -r 2b769da7f67d src/org/eclipse/jetty/io/BufferUtil.java --- a/src/org/eclipse/jetty/io/BufferUtil.java Mon Nov 07 22:51:09 2016 -0700 +++ b/src/org/eclipse/jetty/io/BufferUtil.java Mon Nov 07 23:15:42 2016 -0700 @@ -19,7 +19,6 @@ package org.eclipse.jetty.io; import java.nio.ByteBuffer; -import org.eclipse.jetty.io.nio.NIOBuffer; import org.eclipse.jetty.util.StringUtil; @@ -42,7 +41,7 @@ * @param buffer A buffer containing an integer. The position is not changed. * @return an int */ - public static int toInt(Buffer buffer) + public static int toInt(JBuffer buffer) { int val= 0; boolean started= false; @@ -109,7 +108,7 @@ throw new NumberFormatException(s); } - public static void putHexInt(Buffer buffer, int n) + public static void putHexInt(JBuffer buffer, int n) { if (n < 0) @@ -163,7 +162,7 @@ * @param buffer * @param n */ - public static void prependHexInt(Buffer buffer, int n) + public static void prependHexInt(JBuffer buffer, int n) { if (n==0) { @@ -195,7 +194,7 @@ } - public static void putDecLong(Buffer buffer, long n) + public static void putDecLong(JBuffer buffer, long n) { if (n < 0) { @@ -271,36 +270,36 @@ }; - public static void putCRLF(Buffer buffer) + public static void putCRLF(JBuffer buffer) { buffer.put((byte)13); buffer.put((byte)10); } - public static final NIOBuffer EMPTY_BUFFER = new JBuffer(ByteBuffer.allocate(0)); + public static final JBuffer EMPTY_BUFFER = new JBuffer(ByteBuffer.allocate(0)); - public static NIOBuffer wrap(byte[] array,int offset,int length) { + public static JBuffer wrap(byte[] array,int offset,int length) { return new JBuffer(ByteBuffer.wrap(array,offset,length)); } - public static NIOBuffer wrap(byte[] array) { + public static JBuffer wrap(byte[] array) { return new JBuffer(ByteBuffer.wrap(array)); } - public static NIOBuffer wrap(String s) { + public static JBuffer wrap(String s) { byte[] bytes = StringUtil.getBytes(s); ByteBuffer bb = ByteBuffer.wrap(bytes).asReadOnlyBuffer(); return new JBuffer(bb); } - public static NIOBuffer newBuffer(int size) { + public static JBuffer newBuffer(int size) { ByteBuffer bb = ByteBuffer.allocate(size); bb.limit(0); return new JBuffer(bb); } - public static NIOBuffer newDirectBuffer(int size) { + public static JBuffer newDirectBuffer(int size) { ByteBuffer bb = ByteBuffer.allocateDirect(size); bb.limit(0); return new JBuffer(bb);
diff -r 1accf965d51a -r 2b769da7f67d src/org/eclipse/jetty/io/Buffers.java --- a/src/org/eclipse/jetty/io/Buffers.java Mon Nov 07 22:51:09 2016 -0700 +++ b/src/org/eclipse/jetty/io/Buffers.java Mon Nov 07 23:15:42 2016 -0700 @@ -28,7 +28,7 @@ */ public interface Buffers { - Buffer getHeader(); - Buffer getBuffer(); - Buffer getBuffer(int size); + JBuffer getHeader(); + JBuffer getBuffer(); + JBuffer getBuffer(int size); }
diff -r 1accf965d51a -r 2b769da7f67d src/org/eclipse/jetty/io/EndPoint.java --- a/src/org/eclipse/jetty/io/EndPoint.java Mon Nov 07 22:51:09 2016 -0700 +++ b/src/org/eclipse/jetty/io/EndPoint.java Mon Nov 07 23:15:42 2016 -0700 @@ -55,7 +55,7 @@ * filled or -1 if EOF is reached. * @throws EofException If input is shutdown or the endpoint is closed. */ - int fill(Buffer buffer) throws IOException; + int fill(JBuffer buffer) throws IOException; /** @@ -68,7 +68,7 @@ * @return the number of bytes written * @throws EofException If the endpoint is closed or output is shutdown. */ - int flush(Buffer buffer) throws IOException; + int flush(JBuffer buffer) throws IOException; /** * Flush the buffer from the current getIndex to it's putIndex using whatever byte @@ -83,7 +83,7 @@ * @param trailer A buffer to write after flushing this buffer. This buffers getIndex is updated. * @return the total number of bytes written. */ - int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException; + int flush(JBuffer header, JBuffer buffer, JBuffer trailer) throws IOException; /* ------------------------------------------------------------ */
diff -r 1accf965d51a -r 2b769da7f67d src/org/eclipse/jetty/io/JBuffer.java --- a/src/org/eclipse/jetty/io/JBuffer.java Mon Nov 07 22:51:09 2016 -0700 +++ b/src/org/eclipse/jetty/io/JBuffer.java Mon Nov 07 23:15:42 2016 -0700 @@ -9,11 +9,10 @@ import java.nio.channels.ReadableByteChannel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.eclipse.jetty.io.nio.NIOBuffer; import org.eclipse.jetty.util.TypeUtil; -public final class JBuffer implements NIOBuffer { +public final class JBuffer { private static final Logger LOG = LoggerFactory.getLogger(JBuffer.class); private final ByteBuffer bb; @@ -22,37 +21,30 @@ this.bb = bb; } - @Override public byte[] array() { return bb.hasArray() ? bb.array() : null; } - @Override - public Buffer duplicate() { + public JBuffer duplicate() { return new JBuffer(bb.duplicate()); } - @Override public int remaining() { return bb.remaining(); } - @Override public boolean isReadOnly() { return bb.isReadOnly(); } - @Override public boolean hasRemaining() { return bb.hasRemaining(); } - @Override public byte get() { return bb.get(); } - @Override public void compact() { int n = bb.remaining(); bb.compact(); @@ -60,49 +52,41 @@ bb.limit(n); } - @Override public int capacity() { return bb.capacity(); } - @Override public boolean isDirect() { return bb.isDirect(); } - @Override public ByteBuffer getByteBuffer() { ByteBuffer dup = bb.duplicate(); dup.limit(dup.capacity()); return dup; } - @Override public int getIndex() { return bb.position(); } - @Override public void clear() { bb.position(0); bb.limit(0); } - @Override public int space() { return bb.capacity() - bb.limit(); } - @Override - public Buffer buffer() { + public JBuffer buffer() { return this; } - @Override - public Buffer get(int length) { + public JBuffer get(int length) { ByteBuffer dup = bb.duplicate(); int end = bb.position()+length; dup.limit(end); @@ -110,7 +94,6 @@ return new JBuffer(dup); } - @Override public int get(byte[] b, int offset, int length) { int remaining = bb.remaining(); if( remaining == 0 ) @@ -122,12 +105,10 @@ } - @Override - public int put(Buffer src) { + public int put(JBuffer src) { return put(src.asArray()); } - @Override public void put(byte b) { ByteBuffer dup = bb.duplicate(); @@ -137,7 +118,6 @@ bb.limit(bb.limit()+1); } - @Override public int put(byte[] b, int offset, int length) { ByteBuffer dup = bb.duplicate(); int put = bb.limit(); @@ -151,47 +131,39 @@ return length; } - @Override public int put(byte[] b) { return put(b,0,b.length); } - @Override public final int putIndex() { return bb.limit(); } - @Override public void setGetIndex(int getIndex) { bb.position(getIndex); } - @Override public void setPutIndex(int putIndex) { bb.limit(putIndex); } - @Override public int skip(int n) { if (remaining() < n) n = remaining(); bb.position(bb.position() + n); return n; } - @Override - public Buffer slice() { + public JBuffer slice() { return duplicate(); } - @Override - public final Buffer sliceFrom(int index) { + public final JBuffer sliceFrom(int index) { ByteBuffer dup = bb.duplicate(); dup.position(index); dup.limit(bb.position()-1); return new JBuffer(dup); } - @Override public int readFrom(InputStream in,int max) throws IOException { ByteBuffer dup = bb.duplicate(); int put = bb.limit(); @@ -218,7 +190,6 @@ return toString("ISO-8859-1"); } - @Override public final String toString(int index, int length) { ByteBuffer dup = bb.duplicate(); dup.limit(index+length); @@ -226,7 +197,6 @@ return new JBuffer(dup).toString(); } - @Override public final String toString(String charset) { byte[] bytes = asArray(); @@ -241,7 +211,6 @@ } } - @Override public String toDetailString() { StringBuilder buf = new StringBuilder(); @@ -276,45 +245,39 @@ - private Buffer pokeBuffer(int index) { - Buffer dup = duplicate(); + private JBuffer pokeBuffer(int index) { + JBuffer dup = duplicate(); dup.setPutIndex(index); return dup; } - @Override public int poke(int index, byte b[], int offset, int length) { return pokeBuffer(index).put(b,offset,length); } - @Override public void poke(int index, byte b) { pokeBuffer(index).put(b); } - @Override - public int poke(int index, Buffer src) { + public int poke(int index, JBuffer src) { return pokeBuffer(index).put(src); } - private Buffer peekBuffer(int index) { - Buffer dup = duplicate(); + private JBuffer peekBuffer(int index) { + JBuffer dup = duplicate(); dup.setGetIndex(index); dup.setPutIndex(dup.capacity()); return dup; } - @Override public int peek(int index, byte[] b, int offset, int length) { return peekBuffer(index).get(b,offset,length); } - @Override public byte peek(int index) { return bb.get(index); } - @Override public byte peek() { return peek(bb.position()); }
diff -r 1accf965d51a -r 2b769da7f67d src/org/eclipse/jetty/io/nio/ChannelEndPoint.java --- a/src/org/eclipse/jetty/io/nio/ChannelEndPoint.java Mon Nov 07 22:51:09 2016 -0700 +++ b/src/org/eclipse/jetty/io/nio/ChannelEndPoint.java Mon Nov 07 23:15:42 2016 -0700 @@ -27,7 +27,7 @@ import java.nio.channels.GatheringByteChannel; import java.nio.channels.SocketChannel; -import org.eclipse.jetty.io.Buffer; +import org.eclipse.jetty.io.JBuffer; import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.util.StringUtil; import org.slf4j.Logger; @@ -164,116 +164,93 @@ } @Override - public int fill(Buffer buffer) throws IOException + public int fill(JBuffer buffer) throws IOException { if (_ishut) return -1; - Buffer buf = buffer.buffer(); + JBuffer nbuf = buffer.buffer(); int len = 0; - if (buf instanceof NIOBuffer) + final ByteBuffer bbuf = nbuf.getByteBuffer(); + + //noinspection SynchronizationOnLocalVariableOrMethodParameter + try { - final NIOBuffer nbuf = (NIOBuffer)buf; - final ByteBuffer bbuf = nbuf.getByteBuffer(); + synchronized(bbuf) + { + try + { + bbuf.position(buffer.putIndex()); + len = _channel.read(bbuf); + } + finally + { + buffer.setPutIndex(bbuf.position()); + bbuf.position(0); + } + } - //noinspection SynchronizationOnLocalVariableOrMethodParameter + if (len<0 && isOpen()) + { + if (!isInputShutdown()) + shutdownInput(); + if (isOutputShutdown()) + _channel.close(); + } + } + catch (IOException x) + { + LOG.debug("Exception while filling", x); try { - synchronized(bbuf) - { - try - { - bbuf.position(buffer.putIndex()); - len = _channel.read(bbuf); - } - finally - { - buffer.setPutIndex(bbuf.position()); - bbuf.position(0); - } - } - - if (len<0 && isOpen()) - { - if (!isInputShutdown()) - shutdownInput(); - if (isOutputShutdown()) - _channel.close(); - } + if (_channel.isOpen()) + _channel.close(); } - catch (IOException x) + catch (Exception xx) { - LOG.debug("Exception while filling", x); - try - { - if (_channel.isOpen()) - _channel.close(); - } - catch (Exception xx) - { - LOG.trace("",xx); - } + LOG.trace("",xx); + } - if (len>0) - throw x; - len = -1; - } - } - else - { - throw new IOException("Not Implemented"); + if (len>0) + throw x; + len = -1; } return len; } @Override - public int flush(Buffer buffer) throws IOException + public int flush(JBuffer buffer) throws IOException { - Buffer buf = buffer.buffer(); + JBuffer nbuf = buffer.buffer(); int len=0; - if (buf instanceof NIOBuffer) + final ByteBuffer bbuf = nbuf.getByteBuffer().asReadOnlyBuffer(); + try { - final NIOBuffer nbuf = (NIOBuffer)buf; - final ByteBuffer bbuf = nbuf.getByteBuffer().asReadOnlyBuffer(); - try - { - bbuf.position(buffer.getIndex()); - bbuf.limit(buffer.putIndex()); - len=_channel.write(bbuf); - } - finally - { - if (len>0) - buffer.skip(len); - } + bbuf.position(buffer.getIndex()); + bbuf.limit(buffer.putIndex()); + len=_channel.write(bbuf); } - else if (buffer.array()!=null) + finally { - ByteBuffer b = ByteBuffer.wrap(buffer.array(), buffer.getIndex(), buffer.remaining()); - len=_channel.write(b); if (len>0) buffer.skip(len); } - else - { - throw new IOException("Not Implemented"); - } return len; } @Override - public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException + public int flush(JBuffer header, JBuffer buffer, JBuffer trailer) throws IOException { int length=0; - Buffer buf0 = header==null?null:header.buffer(); - Buffer buf1 = buffer==null?null:buffer.buffer(); + JBuffer buf0 = header==null?null:header.buffer(); + JBuffer buf1 = buffer==null?null:buffer.buffer(); if (_channel instanceof GatheringByteChannel && - header!=null && header.remaining()!=0 && buf0 instanceof NIOBuffer && - buffer!=null && buffer.remaining()!=0 && buf1 instanceof NIOBuffer) + header!=null && header.remaining()!=0 && + buffer!=null && buffer.remaining()!=0) { - length = gatheringFlush(header,((NIOBuffer)buf0).getByteBuffer(),buffer,((NIOBuffer)buf1).getByteBuffer()); + length = gatheringFlush(header,buf0.getByteBuffer(),buffer,buf1.getByteBuffer()); } else { @@ -296,7 +273,7 @@ return length; } - private int gatheringFlush(Buffer header, ByteBuffer bbuf0, Buffer buffer, ByteBuffer bbuf1) throws IOException + private int gatheringFlush(JBuffer header, ByteBuffer bbuf0, JBuffer buffer, ByteBuffer bbuf1) throws IOException { int length;
diff -r 1accf965d51a -r 2b769da7f67d src/org/eclipse/jetty/io/nio/NIOBuffer.java --- a/src/org/eclipse/jetty/io/nio/NIOBuffer.java Mon Nov 07 22:51:09 2016 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. -// ------------------------------------------------------------------------ -// All rights reserved. This program and the accompanying materials -// are made available under the terms of the Eclipse Public License v1.0 -// and Apache License v2.0 which accompanies this distribution. -// -// The Eclipse Public License is available at -// http://www.eclipse.org/legal/epl-v10.html -// -// The Apache License v2.0 is available at -// http://www.opensource.org/licenses/apache2.0.php -// -// You may elect to redistribute this code under either of these licenses. -// ======================================================================== -// - -package org.eclipse.jetty.io.nio; - -import java.nio.ByteBuffer; - -import org.eclipse.jetty.io.Buffer; - - -public interface NIOBuffer extends Buffer -{ - public ByteBuffer getByteBuffer(); - - public boolean isDirect(); -}
diff -r 1accf965d51a -r 2b769da7f67d src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java --- a/src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java Mon Nov 07 22:51:09 2016 -0700 +++ b/src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java Mon Nov 07 23:15:42 2016 -0700 @@ -28,7 +28,7 @@ import java.util.concurrent.RejectedExecutionException; import org.eclipse.jetty.io.AsyncEndPoint; -import org.eclipse.jetty.io.Buffer; +import org.eclipse.jetty.io.JBuffer; import org.eclipse.jetty.io.EofException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -157,14 +157,14 @@ } @Override - public int fill(Buffer buffer) throws IOException + public int fill(JBuffer buffer) throws IOException { int fill=super.fill(buffer); return fill; } @Override - public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException + public int flush(JBuffer header, JBuffer buffer, JBuffer trailer) throws IOException { int l = super.flush(header, buffer, trailer); @@ -186,7 +186,7 @@ } @Override - public int flush(Buffer buffer) throws IOException + public int flush(JBuffer buffer) throws IOException { int l = super.flush(buffer);
diff -r 1accf965d51a -r 2b769da7f67d src/org/eclipse/jetty/io/nio/SslConnection.java --- a/src/org/eclipse/jetty/io/nio/SslConnection.java Mon Nov 07 22:51:09 2016 -0700 +++ b/src/org/eclipse/jetty/io/nio/SslConnection.java Mon Nov 07 23:15:42 2016 -0700 @@ -30,7 +30,7 @@ import org.eclipse.jetty.io.AbstractConnection; import org.eclipse.jetty.io.AsyncEndPoint; -import org.eclipse.jetty.io.Buffer; +import org.eclipse.jetty.io.JBuffer; import org.eclipse.jetty.io.BufferUtil; import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.server.AsyncHttpConnection; @@ -51,7 +51,7 @@ { private final Logger _logger = LoggerFactory.getLogger("org.eclipse.jetty.io.nio.ssl"); - private static final NIOBuffer __ZERO_BUFFER = BufferUtil.EMPTY_BUFFER; + private static final JBuffer __ZERO_BUFFER = BufferUtil.EMPTY_BUFFER; private static final ThreadLocal<SslBuffers> __buffers = new ThreadLocal<SslBuffers>(); private final SSLEngine _engine; @@ -60,9 +60,9 @@ private final SslEndPoint _sslEndPoint; private int _allocations; private SslBuffers _buffers; - private NIOBuffer _inbound; - private NIOBuffer _unwrapBuf; - private NIOBuffer _outbound; + private JBuffer _inbound; + private JBuffer _unwrapBuf; + private JBuffer _outbound; private final AsyncEndPoint _aEndp; private boolean _allowRenegotiate = true; private boolean _handshook; @@ -75,9 +75,9 @@ */ private static class SslBuffers { - final NIOBuffer _in; - final NIOBuffer _out; - final NIOBuffer _unwrap; + final JBuffer _in; + final JBuffer _out; + final JBuffer _unwrap; SslBuffers(int packetSize, int appSize) { @@ -209,7 +209,7 @@ { } - private synchronized boolean process(Buffer toFill, Buffer toFlush) throws IOException + private synchronized boolean process(JBuffer toFill, JBuffer toFlush) throws IOException { boolean some_progress=false; try @@ -376,7 +376,7 @@ } } - private synchronized boolean wrap(final Buffer buffer) throws IOException + private synchronized boolean wrap(final JBuffer buffer) throws IOException { ByteBuffer bbuf=extractByteBuffer(buffer); final SSLEngineResult result; @@ -449,7 +449,7 @@ return result.bytesConsumed()>0 || result.bytesProduced()>0; } - private synchronized boolean unwrap(final Buffer buffer) throws IOException + private synchronized boolean unwrap(final JBuffer buffer) throws IOException { if (!_inbound.hasRemaining()) return false; @@ -532,11 +532,9 @@ } - private ByteBuffer extractByteBuffer(Buffer buffer) + private ByteBuffer extractByteBuffer(JBuffer buffer) { - if (buffer.buffer() instanceof NIOBuffer) - return ((NIOBuffer)buffer.buffer()).getByteBuffer(); - return ByteBuffer.wrap(buffer.array()); + return buffer.getByteBuffer(); } public SslEndPoint getSslEndPoint() @@ -604,7 +602,7 @@ _endp.close(); } - public int fill(Buffer buffer) throws IOException + public int fill(JBuffer buffer) throws IOException { int size=buffer.remaining(); process(buffer, null); @@ -616,14 +614,14 @@ return filled; } - public int flush(Buffer buffer) throws IOException + public int flush(JBuffer buffer) throws IOException { int size = buffer.remaining(); process(null, buffer); return size-buffer.remaining(); } - public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException + public int flush(JBuffer header, JBuffer buffer, JBuffer trailer) throws IOException { if (header!=null && header.hasRemaining()) return flush(header); @@ -735,9 +733,9 @@ // Do NOT use synchronized (SslConnection.this) // because it's very easy to deadlock when debugging is enabled. // We do a best effort to print the right toString() and that's it. - Buffer inbound = _inbound; - Buffer outbound = _outbound; - Buffer unwrap = _unwrapBuf; + JBuffer inbound = _inbound; + JBuffer outbound = _outbound; + JBuffer unwrap = _unwrapBuf; int i = inbound == null? -1 : inbound.remaining(); int o = outbound == null ? -1 : outbound.remaining(); int u = unwrap == null ? -1 : unwrap.remaining();
diff -r 1accf965d51a -r 2b769da7f67d src/org/eclipse/jetty/server/AbstractHttpConnection.java --- a/src/org/eclipse/jetty/server/AbstractHttpConnection.java Mon Nov 07 22:51:09 2016 -0700 +++ b/src/org/eclipse/jetty/server/AbstractHttpConnection.java Mon Nov 07 23:15:42 2016 -0700 @@ -40,7 +40,7 @@ import org.eclipse.jetty.http.HttpVersions; import org.eclipse.jetty.http.MimeTypes; import org.eclipse.jetty.io.AbstractConnection; -import org.eclipse.jetty.io.Buffer; +import org.eclipse.jetty.io.JBuffer; import org.eclipse.jetty.io.Buffers; import org.eclipse.jetty.io.BufferUtil; import org.eclipse.jetty.io.EndPoint; @@ -704,7 +704,7 @@ public final class Output extends ServletOutputStream { private boolean _closed; - private Buffer _onebyte; + private JBuffer _onebyte; // These are held here for reuse by Writer String _characterEncoding; @@ -740,7 +740,7 @@ write(_onebyte); } - private void write(Buffer buffer) throws IOException + private void write(JBuffer buffer) throws IOException { if (_closed) throw new IOException("Closed"); @@ -834,7 +834,7 @@ try { int max = _generator.prepareUncheckedAddContent(); - Buffer buffer = _generator.getUncheckedBuffer(); + JBuffer buffer = _generator.getUncheckedBuffer(); int len = buffer.readFrom(in,max); @@ -880,7 +880,7 @@ public int read(byte[] b, int off, int len) throws IOException { int l = -1; - Buffer content = _parser.blockForContent(getMaxIdleTime()); + JBuffer content = _parser.blockForContent(getMaxIdleTime()); if (content!=null) l = content.get(b, off, len); else if (_earlyEOF)
diff -r 1accf965d51a -r 2b769da7f67d src/org/eclipse/jetty/server/Connector.java --- a/src/org/eclipse/jetty/server/Connector.java Mon Nov 07 22:51:09 2016 -0700 +++ b/src/org/eclipse/jetty/server/Connector.java Mon Nov 07 23:15:42 2016 -0700 @@ -28,7 +28,7 @@ import javax.servlet.ServletRequest; -import org.eclipse.jetty.io.Buffer; +import org.eclipse.jetty.io.JBuffer; import org.eclipse.jetty.io.Buffers; import org.eclipse.jetty.io.BufferUtil; import org.eclipse.jetty.io.EndPoint; @@ -43,7 +43,7 @@ * <ul> * <li>AbstractLifeCycle implementation</li> * <li>Implementations for connector getters and setters</li> - * <li>Buffer management</li> + * <li>JBuffer management</li> * <li>Socket configuration</li> * <li>Base acceptor thread</li> * <li>Optional reverse proxy headers checking</li> @@ -251,7 +251,7 @@ // my own buffers - protected Buffer newBuffer(int size) { + protected JBuffer newBuffer(int size) { return BufferUtil.newDirectBuffer(size); } @@ -265,17 +265,17 @@ } @Override - public Buffer getHeader() { + public JBuffer getHeader() { return BufferUtil.newBuffer(headerSize); } @Override - public Buffer getBuffer() { + public JBuffer getBuffer() { return newBuffer(bufferSize); } @Override - public Buffer getBuffer(int size) { + public JBuffer getBuffer(int size) { return newBuffer(size); } }
diff -r 1accf965d51a -r 2b769da7f67d src/org/eclipse/jetty/server/handler/ContextHandler.java --- a/src/org/eclipse/jetty/server/handler/ContextHandler.java Mon Nov 07 22:51:09 2016 -0700 +++ b/src/org/eclipse/jetty/server/handler/ContextHandler.java Mon Nov 07 23:15:42 2016 -0700 @@ -61,7 +61,6 @@ import org.eclipse.jetty.http.HttpException; import org.eclipse.jetty.http.MimeTypes; -import org.eclipse.jetty.io.Buffer; import org.eclipse.jetty.server.AbstractHttpConnection; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.HandlerContainer;
diff -r 1accf965d51a -r 2b769da7f67d src/org/eclipse/jetty/server/nio/BlockingChannelConnector.java --- a/src/org/eclipse/jetty/server/nio/BlockingChannelConnector.java Mon Nov 07 22:51:09 2016 -0700 +++ b/src/org/eclipse/jetty/server/nio/BlockingChannelConnector.java Mon Nov 07 23:15:42 2016 -0700 @@ -30,7 +30,7 @@ import java.util.concurrent.RejectedExecutionException; import org.eclipse.jetty.http.HttpException; -import org.eclipse.jetty.io.Buffer; +import org.eclipse.jetty.io.JBuffer; import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.EofException; import org.eclipse.jetty.io.nio.ChannelEndPoint; @@ -171,21 +171,21 @@ } @Override - public int fill(Buffer buffer) throws IOException + public int fill(JBuffer buffer) throws IOException { _idleTimestamp = System.currentTimeMillis(); return super.fill(buffer); } @Override - public int flush(Buffer buffer) throws IOException + public int flush(JBuffer buffer) throws IOException { _idleTimestamp = System.currentTimeMillis(); return super.flush(buffer); } @Override - public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException + public int flush(JBuffer header, JBuffer buffer, JBuffer trailer) throws IOException { _idleTimestamp = System.currentTimeMillis(); return super.flush(header,buffer,trailer);
diff -r 1accf965d51a -r 2b769da7f67d src/org/eclipse/jetty/server/ssl/SslSelectChannelConnector.java --- a/src/org/eclipse/jetty/server/ssl/SslSelectChannelConnector.java Mon Nov 07 22:51:09 2016 -0700 +++ b/src/org/eclipse/jetty/server/ssl/SslSelectChannelConnector.java Mon Nov 07 23:15:42 2016 -0700 @@ -27,7 +27,7 @@ import javax.net.ssl.SSLSocket; import org.eclipse.jetty.io.AsyncEndPoint; -import org.eclipse.jetty.io.Buffer; +import org.eclipse.jetty.io.JBuffer; import org.eclipse.jetty.io.Buffers; import org.eclipse.jetty.io.BufferUtil; import org.eclipse.jetty.io.EndPoint; @@ -75,7 +75,7 @@ } @Override - protected Buffer newBuffer(int size) { + protected JBuffer newBuffer(int size) { return BufferUtil.newBuffer(size); }