Mercurial Hosting > luan
changeset 1047:1accf965d51a
remove other Buffer implementations
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 07 Nov 2016 22:51:09 -0700 |
parents | a8c92b0a08ed |
children | 2b769da7f67d |
files | src/org/eclipse/jetty/io/AbstractBuffer.java src/org/eclipse/jetty/io/ByteArrayBuffer.java src/org/eclipse/jetty/io/View.java src/org/eclipse/jetty/io/nio/DirectNIOBuffer.java src/org/eclipse/jetty/io/nio/IndirectNIOBuffer.java src/org/eclipse/jetty/server/Connector.java |
diffstat | 6 files changed, 0 insertions(+), 1218 deletions(-) [+] |
line wrap: on
line diff
diff -r a8c92b0a08ed -r 1accf965d51a src/org/eclipse/jetty/io/AbstractBuffer.java --- a/src/org/eclipse/jetty/io/AbstractBuffer.java Mon Nov 07 22:39:39 2016 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,473 +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; - -import org.eclipse.jetty.util.TypeUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * - * - */ -public abstract class AbstractBuffer implements Buffer -{ - private static final Logger LOG = LoggerFactory.getLogger(AbstractBuffer.class); - - private final static boolean __boundsChecking = Boolean.getBoolean("org.eclipse.jetty.io.AbstractBuffer.boundsChecking"); - - protected final static String __READONLY = "READONLY"; - - int _access; - - protected int _get; - protected int _put; - protected int _hash; - protected int _hashGet; - protected int _hashPut; - - /** - * Constructor for BufferView - * - * @param access 1==READONLY, 2==READWRITE - */ - protected AbstractBuffer(int access) - { - _access = access; - } - - public final byte[] asArray() - { - byte[] bytes = new byte[remaining()]; - byte[] array = array(); - if (array != null) - System.arraycopy(array, getIndex(), bytes, 0, bytes.length); - else - peek(getIndex(), bytes, 0, remaining()); - return bytes; - } - - public Buffer buffer() - { - return this; - } - - public void clear() - { - setGetIndex(0); - setPutIndex(0); - } - - public void compact() - { - if (isReadOnly()) throw new IllegalStateException(__READONLY); - int s = getIndex(); - if (s > 0) - { - byte array[] = array(); - int length = putIndex() - s; - if (length > 0) - { - if (array != null) - System.arraycopy(array(), s, array(), 0, length); - else - poke(0, peek(s, length)); - } - setGetIndex(getIndex() - s); - setPutIndex(putIndex() - s); - } - } - - @Override - public boolean equals(Object obj) - { - if (obj==this) - return true; - - // reject non buffers; - if (obj == null || !(obj instanceof Buffer)) return false; - Buffer b = (Buffer) obj; - - // reject different lengths - if (b.remaining() != remaining()) return false; - - // reject AbstractBuffer with different hash value - if (_hash != 0 && obj instanceof AbstractBuffer) - { - AbstractBuffer ab = (AbstractBuffer) obj; - if (ab._hash != 0 && _hash != ab._hash) return false; - } - - // Nothing for it but to do the hard grind. - int get=getIndex(); - int bi=b.putIndex(); - for (int i = putIndex(); i-->get;) - { - byte b1 = peek(i); - byte b2 = b.peek(--bi); - if (b1 != b2) return false; - } - return true; - } - - public byte get() - { - return peek(_get++); - } - - public int get(byte[] b, int offset, int length) - { - int gi = getIndex(); - int l=remaining(); - if (l==0) - return -1; - - if (length>l) - length=l; - - length = peek(gi, b, offset, length); - if (length>0) - setGetIndex(gi + length); - return length; - } - - public Buffer get(int length) - { - int gi = getIndex(); - Buffer view = peek(gi, length); - setGetIndex(gi + length); - return view; - } - - public final int getIndex() - { - return _get; - } - - public boolean hasRemaining() - { - return _put > _get; - } - - @Override - public int hashCode() - { - if (_hash == 0 || _hashGet!=_get || _hashPut!=_put) - { - int get=getIndex(); - byte[] array = array(); - if (array==null) - { - for (int i = putIndex(); i-- >get;) - { - byte b = peek(i); - if ('a' <= b && b <= 'z') - b = (byte) (b - 'a' + 'A'); - _hash = 31 * _hash + b; - } - } - else - { - for (int i = putIndex(); i-- >get;) - { - byte b = array[i]; - if ('a' <= b && b <= 'z') - b = (byte) (b - 'a' + 'A'); - _hash = 31 * _hash + b; - } - } - if (_hash == 0) - _hash = -1; - _hashGet=_get; - _hashPut=_put; - - } - return _hash; - } - - public boolean isReadOnly() - { - return _access <= READONLY; - } - - public int remaining() - { - return _put - _get; - } - - public byte peek() - { - return peek(_get); - } - - private Buffer peek(int index, int length) - { - Buffer view = duplicate(); - view.setPutIndex(index + length); - view.setGetIndex(index); - return view; - } - - @Override - public int poke(int index, Buffer src) - { - _hash=0; - - int length=src.remaining(); - if (index + length > capacity()) - { - length=capacity()-index; - /* - if (length<0) - throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity()); - */ - } - - byte[] src_array = src.array(); - byte[] dst_array = array(); - if (src_array != null && dst_array != null) - System.arraycopy(src_array, src.getIndex(), dst_array, index, length); - else if (src_array != null) - { - int s=src.getIndex(); - for (int i=0;i<length;i++) - poke(index++,src_array[s++]); - } - else if (dst_array != null) - { - int s=src.getIndex(); - for (int i=0;i<length;i++) - dst_array[index++]=src.peek(s++); - } - else - { - int s=src.getIndex(); - for (int i=0;i<length;i++) - poke(index++,src.peek(s++)); - } - - return length; - } - - - public int poke(int index, byte[] b, int offset, int length) - { - _hash=0; - if (index + length > capacity()) - { - length=capacity()-index; - /* if (length<0) - throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity()); - */ - } - - byte[] dst_array = array(); - if (dst_array != null) - System.arraycopy(b, offset, dst_array, index, length); - else - { - int s=offset; - for (int i=0;i<length;i++) - poke(index++,b[s++]); - } - return length; - } - - public int put(Buffer src) - { - int pi = putIndex(); - int l = poke(pi, src); - setPutIndex(pi + l); - return l; - } - - public void put(byte b) - { - int pi = putIndex(); - poke(pi, b); - setPutIndex(pi + 1); - } - - public int put(byte[] b, int offset, int length) - { - int pi = putIndex(); - int l = poke(pi, b, offset, length); - setPutIndex(pi + l); - return l; - } - - public int put(byte[] b) - { - int pi = putIndex(); - int l = poke(pi, b, 0, b.length); - setPutIndex(pi + l); - return l; - } - - public final int putIndex() - { - return _put; - } - - public final void rewind() - { - setGetIndex(0); - } - - public void setGetIndex(int getIndex) - { - _get = getIndex; - _hash=0; - } - - public void setPutIndex(int putIndex) - { - _put = putIndex; - _hash=0; - } - - public int skip(int n) - { - if (remaining() < n) n = remaining(); - setGetIndex(getIndex() + n); - return n; - } - - public Buffer slice() - { - return peek(getIndex(), remaining()); - } - - public final Buffer sliceFrom(int index) { - return peek(index, getIndex()-index-1); - } - - public int space() - { - return capacity() - _put; - } - - public String toDetailString() - { - StringBuilder buf = new StringBuilder(); - buf.append("["); - buf.append(super.hashCode()); - buf.append(","); - buf.append(this.buffer().hashCode()); - buf.append(",g="); - buf.append(getIndex()); - buf.append(",p="); - buf.append(putIndex()); - buf.append(",c="); - buf.append(capacity()); - buf.append("]={"); - int count = 0; - for (int i = getIndex(); i < putIndex(); i++) - { - byte b = peek(i); - TypeUtil.toHex(b,buf); - if (count++ == 50) - { - if (putIndex() - i > 20) - { - buf.append(" ... "); - i = putIndex() - 20; - } - } - } - buf.append('}'); - return buf.toString(); - } - - @Override - public String toString() - { - return toString("ISO-8859-1"); - } - - @Override - public final String toString(int index, int length) { - return peek(index,length).toString(); - } - - @Override - public final String toString(String charset) - { - try - { - byte[] bytes=array(); - if (bytes!=null) - return new String(bytes,getIndex(),remaining(),charset); - return new String(asArray(), 0, remaining(),charset); - - } - catch(Exception e) - { - LOG.warn("",e); - return new String(asArray(), 0, remaining()); - } - } - - /* ------------------------------------------------------------ */ - public String toDebugString() - { - return getClass()+"@"+super.hashCode(); - } - - /* ------------------------------------------------------------ */ - public int readFrom(InputStream in,int max) throws IOException - { - byte[] array = array(); - int s=space(); - if (s>max) - s=max; - - if (array!=null) - { - int l=in.read(array,_put,s); - if (l>0) - _put+=l; - return l; - } - else - { - byte[] buf=new byte[s>1024?1024:s]; - int total=0; - while (s>0) - { - int l=in.read(buf,0,buf.length); - if (l<0) - return total>0?total:-1; - int p=put(buf,0,l); - assert l==p; - s-=l; - } - return total; - } - } - - public final Buffer duplicate() { - return new View(this); - } -}
diff -r a8c92b0a08ed -r 1accf965d51a src/org/eclipse/jetty/io/ByteArrayBuffer.java --- a/src/org/eclipse/jetty/io/ByteArrayBuffer.java Mon Nov 07 22:39:39 2016 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,301 +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.io.UnsupportedEncodingException; - -import org.eclipse.jetty.util.StringUtil; - - -public class ByteArrayBuffer extends AbstractBuffer -{ - // Set a maximum size to a write for the writeTo method, to ensure that very large content is not - // written as a single write (which may fall foul to write timeouts if consumed slowly). - final static int MAX_WRITE=Integer.getInteger("org.eclipse.jetty.io.ByteArrayBuffer.MAX_WRITE",128*1024); - final protected byte[] _bytes; - - protected ByteArrayBuffer(int size, int access) - { - this(new byte[size],0,0,access); - } - - public ByteArrayBuffer(byte[] bytes) - { - this(bytes, 0, bytes.length, READWRITE); - } - - public ByteArrayBuffer(byte[] bytes, int index, int length) - { - this(bytes, index, length, READWRITE); - } - - public ByteArrayBuffer(byte[] bytes, int index, int length, int access) - { - super(access); - _bytes = bytes; - setPutIndex(index + length); - setGetIndex(index); - } - - public ByteArrayBuffer(int size) - { - this(new byte[size], 0, 0, READWRITE); - setPutIndex(0); - } - - public ByteArrayBuffer(String value) - { - super(READONLY); - _bytes = StringUtil.getBytes(value); - setGetIndex(0); - setPutIndex(_bytes.length); - } - - @Override - public final byte[] array() - { - return _bytes; - } - - @Override - public final int capacity() - { - return _bytes.length; - } - - @Override - public final void compact() - { - if (isReadOnly()) - throw new IllegalStateException(__READONLY); - int s = getIndex(); - if (s > 0) - { - int length = putIndex() - s; - if (length > 0) - { - System.arraycopy(_bytes, s,_bytes, 0, length); - } - setGetIndex(getIndex() - s); - setPutIndex(putIndex() - s); - } - } - - - @Override - public final boolean equals(Object obj) - { - if (obj==this) - return true; - - if (obj == null || !(obj instanceof Buffer)) - return false; - - - Buffer b = (Buffer) obj; - - // reject different lengths - if (b.remaining() != remaining()) - return false; - - // reject AbstractBuffer with different hash value - if (_hash != 0 && obj instanceof AbstractBuffer) - { - AbstractBuffer ab = (AbstractBuffer) obj; - if (ab._hash != 0 && _hash != ab._hash) - return false; - } - - // Nothing for it but to do the hard grind. - int get=getIndex(); - int bi=b.putIndex(); - for (int i = putIndex(); i-->get;) - { - byte b1 = _bytes[i]; - byte b2 = b.peek(--bi); - if (b1 != b2) return false; - } - return true; - } - - @Override - public final byte get() - { - return _bytes[_get++]; - } - - @Override - public final int hashCode() - { - if (_hash == 0 || _hashGet!=_get || _hashPut!=_put) - { - int get=getIndex(); - for (int i = putIndex(); i-- >get;) - { - byte b = _bytes[i]; - if ('a' <= b && b <= 'z') - b = (byte) (b - 'a' + 'A'); - _hash = 31 * _hash + b; - } - if (_hash == 0) - _hash = -1; - _hashGet=_get; - _hashPut=_put; - } - return _hash; - } - - - @Override - public final byte peek(int index) - { - return _bytes[index]; - } - - @Override - public final int peek(int index, byte[] b, int offset, int length) - { - int l = length; - if (index + l > capacity()) - { - l = capacity() - index; - if (l==0) - return -1; - } - - if (l < 0) - return -1; - - System.arraycopy(_bytes, index, b, offset, l); - return l; - } - - @Override - public final void poke(int index, byte b) - { - /* - if (isReadOnly()) - throw new IllegalStateException(__READONLY); - - if (index < 0) - throw new IllegalArgumentException("index<0: " + index + "<0"); - if (index > capacity()) - throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity()); - */ - _bytes[index] = b; - } - - @Override - public final int poke(int index, Buffer src) - { - _hash=0; - - /* - if (isReadOnly()) - throw new IllegalStateException(__READONLY); - if (index < 0) - throw new IllegalArgumentException("index<0: " + index + "<0"); - */ - - int length=src.remaining(); - if (index + length > capacity()) - { - length=capacity()-index; - /* - if (length<0) - throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity()); - */ - } - - byte[] src_array = src.array(); - if (src_array != null) - System.arraycopy(src_array, src.getIndex(), _bytes, index, length); - else - { - int s=src.getIndex(); - for (int i=0;i<length;i++) - _bytes[index++]=src.peek(s++); - } - - return length; - } - - - @Override - public final int poke(int index, byte[] b, int offset, int length) - { - _hash=0; - /* - if (isReadOnly()) - throw new IllegalStateException(__READONLY); - if (index < 0) - throw new IllegalArgumentException("index<0: " + index + "<0"); - */ - - if (index + length > capacity()) - { - length=capacity()-index; - /* if (length<0) - throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity()); - */ - } - - System.arraycopy(b, offset, _bytes, index, length); - - return length; - } - - @Override - public final int readFrom(InputStream in,int max) throws IOException - { - if (max<0||max>space()) - max=space(); - int p = putIndex(); - - int len=0, total=0, available=max; - while (total<max) - { - len=in.read(_bytes,p,available); - if (len<0) - break; - else if (len>0) - { - p += len; - total += len; - available -= len; - setPutIndex(p); - } - if (in.available()<=0) - break; - } - if (len<0 && total==0) - return -1; - return total; - } - - @Override - public final int space() - { - return _bytes.length - _put; - } - -}
diff -r a8c92b0a08ed -r 1accf965d51a src/org/eclipse/jetty/io/View.java --- a/src/org/eclipse/jetty/io/View.java Mon Nov 07 22:39:39 2016 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,128 +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; - -/** - * A View on another buffer. Allows operations that do not change the _content or - * indexes of the backing buffer. - * - * - * - */ -final class View extends AbstractBuffer -{ - private Buffer _buffer; - - View(Buffer buffer) - { - super( buffer.isReadOnly()?READONLY:READWRITE ); - _buffer = buffer.buffer(); - setGetIndex(0); - setPutIndex(buffer.putIndex()); - setGetIndex(buffer.getIndex()); - } - - - @Override - public byte[] array() - { - return _buffer.array(); - } - - @Override - public Buffer buffer() - { - return _buffer.buffer(); - } - - @Override - public int capacity() - { - return _buffer.capacity(); - } - - @Override - public void clear() - { - setGetIndex(0); - setPutIndex(_buffer.getIndex()); - setGetIndex(_buffer.getIndex()); - } - - @Override - public void compact() - { - // TODO - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) - { - return this==obj ||((obj instanceof Buffer)&& obj.equals(this)) || super.equals(obj); - } - - @Override - public boolean isReadOnly() - { - return _buffer.isReadOnly(); - } - - @Override - public byte peek(int index) - { - return _buffer.peek(index); - } - - @Override - public int peek(int index, byte[] b, int offset, int length) - { - return _buffer.peek(index,b,offset,length); - } - - @Override - public int poke(int index, Buffer src) - { - return _buffer.poke(index,src); - } - - @Override - public void poke(int index, byte b) - { - _buffer.poke(index,b); - } - - @Override - public int poke(int index, byte[] b, int offset, int length) - { - return _buffer.poke(index,b,offset,length); - } - - @Override - public String toString() - { - if (_buffer==null) - return "INVALID"; - return super.toString(); - } -}
diff -r a8c92b0a08ed -r 1accf965d51a src/org/eclipse/jetty/io/nio/DirectNIOBuffer.java --- a/src/org/eclipse/jetty/io/nio/DirectNIOBuffer.java Mon Nov 07 22:39:39 2016 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,263 +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.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.ByteBuffer; -import java.nio.channels.Channels; -import java.nio.channels.FileChannel; -import java.nio.channels.ReadableByteChannel; -import java.nio.channels.WritableByteChannel; - -import org.eclipse.jetty.io.AbstractBuffer; -import org.eclipse.jetty.io.Buffer; -import org.eclipse.jetty.util.IO; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -public final class DirectNIOBuffer extends AbstractBuffer implements NIOBuffer -{ - private static final Logger LOG = LoggerFactory.getLogger(DirectNIOBuffer.class); - - protected final ByteBuffer _buf; - private ReadableByteChannel _in; - private InputStream _inStream; - - public DirectNIOBuffer(int size) - { - super(READWRITE); - _buf = ByteBuffer.allocateDirect(size); - _buf.position(0); - _buf.limit(_buf.capacity()); - } - - - @Override - public boolean isDirect() - { - return true; - } - - @Override - public byte[] array() - { - return null; - } - - @Override - public int capacity() - { - return _buf.capacity(); - } - - @Override - public byte peek(int position) - { - return _buf.get(position); - } - - @Override - public int peek(int index, byte[] b, int offset, int length) - { - int l = length; - if (index+l > capacity()) - { - l=capacity()-index; - if (l==0) - return -1; - } - - if (l < 0) - return -1; - try - { - _buf.position(index); - _buf.get(b,offset,l); - } - finally - { - _buf.position(0); - } - - return l; - } - - @Override - public void poke(int index, byte b) - { - if (isReadOnly()) throw new IllegalStateException(__READONLY); - if (index < 0) throw new IllegalArgumentException("index<0: " + index + "<0"); - if (index > capacity()) - throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity()); - _buf.put(index,b); - } - - @Override - public int poke(int index, Buffer src) - { - if (isReadOnly()) throw new IllegalStateException(__READONLY); - - byte[] array=src.array(); - if (array!=null) - { - return poke(index,array,src.getIndex(),src.remaining()); - } - else - { - Buffer src_buf=src.buffer(); - if (src_buf instanceof DirectNIOBuffer) - { - ByteBuffer src_bytebuf = ((DirectNIOBuffer)src_buf)._buf; - if (src_bytebuf==_buf) - src_bytebuf=_buf.duplicate(); - try - { - _buf.position(index); - int space = _buf.remaining(); - - int length=src.remaining(); - if (length>space) - length=space; - - src_bytebuf.position(src.getIndex()); - src_bytebuf.limit(src.getIndex()+length); - - _buf.put(src_bytebuf); - return length; - } - finally - { - _buf.position(0); - src_bytebuf.limit(src_bytebuf.capacity()); - src_bytebuf.position(0); - } - } - else - return super.poke(index,src); - } - } - - @Override - public int poke(int index, byte[] b, int offset, int length) - { - if (isReadOnly()) throw new IllegalStateException(__READONLY); - - if (index < 0) throw new IllegalArgumentException("index<0: " + index + "<0"); - - if (index + length > capacity()) - { - length=capacity()-index; - if (length<0) - throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity()); - } - - try - { - _buf.position(index); - - int space=_buf.remaining(); - - if (length>space) - length=space; - if (length>0) - _buf.put(b,offset,length); - return length; - } - finally - { - _buf.position(0); - } - } - - @Override - public ByteBuffer getByteBuffer() - { - return _buf; - } - - @Override - public int readFrom(InputStream in, int max) throws IOException - { - if (_in==null || !_in.isOpen() || in!=_inStream) - { - _in = Channels.newChannel(in); - _inStream = in; - } - - if (max<0 || max>space()) - max=space(); - int p = putIndex(); - - try - { - int len=0, total=0, available=max; - int loop=0; - while (total<max) - { - _buf.position(p); - _buf.limit(p+available); - len = _in.read(_buf); - if (len<0) - { - _in = null; - _inStream = in; - break; - } - else if (len>0) - { - p += len; - total += len; - available -= len; - setPutIndex(p); - loop=0; - } - else if (loop++>1) - break; - if (in.available()<=0) - break; - } - if (len<0 && total==0) - return -1; - return total; - - } - catch(IOException e) - { - _in = null; - _inStream = in; - throw e; - } - finally - { - if (_in!=null && !_in.isOpen()) - { - _in = null; - _inStream = in; - } - _buf.position(0); - _buf.limit(_buf.capacity()); - } - } - -}
diff -r a8c92b0a08ed -r 1accf965d51a src/org/eclipse/jetty/io/nio/IndirectNIOBuffer.java --- a/src/org/eclipse/jetty/io/nio/IndirectNIOBuffer.java Mon Nov 07 22:39:39 2016 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +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.ByteArrayBuffer; - - -public final class IndirectNIOBuffer extends ByteArrayBuffer implements NIOBuffer -{ - private final ByteBuffer _buf; - - public IndirectNIOBuffer(int size) - { - super(size,READWRITE); - _buf = ByteBuffer.wrap(_bytes); - _buf.position(0); - _buf.limit(_buf.capacity()); - } - - @Override - public ByteBuffer getByteBuffer() - { - return _buf; - } - - @Override - public boolean isDirect() - { - return false; - } -}
diff -r a8c92b0a08ed -r 1accf965d51a src/org/eclipse/jetty/server/Connector.java --- a/src/org/eclipse/jetty/server/Connector.java Mon Nov 07 22:39:39 2016 -0700 +++ b/src/org/eclipse/jetty/server/Connector.java Mon Nov 07 22:51:09 2016 -0700 @@ -33,8 +33,6 @@ import org.eclipse.jetty.io.BufferUtil; import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.EofException; -import org.eclipse.jetty.io.nio.DirectNIOBuffer; -import org.eclipse.jetty.io.nio.IndirectNIOBuffer; import org.eclipse.jetty.util.component.AggregateLifeCycle; import org.eclipse.jetty.util.component.Dumpable; import org.slf4j.Logger; @@ -254,7 +252,6 @@ // my own buffers protected Buffer newBuffer(int size) { -// return new DirectNIOBuffer(size); return BufferUtil.newDirectBuffer(size); } @@ -269,7 +266,6 @@ @Override public Buffer getHeader() { -// return new IndirectNIOBuffer(headerSize); return BufferUtil.newBuffer(headerSize); }