jetty-9 jetty-io mostly working with all NIO buffers. Occassional failure in SSL stress test
This commit is contained in:
parent
91c526cc48
commit
c1bcec61d5
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>example-async-rest</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.eclipse.jetty.example-async-rest</groupId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>example-async-rest</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.eclipse.jetty.example-async-rest</groupId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>example-jetty-embedded</artifactId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty.aggregate</groupId>
|
||||
<artifactId>jetty-aggregate-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.eclipse.jetty.aggregate</groupId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty.aggregate</groupId>
|
||||
<artifactId>jetty-aggregate-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-all</artifactId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty.aggregate</groupId>
|
||||
<artifactId>jetty-aggregate-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.eclipse.jetty.aggregate</groupId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty.aggregate</groupId>
|
||||
<artifactId>jetty-aggregate-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-plus</artifactId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty.aggregate</groupId>
|
||||
<artifactId>jetty-aggregate-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty.aggregate</groupId>
|
||||
<artifactId>jetty-aggregate-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-servlet</artifactId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty.aggregate</groupId>
|
||||
<artifactId>jetty-aggregate-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-webapp</artifactId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty.aggregate</groupId>
|
||||
<artifactId>jetty-aggregate-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-websocket</artifactId>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<groupId>org.eclipse.jetty.aggregate</groupId>
|
||||
<artifactId>jetty-aggregate-project</artifactId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-ajp</artifactId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-annotations</artifactId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-continuation</artifactId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-deploy</artifactId>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>jetty-distribution</artifactId>
|
||||
<name>Jetty :: Distribution Assemblies</name>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-http-spi</artifactId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-http</artifactId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-io</artifactId>
|
||||
|
|
|
@ -1,705 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2004-2009 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 org.eclipse.jetty.util.TypeUtil;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractBuffer implements Buffer
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(AbstractBuffer.class);
|
||||
|
||||
private final static boolean __boundsChecking = Boolean.getBoolean("org.eclipse.jetty.io.AbstractBuffer.boundsChecking");
|
||||
|
||||
protected final static String
|
||||
__IMMUTABLE = "IMMUTABLE",
|
||||
__READONLY = "READONLY",
|
||||
__READWRITE = "READWRITE",
|
||||
__VOLATILE = "VOLATILE";
|
||||
|
||||
protected int _access;
|
||||
protected boolean _volatile;
|
||||
|
||||
protected int _get;
|
||||
protected int _put;
|
||||
protected int _hash;
|
||||
protected int _hashGet;
|
||||
protected int _hashPut;
|
||||
protected int _mark;
|
||||
protected String _string;
|
||||
protected View _view;
|
||||
|
||||
/**
|
||||
* Constructor for BufferView
|
||||
*
|
||||
* @param access 0==IMMUTABLE, 1==READONLY, 2==READWRITE
|
||||
*/
|
||||
public AbstractBuffer(int access, boolean isVolatile)
|
||||
{
|
||||
if (access == IMMUTABLE && isVolatile)
|
||||
throw new IllegalArgumentException("IMMUTABLE && VOLATILE");
|
||||
setMarkIndex(-1);
|
||||
_access = access;
|
||||
_volatile = isVolatile;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.io.Buffer#toArray()
|
||||
*/
|
||||
public byte[] asArray()
|
||||
{
|
||||
byte[] bytes = new byte[length()];
|
||||
byte[] array = array();
|
||||
if (array != null)
|
||||
System.arraycopy(array, getIndex(), bytes, 0, bytes.length);
|
||||
else
|
||||
peek(getIndex(), bytes, 0, length());
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public ByteArrayBuffer duplicate(int access)
|
||||
{
|
||||
Buffer b=this.buffer();
|
||||
if (this instanceof Buffer.CaseInsensitve || b instanceof Buffer.CaseInsensitve)
|
||||
return new ByteArrayBuffer.CaseInsensitive(asArray(), 0, length(),access);
|
||||
else
|
||||
return new ByteArrayBuffer(asArray(), 0, length(), access);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.io.Buffer#asNonVolatile()
|
||||
*/
|
||||
public Buffer asNonVolatileBuffer()
|
||||
{
|
||||
if (!isVolatile()) return this;
|
||||
return duplicate(_access);
|
||||
}
|
||||
|
||||
public Buffer asImmutableBuffer()
|
||||
{
|
||||
if (isImmutable()) return this;
|
||||
return duplicate(IMMUTABLE);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.util.Buffer#asReadOnlyBuffer()
|
||||
*/
|
||||
public Buffer asReadOnlyBuffer()
|
||||
{
|
||||
if (isReadOnly()) return this;
|
||||
return new View(this, markIndex(), getIndex(), putIndex(), READONLY);
|
||||
}
|
||||
|
||||
public Buffer asMutableBuffer()
|
||||
{
|
||||
if (!isImmutable()) return this;
|
||||
|
||||
Buffer b=this.buffer();
|
||||
if (b.isReadOnly())
|
||||
{
|
||||
return duplicate(READWRITE);
|
||||
}
|
||||
return new View(b, markIndex(), getIndex(), putIndex(), _access);
|
||||
}
|
||||
|
||||
public Buffer buffer()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
setMarkIndex(-1);
|
||||
setGetIndex(0);
|
||||
setPutIndex(0);
|
||||
}
|
||||
|
||||
public void compact()
|
||||
{
|
||||
if (isReadOnly()) throw new IllegalStateException(__READONLY);
|
||||
int s = markIndex() >= 0 ? markIndex() : 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));
|
||||
}
|
||||
if (markIndex() > 0) setMarkIndex(markIndex() - s);
|
||||
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;
|
||||
|
||||
if (this instanceof Buffer.CaseInsensitve || b instanceof Buffer.CaseInsensitve)
|
||||
return equalsIgnoreCase(b);
|
||||
|
||||
// reject different lengths
|
||||
if (b.length() != length()) 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 boolean equalsIgnoreCase(Buffer b)
|
||||
{
|
||||
if (b==this)
|
||||
return true;
|
||||
|
||||
// reject different lengths
|
||||
if (b.length() != length()) return false;
|
||||
|
||||
// reject AbstractBuffer with different hash value
|
||||
if (_hash != 0 && b instanceof AbstractBuffer)
|
||||
{
|
||||
AbstractBuffer ab = (AbstractBuffer) b;
|
||||
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();
|
||||
|
||||
byte[] array = array();
|
||||
byte[] barray= b.array();
|
||||
if (array!=null && barray!=null)
|
||||
{
|
||||
for (int i = putIndex(); i-->get;)
|
||||
{
|
||||
byte b1 = array[i];
|
||||
byte b2 = barray[--bi];
|
||||
if (b1 != b2)
|
||||
{
|
||||
if ('a' <= b1 && b1 <= 'z') b1 = (byte) (b1 - 'a' + 'A');
|
||||
if ('a' <= b2 && b2 <= 'z') b2 = (byte) (b2 - 'a' + 'A');
|
||||
if (b1 != b2) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = putIndex(); i-->get;)
|
||||
{
|
||||
byte b1 = peek(i);
|
||||
byte b2 = b.peek(--bi);
|
||||
if (b1 != b2)
|
||||
{
|
||||
if ('a' <= b1 && b1 <= 'z') b1 = (byte) (b1 - 'a' + 'A');
|
||||
if ('a' <= b2 && b2 <= 'z') b2 = (byte) (b2 - 'a' + 'A');
|
||||
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=length();
|
||||
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 hasContent()
|
||||
{
|
||||
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 isImmutable()
|
||||
{
|
||||
return _access <= IMMUTABLE;
|
||||
}
|
||||
|
||||
public boolean isReadOnly()
|
||||
{
|
||||
return _access <= READONLY;
|
||||
}
|
||||
|
||||
public boolean isVolatile()
|
||||
{
|
||||
return _volatile;
|
||||
}
|
||||
|
||||
public int length()
|
||||
{
|
||||
return _put - _get;
|
||||
}
|
||||
|
||||
public void mark()
|
||||
{
|
||||
setMarkIndex(_get - 1);
|
||||
}
|
||||
|
||||
public void mark(int offset)
|
||||
{
|
||||
setMarkIndex(_get + offset);
|
||||
}
|
||||
|
||||
public int markIndex()
|
||||
{
|
||||
return _mark;
|
||||
}
|
||||
|
||||
public byte peek()
|
||||
{
|
||||
return peek(_get);
|
||||
}
|
||||
|
||||
public Buffer peek(int index, int length)
|
||||
{
|
||||
if (_view == null)
|
||||
{
|
||||
_view = new View(this, -1, index, index + length, isReadOnly() ? READONLY : READWRITE);
|
||||
}
|
||||
else
|
||||
{
|
||||
_view.update(this.buffer());
|
||||
_view.setMarkIndex(-1);
|
||||
_view.setGetIndex(0);
|
||||
_view.setPutIndex(index + length);
|
||||
_view.setGetIndex(index);
|
||||
|
||||
}
|
||||
return _view;
|
||||
}
|
||||
|
||||
public 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.length();
|
||||
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 (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());
|
||||
*/
|
||||
}
|
||||
|
||||
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 void reset()
|
||||
{
|
||||
if (markIndex() >= 0) setGetIndex(markIndex());
|
||||
}
|
||||
|
||||
public void rewind()
|
||||
{
|
||||
setGetIndex(0);
|
||||
setMarkIndex(-1);
|
||||
}
|
||||
|
||||
public void setGetIndex(int getIndex)
|
||||
{
|
||||
/* bounds checking
|
||||
if (isImmutable())
|
||||
throw new IllegalStateException(__IMMUTABLE);
|
||||
if (getIndex < 0)
|
||||
throw new IllegalArgumentException("getIndex<0: " + getIndex + "<0");
|
||||
if (getIndex > putIndex())
|
||||
throw new IllegalArgumentException("getIndex>putIndex: " + getIndex + ">" + putIndex());
|
||||
*/
|
||||
_get = getIndex;
|
||||
_hash=0;
|
||||
}
|
||||
|
||||
public void setMarkIndex(int index)
|
||||
{
|
||||
/*
|
||||
if (index>=0 && isImmutable())
|
||||
throw new IllegalStateException(__IMMUTABLE);
|
||||
*/
|
||||
_mark = index;
|
||||
}
|
||||
|
||||
public void setPutIndex(int putIndex)
|
||||
{
|
||||
/* bounds checking
|
||||
if (isImmutable())
|
||||
throw new IllegalStateException(__IMMUTABLE);
|
||||
if (putIndex > capacity())
|
||||
throw new IllegalArgumentException("putIndex>capacity: " + putIndex + ">" + capacity());
|
||||
if (getIndex() > putIndex)
|
||||
throw new IllegalArgumentException("getIndex>putIndex: " + getIndex() + ">" + putIndex);
|
||||
*/
|
||||
_put = putIndex;
|
||||
_hash=0;
|
||||
}
|
||||
|
||||
public int skip(int n)
|
||||
{
|
||||
if (length() < n) n = length();
|
||||
setGetIndex(getIndex() + n);
|
||||
return n;
|
||||
}
|
||||
|
||||
public Buffer slice()
|
||||
{
|
||||
return peek(getIndex(), length());
|
||||
}
|
||||
|
||||
public Buffer sliceFromMark()
|
||||
{
|
||||
return sliceFromMark(getIndex() - markIndex() - 1);
|
||||
}
|
||||
|
||||
public Buffer sliceFromMark(int length)
|
||||
{
|
||||
if (markIndex() < 0) return null;
|
||||
Buffer view = peek(markIndex(), length);
|
||||
setMarkIndex(-1);
|
||||
return view;
|
||||
}
|
||||
|
||||
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(",m=");
|
||||
buf.append(markIndex());
|
||||
buf.append(",g=");
|
||||
buf.append(getIndex());
|
||||
buf.append(",p=");
|
||||
buf.append(putIndex());
|
||||
buf.append(",c=");
|
||||
buf.append(capacity());
|
||||
buf.append("]={");
|
||||
if (markIndex() >= 0)
|
||||
{
|
||||
for (int i = markIndex(); i < getIndex(); i++)
|
||||
{
|
||||
byte b = peek(i);
|
||||
TypeUtil.toHex(b,buf);
|
||||
}
|
||||
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()
|
||||
{
|
||||
if (isImmutable())
|
||||
{
|
||||
if (_string == null)
|
||||
_string = new String(asArray(), 0, length());
|
||||
return _string;
|
||||
}
|
||||
return new String(asArray(), 0, length());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public String toString(String charset)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] bytes=array();
|
||||
if (bytes!=null)
|
||||
return new String(bytes,getIndex(),length(),charset);
|
||||
return new String(asArray(), 0, length(),charset);
|
||||
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
LOG.warn(e);
|
||||
return new String(asArray(), 0, length());
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public String toDebugString()
|
||||
{
|
||||
return getClass()+"@"+super.hashCode();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void writeTo(OutputStream out)
|
||||
throws IOException
|
||||
{
|
||||
byte[] array = array();
|
||||
|
||||
if (array!=null)
|
||||
{
|
||||
out.write(array,getIndex(),length());
|
||||
}
|
||||
else
|
||||
{
|
||||
int len = this.length();
|
||||
byte[] buf=new byte[len>1024?1024:len];
|
||||
int offset=_get;
|
||||
while (len>0)
|
||||
{
|
||||
int l=peek(offset,buf,0,len>buf.length?buf.length:len);
|
||||
out.write(buf,0,l);
|
||||
offset+=l;
|
||||
len-=l;
|
||||
}
|
||||
}
|
||||
clear();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package org.eclipse.jetty.io;
|
||||
|
||||
import org.eclipse.jetty.io.nio.DirectNIOBuffer;
|
||||
import org.eclipse.jetty.io.nio.IndirectNIOBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
|
||||
public abstract class AbstractBuffers implements Buffers
|
||||
{
|
||||
|
@ -45,16 +45,14 @@ public abstract class AbstractBuffers implements Buffers
|
|||
* Create a new header Buffer
|
||||
* @return new Buffer
|
||||
*/
|
||||
final protected Buffer newHeader()
|
||||
final protected ByteBuffer newHeader()
|
||||
{
|
||||
switch(_headerType)
|
||||
{
|
||||
case BYTE_ARRAY:
|
||||
return new ByteArrayBuffer(_headerSize);
|
||||
case DIRECT:
|
||||
return new DirectNIOBuffer(_headerSize);
|
||||
return BufferUtil.allocateDirect(_headerSize);
|
||||
case INDIRECT:
|
||||
return new IndirectNIOBuffer(_headerSize);
|
||||
return BufferUtil.allocate(_headerSize);
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
@ -64,16 +62,14 @@ public abstract class AbstractBuffers implements Buffers
|
|||
* Create a new content Buffer
|
||||
* @return new Buffer
|
||||
*/
|
||||
final protected Buffer newBuffer()
|
||||
final protected ByteBuffer newBuffer()
|
||||
{
|
||||
switch(_bufferType)
|
||||
{
|
||||
case BYTE_ARRAY:
|
||||
return new ByteArrayBuffer(_bufferSize);
|
||||
case DIRECT:
|
||||
return new DirectNIOBuffer(_bufferSize);
|
||||
return BufferUtil.allocateDirect(_bufferSize);
|
||||
case INDIRECT:
|
||||
return new IndirectNIOBuffer(_bufferSize);
|
||||
return BufferUtil.allocate(_bufferSize);
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
@ -84,16 +80,14 @@ public abstract class AbstractBuffers implements Buffers
|
|||
* @param size
|
||||
* @return new Buffer
|
||||
*/
|
||||
final protected Buffer newBuffer(int size)
|
||||
final protected ByteBuffer newBuffer(int size)
|
||||
{
|
||||
switch(_otherType)
|
||||
{
|
||||
case BYTE_ARRAY:
|
||||
return new ByteArrayBuffer(size);
|
||||
case DIRECT:
|
||||
return new DirectNIOBuffer(size);
|
||||
return BufferUtil.allocateDirect(size);
|
||||
case INDIRECT:
|
||||
return new IndirectNIOBuffer(size);
|
||||
return BufferUtil.allocate(size);
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
@ -103,18 +97,17 @@ public abstract class AbstractBuffers implements Buffers
|
|||
* @param buffer
|
||||
* @return True if the buffer is the correct type to be a Header buffer
|
||||
*/
|
||||
public final boolean isHeader(Buffer buffer)
|
||||
public final boolean isHeader(ByteBuffer buffer)
|
||||
{
|
||||
if (buffer.capacity()==_headerSize)
|
||||
{
|
||||
switch(_headerType)
|
||||
{
|
||||
case BYTE_ARRAY:
|
||||
return buffer instanceof ByteArrayBuffer && !(buffer instanceof IndirectNIOBuffer);
|
||||
case DIRECT:
|
||||
return buffer instanceof DirectNIOBuffer;
|
||||
return buffer.isDirect();
|
||||
|
||||
case INDIRECT:
|
||||
return buffer instanceof IndirectNIOBuffer;
|
||||
return !buffer.isDirect();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -125,18 +118,17 @@ public abstract class AbstractBuffers implements Buffers
|
|||
* @param buffer
|
||||
* @return True if the buffer is the correct type to be a Header buffer
|
||||
*/
|
||||
public final boolean isBuffer(Buffer buffer)
|
||||
public final boolean isBuffer(ByteBuffer buffer)
|
||||
{
|
||||
if (buffer.capacity()==_bufferSize)
|
||||
{
|
||||
switch(_bufferType)
|
||||
{
|
||||
case BYTE_ARRAY:
|
||||
return buffer instanceof ByteArrayBuffer && !(buffer instanceof IndirectNIOBuffer);
|
||||
case DIRECT:
|
||||
return buffer instanceof DirectNIOBuffer;
|
||||
return buffer.isDirect();
|
||||
|
||||
case INDIRECT:
|
||||
return buffer instanceof IndirectNIOBuffer;
|
||||
return !buffer.isDirect();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -1,371 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2004-2009 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;
|
||||
|
||||
|
||||
/**
|
||||
* 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 dependant 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 extends Cloneable
|
||||
{
|
||||
public final static int
|
||||
IMMUTABLE=0, // neither indexes or contexts can be changed
|
||||
READONLY=1, // indexes may be changed, but not content
|
||||
READWRITE=2; // anything can be changed
|
||||
public final boolean VOLATILE=true; // The buffer may change outside of current scope.
|
||||
public final boolean NON_VOLATILE=false;
|
||||
|
||||
/**
|
||||
* Get the underlying array, if one exists.
|
||||
* @return a <code>byte[]</code> backing this buffer or null if none exists.
|
||||
*/
|
||||
byte[] array();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return a <code>byte[]</code> value of the bytes from the getIndex to the putIndex.
|
||||
*/
|
||||
byte[] asArray();
|
||||
|
||||
/**
|
||||
* Get the unerlying buffer. If this buffer wraps a backing buffer.
|
||||
* @return The root backing buffer or this if there is no backing buffer;
|
||||
*/
|
||||
Buffer buffer();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return a non volitile version of this <code>Buffer</code> value
|
||||
*/
|
||||
Buffer asNonVolatileBuffer();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return a readonly version of this <code>Buffer</code>.
|
||||
*/
|
||||
Buffer asReadOnlyBuffer();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return an immutable version of this <code>Buffer</code>.
|
||||
*/
|
||||
Buffer asImmutableBuffer();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return an immutable version of this <code>Buffer</code>.
|
||||
*/
|
||||
Buffer asMutableBuffer();
|
||||
|
||||
/**
|
||||
*
|
||||
* 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 hasContent();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return a <code>boolean</code> value true if case sensitive comparison on this buffer
|
||||
*/
|
||||
boolean equalsIgnoreCase(Buffer buffer);
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return a <code>boolean</code> value true if the buffer is immutable and that neither
|
||||
* the buffer contents nor the indexes may be changed.
|
||||
*/
|
||||
boolean isImmutable();
|
||||
|
||||
/**
|
||||
*
|
||||
* @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();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return a <code>boolean</code> value true if the buffer contents may change
|
||||
* via alternate paths than this buffer. If the contents of this buffer are to be used outside of the
|
||||
* current context, then a copy must be made.
|
||||
*/
|
||||
boolean isVolatile();
|
||||
|
||||
/**
|
||||
* The number of bytes from the getIndex to the putIndex
|
||||
* @return an <code>int</code> == putIndex()-getIndex()
|
||||
*/
|
||||
int length();
|
||||
|
||||
/**
|
||||
* Set the mark to the current getIndex.
|
||||
*/
|
||||
void mark();
|
||||
|
||||
/**
|
||||
* Set the mark relative to the current getIndex
|
||||
* @param offset an <code>int</code> value to add to the current getIndex to obtain the mark value.
|
||||
*/
|
||||
void mark(int offset);
|
||||
|
||||
/**
|
||||
* The current index of the mark.
|
||||
* @return an <code>int</code> index in the buffer or -1 if the mark is not set.
|
||||
*/
|
||||
int markIndex();
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param index an <code>int</code> value
|
||||
* @param length an <code>int</code> value
|
||||
* @return The <code>Buffer</code> value from the requested getIndex.
|
||||
*/
|
||||
Buffer peek(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();
|
||||
|
||||
/**
|
||||
* Reset the current getIndex to the mark
|
||||
*/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* Set the buffers start getIndex.
|
||||
* @param newStart an <code>int</code> value
|
||||
*/
|
||||
void setGetIndex(int newStart);
|
||||
|
||||
/**
|
||||
* Set a specific value for the mark.
|
||||
* @param newMark an <code>int</code> value
|
||||
*/
|
||||
void setMarkIndex(int newMark);
|
||||
|
||||
/**
|
||||
*
|
||||
* @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();
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return a volitile <code>Buffer</code> value from the mark to the putIndex
|
||||
*/
|
||||
Buffer sliceFromMark();
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param length an <code>int</code> value
|
||||
* @return a valitile <code>Buffer</code> value from the mark of the length requested.
|
||||
*/
|
||||
Buffer sliceFromMark(int length);
|
||||
|
||||
/**
|
||||
*
|
||||
* @return a <code>String</code> value describing the state and contents of the buffer.
|
||||
*/
|
||||
String toDetailString();
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Write the buffer's contents to the output stream
|
||||
* @param out
|
||||
*/
|
||||
void writeTo(OutputStream out) throws IOException;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** 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);
|
||||
|
||||
/*
|
||||
* Buffers implementing this interface should be compared with case insensitive equals
|
||||
*
|
||||
*/
|
||||
public interface CaseInsensitve
|
||||
{}
|
||||
|
||||
|
||||
}
|
|
@ -13,23 +13,26 @@
|
|||
|
||||
package org.eclipse.jetty.io;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.eclipse.jetty.util.StringMap;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
|
||||
/* ------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Stores a collection of {@link Buffer} objects.
|
||||
* Stores a collection of {@link ByteBuffer} objects.
|
||||
* Buffers are stored in an ordered collection and can retreived by index or value
|
||||
*
|
||||
*/
|
||||
public class BufferCache
|
||||
{
|
||||
private final HashMap _bufferMap=new HashMap();
|
||||
private final StringMap _stringMap=new StringMap(StringMap.CASE_INSENSTIVE);
|
||||
private final ArrayList _index= new ArrayList();
|
||||
private final ArrayList<CachedBuffer> _index= new ArrayList<CachedBuffer>();
|
||||
|
||||
/* ------------------------------------------------------------------------------- */
|
||||
/** Add a buffer to the cache at the specified index.
|
||||
|
@ -38,12 +41,13 @@ public class BufferCache
|
|||
public CachedBuffer add(String value, int ordinal)
|
||||
{
|
||||
CachedBuffer buffer= new CachedBuffer(value, ordinal);
|
||||
_bufferMap.put(buffer, buffer);
|
||||
_stringMap.put(value, buffer);
|
||||
while ((ordinal - _index.size()) >= 0)
|
||||
_index.add(null);
|
||||
if (_index.get(ordinal)==null)
|
||||
_index.add(ordinal, buffer);
|
||||
if (ordinal>=0)
|
||||
{
|
||||
while ((ordinal - _index.size()) >= 0)
|
||||
_index.add(null);
|
||||
_index.set(ordinal,buffer);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
@ -54,9 +58,29 @@ public class BufferCache
|
|||
return (CachedBuffer)_index.get(ordinal);
|
||||
}
|
||||
|
||||
public CachedBuffer get(Buffer buffer)
|
||||
public ByteBuffer getBuffer(ByteBuffer buffer)
|
||||
{
|
||||
return (CachedBuffer)_bufferMap.get(buffer);
|
||||
CachedBuffer cached=get(buffer);
|
||||
if (cached!=null)
|
||||
return cached.getBuffer();
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public String getString(ByteBuffer buffer)
|
||||
{
|
||||
CachedBuffer cached=get(buffer);
|
||||
if (cached!=null)
|
||||
return cached.toString();
|
||||
return BufferUtil.toString(buffer);
|
||||
}
|
||||
|
||||
public CachedBuffer get(ByteBuffer buffer)
|
||||
{
|
||||
byte[] array=buffer.isReadOnly()?null:buffer.array();
|
||||
Map.Entry<String,Object> entry=_stringMap.getBestEntry(buffer);
|
||||
if (entry!=null)
|
||||
return (CachedBuffer)entry.getValue();
|
||||
return null;
|
||||
}
|
||||
|
||||
public CachedBuffer get(String value)
|
||||
|
@ -64,20 +88,14 @@ public class BufferCache
|
|||
return (CachedBuffer)_stringMap.get(value);
|
||||
}
|
||||
|
||||
public Buffer lookup(Buffer buffer)
|
||||
@Deprecated
|
||||
public ByteBuffer lookup(ByteBuffer buffer)
|
||||
{
|
||||
if (buffer instanceof CachedBuffer)
|
||||
return buffer;
|
||||
CachedBuffer cached=get(buffer);
|
||||
if (cached!=null)
|
||||
return cached.getBuffer();
|
||||
|
||||
Buffer b= get(buffer);
|
||||
if (b == null)
|
||||
{
|
||||
if (buffer instanceof Buffer.CaseInsensitve)
|
||||
return buffer;
|
||||
return new ByteArrayBuffer.CaseInsensitive(buffer.asArray(),0,buffer.length(),Buffer.IMMUTABLE);
|
||||
}
|
||||
|
||||
return b;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public CachedBuffer getBest(byte[] value, int offset, int maxLength)
|
||||
|
@ -88,19 +106,28 @@ public class BufferCache
|
|||
return null;
|
||||
}
|
||||
|
||||
public Buffer lookup(String value)
|
||||
public ByteBuffer lookup(String value)
|
||||
{
|
||||
Buffer b= get(value);
|
||||
CachedBuffer b= get(value);
|
||||
if (b == null)
|
||||
{
|
||||
return new CachedBuffer(value,-1);
|
||||
}
|
||||
return b;
|
||||
return ByteBuffer.wrap(value.getBytes(StringUtil.__ISO_8859_1_CHARSET));
|
||||
return b.getBuffer();
|
||||
}
|
||||
|
||||
public String toString(Buffer buffer)
|
||||
public String toString(ByteBuffer buffer)
|
||||
{
|
||||
return lookup(buffer).toString();
|
||||
CachedBuffer cached = get(buffer);
|
||||
if (cached!=null)
|
||||
return cached.toString();
|
||||
|
||||
|
||||
byte[] array=buffer.array();
|
||||
if (array!=null)
|
||||
return new String(array,buffer.position(),buffer.remaining(),StringUtil.__ISO_8859_1_CHARSET);
|
||||
|
||||
array=new byte[buffer.remaining()];
|
||||
buffer.asReadOnlyBuffer().get(array);
|
||||
return new String(array,0,buffer.remaining(),StringUtil.__ISO_8859_1_CHARSET);
|
||||
}
|
||||
|
||||
public int getOrdinal(String value)
|
||||
|
@ -109,24 +136,25 @@ public class BufferCache
|
|||
return buffer==null?-1:buffer.getOrdinal();
|
||||
}
|
||||
|
||||
public int getOrdinal(Buffer buffer)
|
||||
public int getOrdinal(ByteBuffer buffer)
|
||||
{
|
||||
if (buffer instanceof CachedBuffer)
|
||||
return ((CachedBuffer)buffer).getOrdinal();
|
||||
buffer=lookup(buffer);
|
||||
if (buffer!=null && buffer instanceof CachedBuffer)
|
||||
return ((CachedBuffer)buffer).getOrdinal();
|
||||
CachedBuffer cached = get(buffer);
|
||||
if (cached!=null)
|
||||
return cached.getOrdinal();
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static class CachedBuffer extends ByteArrayBuffer.CaseInsensitive
|
||||
public static class CachedBuffer
|
||||
{
|
||||
private final int _ordinal;
|
||||
private final String _string;
|
||||
private final ByteBuffer _buffer;
|
||||
private HashMap _associateMap=null;
|
||||
|
||||
public CachedBuffer(String value, int ordinal)
|
||||
{
|
||||
super(value);
|
||||
_string=value;
|
||||
_buffer=ByteBuffer.wrap(value.getBytes(StringUtil.__ISO_8859_1_CHARSET)).asReadOnlyBuffer();
|
||||
_ordinal= ordinal;
|
||||
}
|
||||
|
||||
|
@ -135,6 +163,16 @@ public class BufferCache
|
|||
return _ordinal;
|
||||
}
|
||||
|
||||
public ByteBuffer getBuffer()
|
||||
{
|
||||
return _buffer;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return _string;
|
||||
}
|
||||
|
||||
public CachedBuffer getAssociate(Object key)
|
||||
{
|
||||
if (_associateMap==null)
|
||||
|
@ -156,7 +194,6 @@ public class BufferCache
|
|||
public String toString()
|
||||
{
|
||||
return "CACHE["+
|
||||
"bufferMap="+_bufferMap+
|
||||
",stringMap="+_stringMap+
|
||||
",index="+_index+
|
||||
"]";
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
package org.eclipse.jetty.io;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.text.DateFormatSymbols;
|
||||
import java.util.Locale;
|
||||
|
||||
|
@ -20,7 +21,7 @@ import org.eclipse.jetty.util.DateCache;
|
|||
|
||||
public class BufferDateCache extends DateCache
|
||||
{
|
||||
Buffer _buffer;
|
||||
ByteBuffer _buffer;
|
||||
String _last;
|
||||
|
||||
public BufferDateCache()
|
||||
|
@ -43,13 +44,13 @@ public class BufferDateCache extends DateCache
|
|||
super(format);
|
||||
}
|
||||
|
||||
public synchronized Buffer formatBuffer(long date)
|
||||
public synchronized ByteBuffer formatBuffer(long date)
|
||||
{
|
||||
String d = super.format(date);
|
||||
if (d==_last)
|
||||
return _buffer;
|
||||
_last=d;
|
||||
_buffer=new ByteArrayBuffer(d);
|
||||
_buffer=BufferUtil.toBuffer(d);
|
||||
|
||||
return _buffer;
|
||||
}
|
||||
|
|
|
@ -13,36 +13,181 @@
|
|||
|
||||
package org.eclipse.jetty.io;
|
||||
|
||||
import org.eclipse.jetty.io.BufferCache.CachedBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
|
||||
/* ------------------------------------------------------------------------------- */
|
||||
/** Buffer utility methods.
|
||||
/**
|
||||
* Buffer utility methods.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class BufferUtil
|
||||
{
|
||||
static final byte SPACE= 0x20;
|
||||
static final byte MINUS= '-';
|
||||
static final byte[] DIGIT=
|
||||
{(byte)'0',(byte)'1',(byte)'2',(byte)'3',(byte)'4',(byte)'5',(byte)'6',(byte)'7',(byte)'8',(byte)'9',(byte)'A',(byte)'B',(byte)'C',(byte)'D',(byte)'E',(byte)'F'};
|
||||
static final byte SPACE = 0x20;
|
||||
static final byte MINUS = '-';
|
||||
static final byte[] DIGIT =
|
||||
{ (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6', (byte)'7', (byte)'8', (byte)'9', (byte)'A', (byte)'B', (byte)'C', (byte)'D',
|
||||
(byte)'E', (byte)'F' };
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public static void clear(ByteBuffer buffer)
|
||||
{
|
||||
buffer.position(0);
|
||||
buffer.limit(0);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Allocate ByteBuffer in output mode.
|
||||
* The position and limit will both be zero, indicating that the buffer is
|
||||
* empty and must be flipped before any data is put to it.
|
||||
* @param capacity
|
||||
* @return Buffer
|
||||
*/
|
||||
public static ByteBuffer allocate(int capacity)
|
||||
{
|
||||
ByteBuffer buf = ByteBuffer.allocate(capacity);
|
||||
buf.limit(0);
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Allocate ByteBuffer in output mode.
|
||||
* The position and limit will both be zero, indicating that the buffer is
|
||||
* empty and must be flipped before any data is put to it.
|
||||
* @param capacity
|
||||
* @return Buffer
|
||||
*/
|
||||
public static ByteBuffer allocateDirect(int capacity)
|
||||
{
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(capacity);
|
||||
buf.limit(0);
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public static byte[] toArray(ByteBuffer buffer)
|
||||
{
|
||||
byte[] to = new byte[buffer.remaining()];
|
||||
if (buffer.isDirect())
|
||||
buffer.slice().get(to);
|
||||
else
|
||||
{
|
||||
byte[] array = buffer.array();
|
||||
System.arraycopy(array,buffer.position(),to,0,to.length);
|
||||
}
|
||||
return to;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public static boolean isEmpty(ByteBuffer buf)
|
||||
{
|
||||
return buf==null || buf.remaining()==0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public static boolean isAtCapacity(ByteBuffer buf)
|
||||
{
|
||||
return buf!=null && buf.limit()==buf.capacity();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Put data from one buffer into another, avoiding over/under flows
|
||||
* @param from
|
||||
* @param to
|
||||
*/
|
||||
public static int put(ByteBuffer from, ByteBuffer to)
|
||||
{
|
||||
int put;
|
||||
int pos=to.position();
|
||||
try
|
||||
{
|
||||
to.position(to.limit());
|
||||
to.limit(to.capacity());
|
||||
|
||||
int remaining=from.remaining();
|
||||
if (remaining>0)
|
||||
{
|
||||
if (remaining<=to.remaining())
|
||||
{
|
||||
to.put(from);
|
||||
put=remaining;
|
||||
}
|
||||
else if (to.isDirect())
|
||||
{
|
||||
put=to.remaining();
|
||||
ByteBuffer slice=from.slice();
|
||||
slice.limit(put);
|
||||
to.put(slice);
|
||||
from.position(from.position()+put);
|
||||
}
|
||||
else
|
||||
{
|
||||
put=to.remaining();
|
||||
to.put(from.array(),from.arrayOffset()+from.position(),put);
|
||||
from.position(from.position()+put);
|
||||
}
|
||||
}
|
||||
else
|
||||
put=0;
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
to.limit(to.position());
|
||||
to.position(pos);
|
||||
}
|
||||
return put;
|
||||
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public static String toString(ByteBuffer buffer)
|
||||
{
|
||||
return toString(buffer,StringUtil.__ISO_8859_1_CHARSET);
|
||||
}
|
||||
|
||||
public static String toUTF8String(ByteBuffer buffer)
|
||||
{
|
||||
return toString(buffer,StringUtil.__UTF8_CHARSET);
|
||||
}
|
||||
|
||||
public static String toString(ByteBuffer buffer, Charset charset)
|
||||
{
|
||||
if (buffer == null)
|
||||
return null;
|
||||
byte[] array = buffer.isReadOnly()?null:buffer.array();
|
||||
if (array == null)
|
||||
{
|
||||
byte[] to = new byte[buffer.remaining()];
|
||||
buffer.slice().get(to);
|
||||
return new String(to,0,to.length,charset);
|
||||
}
|
||||
return new String(array,buffer.position(),buffer.remaining(),charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert buffer to an integer.
|
||||
* Parses up to the first non-numeric character. If no number is found an
|
||||
* IllegalArgumentException is thrown
|
||||
* @param buffer A buffer containing an integer. The position is not changed.
|
||||
* Convert buffer to an integer. Parses up to the first non-numeric character. If no number is found an IllegalArgumentException is thrown
|
||||
*
|
||||
* @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(ByteBuffer buffer)
|
||||
{
|
||||
int val= 0;
|
||||
boolean started= false;
|
||||
boolean minus= false;
|
||||
for (int i= buffer.getIndex(); i < buffer.putIndex(); i++)
|
||||
int val = 0;
|
||||
boolean started = false;
|
||||
boolean minus = false;
|
||||
|
||||
// TODO add version that operates on array
|
||||
|
||||
for (int i = buffer.position(); i < buffer.limit(); i++)
|
||||
{
|
||||
byte b= buffer.peek(i);
|
||||
byte b = buffer.get(i);
|
||||
if (b <= SPACE)
|
||||
{
|
||||
if (started)
|
||||
|
@ -50,37 +195,39 @@ public class BufferUtil
|
|||
}
|
||||
else if (b >= '0' && b <= '9')
|
||||
{
|
||||
val= val * 10 + (b - '0');
|
||||
started= true;
|
||||
val = val * 10 + (b - '0');
|
||||
started = true;
|
||||
}
|
||||
else if (b == MINUS && !started)
|
||||
{
|
||||
minus= true;
|
||||
minus = true;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (started)
|
||||
return minus ? (-val) : val;
|
||||
throw new NumberFormatException(buffer.toString());
|
||||
return minus?(-val):val;
|
||||
throw new NumberFormatException(toString(buffer));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert buffer to an long.
|
||||
* Parses up to the first non-numeric character. If no number is found an
|
||||
* IllegalArgumentException is thrown
|
||||
* @param buffer A buffer containing an integer. The position is not changed.
|
||||
* Convert buffer to an long. Parses up to the first non-numeric character. If no number is found an IllegalArgumentException is thrown
|
||||
*
|
||||
* @param buffer
|
||||
* A buffer containing an integer. The position is not changed.
|
||||
* @return an int
|
||||
*/
|
||||
public static long toLong(Buffer buffer)
|
||||
public static long toLong(ByteBuffer buffer)
|
||||
{
|
||||
long val= 0;
|
||||
boolean started= false;
|
||||
boolean minus= false;
|
||||
for (int i= buffer.getIndex(); i < buffer.putIndex(); i++)
|
||||
long val = 0;
|
||||
boolean started = false;
|
||||
boolean minus = false;
|
||||
// TODO add version that operates on array
|
||||
|
||||
for (int i = buffer.position(); i < buffer.limit(); i++)
|
||||
{
|
||||
byte b= buffer.peek(i);
|
||||
byte b = buffer.get(i);
|
||||
if (b <= SPACE)
|
||||
{
|
||||
if (started)
|
||||
|
@ -88,43 +235,42 @@ public class BufferUtil
|
|||
}
|
||||
else if (b >= '0' && b <= '9')
|
||||
{
|
||||
val= val * 10L + (b - '0');
|
||||
started= true;
|
||||
val = val * 10L + (b - '0');
|
||||
started = true;
|
||||
}
|
||||
else if (b == MINUS && !started)
|
||||
{
|
||||
minus= true;
|
||||
minus = true;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (started)
|
||||
return minus ? (-val) : val;
|
||||
throw new NumberFormatException(buffer.toString());
|
||||
return minus?(-val):val;
|
||||
throw new NumberFormatException(toString(buffer));
|
||||
}
|
||||
|
||||
public static void putHexInt(Buffer buffer, int n)
|
||||
public static void putHexInt(ByteBuffer buffer, int n)
|
||||
{
|
||||
|
||||
if (n < 0)
|
||||
{
|
||||
buffer.put((byte)'-');
|
||||
|
||||
if (n == Integer.MIN_VALUE)
|
||||
{
|
||||
buffer.put((byte)(0x7f&'8'));
|
||||
buffer.put((byte)(0x7f&'0'));
|
||||
buffer.put((byte)(0x7f&'0'));
|
||||
buffer.put((byte)(0x7f&'0'));
|
||||
buffer.put((byte)(0x7f&'0'));
|
||||
buffer.put((byte)(0x7f&'0'));
|
||||
buffer.put((byte)(0x7f&'0'));
|
||||
buffer.put((byte)(0x7f&'0'));
|
||||
buffer.put((byte)(0x7f & '8'));
|
||||
buffer.put((byte)(0x7f & '0'));
|
||||
buffer.put((byte)(0x7f & '0'));
|
||||
buffer.put((byte)(0x7f & '0'));
|
||||
buffer.put((byte)(0x7f & '0'));
|
||||
buffer.put((byte)(0x7f & '0'));
|
||||
buffer.put((byte)(0x7f & '0'));
|
||||
buffer.put((byte)(0x7f & '0'));
|
||||
|
||||
return;
|
||||
}
|
||||
n= -n;
|
||||
n = -n;
|
||||
}
|
||||
|
||||
if (n < 0x10)
|
||||
|
@ -133,9 +279,9 @@ public class BufferUtil
|
|||
}
|
||||
else
|
||||
{
|
||||
boolean started= false;
|
||||
boolean started = false;
|
||||
// This assumes constant time int arithmatic
|
||||
for (int i= 0; i < hexDivisors.length; i++)
|
||||
for (int i = 0; i < hexDivisors.length; i++)
|
||||
{
|
||||
if (n < hexDivisors[i])
|
||||
{
|
||||
|
@ -144,10 +290,10 @@ public class BufferUtil
|
|||
continue;
|
||||
}
|
||||
|
||||
started= true;
|
||||
int d= n / hexDivisors[i];
|
||||
started = true;
|
||||
int d = n / hexDivisors[i];
|
||||
buffer.put(DIGIT[d]);
|
||||
n= n - d * hexDivisors[i];
|
||||
n = n - d * hexDivisors[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -155,43 +301,43 @@ public class BufferUtil
|
|||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Add hex integer BEFORE current getIndex.
|
||||
*
|
||||
* @param buffer
|
||||
* @param n
|
||||
*/
|
||||
public static void prependHexInt(Buffer buffer, int n)
|
||||
public static void prependHexInt(ByteBuffer buffer, int n)
|
||||
{
|
||||
if (n==0)
|
||||
if (n == 0)
|
||||
{
|
||||
int gi=buffer.getIndex();
|
||||
buffer.poke(--gi,(byte)'0');
|
||||
buffer.setGetIndex(gi);
|
||||
int gi = buffer.position();
|
||||
buffer.put(--gi,(byte)'0');
|
||||
buffer.position(gi);
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean minus=false;
|
||||
if (n<0)
|
||||
boolean minus = false;
|
||||
if (n < 0)
|
||||
{
|
||||
minus=true;
|
||||
n=-n;
|
||||
minus = true;
|
||||
n = -n;
|
||||
}
|
||||
|
||||
int gi=buffer.getIndex();
|
||||
while(n>0)
|
||||
int gi = buffer.position();
|
||||
while (n > 0)
|
||||
{
|
||||
int d = 0xf&n;
|
||||
n=n>>4;
|
||||
buffer.poke(--gi,DIGIT[d]);
|
||||
int d = 0xf & n;
|
||||
n = n >> 4;
|
||||
buffer.put(--gi,DIGIT[d]);
|
||||
}
|
||||
|
||||
if (minus)
|
||||
buffer.poke(--gi,(byte)'-');
|
||||
buffer.setGetIndex(gi);
|
||||
buffer.put(--gi,(byte)'-');
|
||||
buffer.position(gi);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public static void putDecInt(Buffer buffer, int n)
|
||||
public static void putDecInt(ByteBuffer buffer, int n)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
|
@ -200,10 +346,10 @@ public class BufferUtil
|
|||
if (n == Integer.MIN_VALUE)
|
||||
{
|
||||
buffer.put((byte)'2');
|
||||
n= 147483648;
|
||||
n = 147483648;
|
||||
}
|
||||
else
|
||||
n= -n;
|
||||
n = -n;
|
||||
}
|
||||
|
||||
if (n < 10)
|
||||
|
@ -212,9 +358,9 @@ public class BufferUtil
|
|||
}
|
||||
else
|
||||
{
|
||||
boolean started= false;
|
||||
boolean started = false;
|
||||
// This assumes constant time int arithmatic
|
||||
for (int i= 0; i < decDivisors.length; i++)
|
||||
for (int i = 0; i < decDivisors.length; i++)
|
||||
{
|
||||
if (n < decDivisors[i])
|
||||
{
|
||||
|
@ -223,15 +369,15 @@ public class BufferUtil
|
|||
continue;
|
||||
}
|
||||
|
||||
started= true;
|
||||
int d= n / decDivisors[i];
|
||||
started = true;
|
||||
int d = n / decDivisors[i];
|
||||
buffer.put(DIGIT[d]);
|
||||
n= n - d * decDivisors[i];
|
||||
n = n - d * decDivisors[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void putDecLong(Buffer buffer, long n)
|
||||
public static void putDecLong(ByteBuffer buffer, long n)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
|
@ -240,10 +386,10 @@ public class BufferUtil
|
|||
if (n == Long.MIN_VALUE)
|
||||
{
|
||||
buffer.put((byte)'9');
|
||||
n= 223372036854775808L;
|
||||
n = 223372036854775808L;
|
||||
}
|
||||
else
|
||||
n= -n;
|
||||
n = -n;
|
||||
}
|
||||
|
||||
if (n < 10)
|
||||
|
@ -252,9 +398,9 @@ public class BufferUtil
|
|||
}
|
||||
else
|
||||
{
|
||||
boolean started= false;
|
||||
boolean started = false;
|
||||
// This assumes constant time int arithmatic
|
||||
for (int i= 0; i < decDivisorsL.length; i++)
|
||||
for (int i = 0; i < decDivisorsL.length; i++)
|
||||
{
|
||||
if (n < decDivisorsL[i])
|
||||
{
|
||||
|
@ -263,92 +409,64 @@ public class BufferUtil
|
|||
continue;
|
||||
}
|
||||
|
||||
started= true;
|
||||
long d= n / decDivisorsL[i];
|
||||
started = true;
|
||||
long d = n / decDivisorsL[i];
|
||||
buffer.put(DIGIT[(int)d]);
|
||||
n= n - d * decDivisorsL[i];
|
||||
n = n - d * decDivisorsL[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Buffer toBuffer(long value)
|
||||
public static ByteBuffer toBuffer(int value)
|
||||
{
|
||||
ByteArrayBuffer buf=new ByteArrayBuffer(32);
|
||||
putDecLong(buf, value);
|
||||
ByteBuffer buf = ByteBuffer.allocate(32);
|
||||
putDecInt(buf,value);
|
||||
return buf;
|
||||
}
|
||||
|
||||
private final static int[] decDivisors=
|
||||
public static ByteBuffer toBuffer(long value)
|
||||
{
|
||||
1000000000,
|
||||
100000000,
|
||||
10000000,
|
||||
1000000,
|
||||
100000,
|
||||
10000,
|
||||
1000,
|
||||
100,
|
||||
10,
|
||||
1
|
||||
};
|
||||
ByteBuffer buf = ByteBuffer.allocate(32);
|
||||
putDecLong(buf,value);
|
||||
return buf;
|
||||
}
|
||||
|
||||
private final static int[] hexDivisors=
|
||||
public static ByteBuffer toBuffer(String s)
|
||||
{
|
||||
0x10000000,
|
||||
0x1000000,
|
||||
0x100000,
|
||||
0x10000,
|
||||
0x1000,
|
||||
0x100,
|
||||
0x10,
|
||||
0x1
|
||||
};
|
||||
return ByteBuffer.wrap(s.getBytes(StringUtil.__ISO_8859_1_CHARSET));
|
||||
}
|
||||
|
||||
private final static long[] decDivisorsL=
|
||||
public static ByteBuffer toBuffer(String s, Charset charset)
|
||||
{
|
||||
1000000000000000000L,
|
||||
100000000000000000L,
|
||||
10000000000000000L,
|
||||
1000000000000000L,
|
||||
100000000000000L,
|
||||
10000000000000L,
|
||||
1000000000000L,
|
||||
100000000000L,
|
||||
10000000000L,
|
||||
1000000000L,
|
||||
100000000L,
|
||||
10000000L,
|
||||
1000000L,
|
||||
100000L,
|
||||
10000L,
|
||||
1000L,
|
||||
100L,
|
||||
10L,
|
||||
1L
|
||||
};
|
||||
return ByteBuffer.wrap(s.getBytes(charset));
|
||||
}
|
||||
|
||||
private final static int[] decDivisors =
|
||||
{ 1000000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1 };
|
||||
|
||||
public static void putCRLF(Buffer buffer)
|
||||
private final static int[] hexDivisors =
|
||||
{ 0x10000000, 0x1000000, 0x100000, 0x10000, 0x1000, 0x100, 0x10, 0x1 };
|
||||
|
||||
private final static long[] decDivisorsL =
|
||||
{ 1000000000000000000L, 100000000000000000L, 10000000000000000L, 1000000000000000L, 100000000000000L, 10000000000000L, 1000000000000L, 100000000000L,
|
||||
10000000000L, 1000000000L, 100000000L, 10000000L, 1000000L, 100000L, 10000L, 1000L, 100L, 10L, 1L };
|
||||
|
||||
public static void putCRLF(ByteBuffer buffer)
|
||||
{
|
||||
buffer.put((byte)13);
|
||||
buffer.put((byte)10);
|
||||
}
|
||||
|
||||
public static boolean isPrefix(Buffer prefix,Buffer buffer)
|
||||
public static boolean isPrefix(ByteBuffer prefix, ByteBuffer buffer)
|
||||
{
|
||||
if (prefix.length()>buffer.length())
|
||||
if (prefix.remaining() > buffer.remaining())
|
||||
return false;
|
||||
int bi=buffer.getIndex();
|
||||
for (int i=prefix.getIndex(); i<prefix.putIndex();i++)
|
||||
if (prefix.peek(i)!=buffer.peek(bi++))
|
||||
int bi = buffer.position();
|
||||
for (int i = prefix.position(); i < prefix.limit(); i++)
|
||||
if (prefix.get(i) != buffer.get(bi++))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String to8859_1_String(Buffer buffer)
|
||||
{
|
||||
if (buffer instanceof CachedBuffer)
|
||||
return buffer.toString();
|
||||
return buffer.toString(StringUtil.__ISO_8859_1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
package org.eclipse.jetty.io;
|
||||
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** BufferSource.
|
||||
* Represents a pool or other source of buffers and abstracts the creation
|
||||
|
@ -23,11 +25,11 @@ package org.eclipse.jetty.io;
|
|||
*/
|
||||
public interface Buffers
|
||||
{
|
||||
enum Type { BYTE_ARRAY, DIRECT, INDIRECT } ;
|
||||
enum Type { DIRECT, INDIRECT } ;
|
||||
|
||||
Buffer getHeader();
|
||||
Buffer getBuffer();
|
||||
Buffer getBuffer(int size);
|
||||
ByteBuffer getHeader();
|
||||
ByteBuffer getBuffer();
|
||||
ByteBuffer getBuffer(int size);
|
||||
|
||||
void returnBuffer(Buffer buffer);
|
||||
void returnBuffer(ByteBuffer buffer);
|
||||
}
|
||||
|
|
|
@ -1,417 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2004-2009 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
|
||||
{
|
||||
final protected byte[] _bytes;
|
||||
|
||||
protected ByteArrayBuffer(int size, int access, boolean isVolatile)
|
||||
{
|
||||
this(new byte[size],0,0,access, isVolatile);
|
||||
}
|
||||
|
||||
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(READWRITE, NON_VOLATILE);
|
||||
_bytes = bytes;
|
||||
setPutIndex(index + length);
|
||||
setGetIndex(index);
|
||||
_access = access;
|
||||
}
|
||||
|
||||
public ByteArrayBuffer(byte[] bytes, int index, int length, int access, boolean isVolatile)
|
||||
{
|
||||
super(READWRITE, isVolatile);
|
||||
_bytes = bytes;
|
||||
setPutIndex(index + length);
|
||||
setGetIndex(index);
|
||||
_access = access;
|
||||
}
|
||||
|
||||
public ByteArrayBuffer(int size)
|
||||
{
|
||||
this(new byte[size], 0, 0, READWRITE);
|
||||
setPutIndex(0);
|
||||
}
|
||||
|
||||
public ByteArrayBuffer(String value)
|
||||
{
|
||||
super(READWRITE,NON_VOLATILE);
|
||||
_bytes = StringUtil.getBytes(value);
|
||||
setGetIndex(0);
|
||||
setPutIndex(_bytes.length);
|
||||
_access=IMMUTABLE;
|
||||
_string = value;
|
||||
}
|
||||
|
||||
public ByteArrayBuffer(String value,boolean immutable)
|
||||
{
|
||||
super(READWRITE,NON_VOLATILE);
|
||||
_bytes = StringUtil.getBytes(value);
|
||||
setGetIndex(0);
|
||||
setPutIndex(_bytes.length);
|
||||
if (immutable)
|
||||
{
|
||||
_access=IMMUTABLE;
|
||||
_string = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ByteArrayBuffer(String value,String encoding) throws UnsupportedEncodingException
|
||||
{
|
||||
super(READWRITE,NON_VOLATILE);
|
||||
_bytes = value.getBytes(encoding);
|
||||
setGetIndex(0);
|
||||
setPutIndex(_bytes.length);
|
||||
_access=IMMUTABLE;
|
||||
_string = value;
|
||||
}
|
||||
|
||||
public byte[] array()
|
||||
{
|
||||
return _bytes;
|
||||
}
|
||||
|
||||
public int capacity()
|
||||
{
|
||||
return _bytes.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compact()
|
||||
{
|
||||
if (isReadOnly())
|
||||
throw new IllegalStateException(__READONLY);
|
||||
int s = markIndex() >= 0 ? markIndex() : getIndex();
|
||||
if (s > 0)
|
||||
{
|
||||
int length = putIndex() - s;
|
||||
if (length > 0)
|
||||
{
|
||||
System.arraycopy(_bytes, s,_bytes, 0, length);
|
||||
}
|
||||
if (markIndex() > 0) setMarkIndex(markIndex() - s);
|
||||
setGetIndex(getIndex() - s);
|
||||
setPutIndex(putIndex() - s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (obj==this)
|
||||
return true;
|
||||
|
||||
if (obj == null || !(obj instanceof Buffer))
|
||||
return false;
|
||||
|
||||
if (obj instanceof Buffer.CaseInsensitve)
|
||||
return equalsIgnoreCase((Buffer)obj);
|
||||
|
||||
|
||||
Buffer b = (Buffer) obj;
|
||||
|
||||
// reject different lengths
|
||||
if (b.length() != length())
|
||||
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 boolean equalsIgnoreCase(Buffer b)
|
||||
{
|
||||
if (b==this)
|
||||
return true;
|
||||
|
||||
// reject different lengths
|
||||
if (b==null || b.length() != length())
|
||||
return false;
|
||||
|
||||
// reject AbstractBuffer with different hash value
|
||||
if (_hash != 0 && b instanceof AbstractBuffer)
|
||||
{
|
||||
AbstractBuffer ab = (AbstractBuffer) b;
|
||||
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();
|
||||
byte[] barray=b.array();
|
||||
if (barray==null)
|
||||
{
|
||||
for (int i = putIndex(); i-->get;)
|
||||
{
|
||||
byte b1 = _bytes[i];
|
||||
byte b2 = b.peek(--bi);
|
||||
if (b1 != b2)
|
||||
{
|
||||
if ('a' <= b1 && b1 <= 'z') b1 = (byte) (b1 - 'a' + 'A');
|
||||
if ('a' <= b2 && b2 <= 'z') b2 = (byte) (b2 - 'a' + 'A');
|
||||
if (b1 != b2) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = putIndex(); i-->get;)
|
||||
{
|
||||
byte b1 = _bytes[i];
|
||||
byte b2 = barray[--bi];
|
||||
if (b1 != b2)
|
||||
{
|
||||
if ('a' <= b1 && b1 <= 'z') b1 = (byte) (b1 - 'a' + 'A');
|
||||
if ('a' <= b2 && b2 <= 'z') b2 = (byte) (b2 - 'a' + 'A');
|
||||
if (b1 != b2) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte get()
|
||||
{
|
||||
return _bytes[_get++];
|
||||
}
|
||||
|
||||
@Override
|
||||
public 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;
|
||||
}
|
||||
|
||||
|
||||
public byte peek(int index)
|
||||
{
|
||||
return _bytes[index];
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
System.arraycopy(_bytes, index, b, offset, l);
|
||||
return l;
|
||||
}
|
||||
|
||||
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());
|
||||
*/
|
||||
_bytes[index] = b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public 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.length();
|
||||
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 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 void writeTo(OutputStream out)
|
||||
throws IOException
|
||||
{
|
||||
out.write(_bytes,getIndex(),length());
|
||||
clear();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public 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 int space()
|
||||
{
|
||||
return _bytes.length - _put;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------ */
|
||||
public static class CaseInsensitive extends ByteArrayBuffer implements Buffer.CaseInsensitve
|
||||
{
|
||||
public CaseInsensitive(String s)
|
||||
{
|
||||
super(s);
|
||||
}
|
||||
|
||||
public CaseInsensitive(byte[] b, int o, int l, int rw)
|
||||
{
|
||||
super(b,o,l,rw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return obj instanceof Buffer && equalsIgnoreCase((Buffer)obj);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@
|
|||
package org.eclipse.jetty.io;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
|
||||
|
||||
|
@ -25,15 +26,13 @@ import java.io.IOException;
|
|||
public class ByteArrayEndPoint implements ConnectedEndPoint
|
||||
{
|
||||
protected byte[] _inBytes;
|
||||
protected ByteArrayBuffer _in;
|
||||
protected ByteArrayBuffer _out;
|
||||
protected ByteBuffer _in;
|
||||
protected ByteBuffer _out;
|
||||
protected boolean _closed;
|
||||
protected boolean _nonBlocking;
|
||||
protected boolean _growOutput;
|
||||
protected Connection _connection;
|
||||
protected int _maxIdleTime;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
*
|
||||
|
@ -42,6 +41,17 @@ public class ByteArrayEndPoint implements ConnectedEndPoint
|
|||
{
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ByteArrayEndPoint(byte[] input, int outputSize)
|
||||
{
|
||||
_inBytes=input;
|
||||
_in=ByteBuffer.wrap(input);
|
||||
_out=ByteBuffer.allocate(outputSize);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.io.ConnectedEndPoint#getConnection()
|
||||
|
@ -60,40 +70,11 @@ public class ByteArrayEndPoint implements ConnectedEndPoint
|
|||
_connection=connection;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return the nonBlocking
|
||||
*/
|
||||
public boolean isNonBlocking()
|
||||
{
|
||||
return _nonBlocking;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param nonBlocking the nonBlocking to set
|
||||
*/
|
||||
public void setNonBlocking(boolean nonBlocking)
|
||||
{
|
||||
_nonBlocking=nonBlocking;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ByteArrayEndPoint(byte[] input, int outputSize)
|
||||
{
|
||||
_inBytes=input;
|
||||
_in=new ByteArrayBuffer(input);
|
||||
_out=new ByteArrayBuffer(outputSize);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return Returns the in.
|
||||
*/
|
||||
public ByteArrayBuffer getIn()
|
||||
public ByteBuffer getIn()
|
||||
{
|
||||
return _in;
|
||||
}
|
||||
|
@ -101,7 +82,7 @@ public class ByteArrayEndPoint implements ConnectedEndPoint
|
|||
/**
|
||||
* @param in The in to set.
|
||||
*/
|
||||
public void setIn(ByteArrayBuffer in)
|
||||
public void setIn(ByteBuffer in)
|
||||
{
|
||||
_in = in;
|
||||
}
|
||||
|
@ -109,7 +90,7 @@ public class ByteArrayEndPoint implements ConnectedEndPoint
|
|||
/**
|
||||
* @return Returns the out.
|
||||
*/
|
||||
public ByteArrayBuffer getOut()
|
||||
public ByteBuffer getOut()
|
||||
{
|
||||
return _out;
|
||||
}
|
||||
|
@ -117,7 +98,7 @@ public class ByteArrayEndPoint implements ConnectedEndPoint
|
|||
/**
|
||||
* @param out The out to set.
|
||||
*/
|
||||
public void setOut(ByteArrayBuffer out)
|
||||
public void setOut(ByteBuffer out)
|
||||
{
|
||||
_out = out;
|
||||
}
|
||||
|
@ -149,15 +130,6 @@ public class ByteArrayEndPoint implements ConnectedEndPoint
|
|||
return _closed;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.io.EndPoint#isBlocking()
|
||||
*/
|
||||
public boolean isBlocking()
|
||||
{
|
||||
return !_nonBlocking;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean blockReadable(long millisecs)
|
||||
{
|
||||
|
@ -201,81 +173,60 @@ public class ByteArrayEndPoint implements ConnectedEndPoint
|
|||
/*
|
||||
* @see org.eclipse.io.EndPoint#fill(org.eclipse.io.Buffer)
|
||||
*/
|
||||
public int fill(Buffer buffer) throws IOException
|
||||
public int fill(ByteBuffer buffer) throws IOException
|
||||
{
|
||||
if (_closed)
|
||||
throw new IOException("CLOSED");
|
||||
if (_in!=null)
|
||||
return BufferUtil.put(_in,buffer);
|
||||
|
||||
if (_in!=null && _in.length()>0)
|
||||
{
|
||||
int len = buffer.put(_in);
|
||||
_in.skip(len);
|
||||
return len;
|
||||
}
|
||||
|
||||
if (_in!=null && _in.length()==0 && _nonBlocking)
|
||||
return 0;
|
||||
|
||||
close();
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.io.EndPoint#flush(org.eclipse.io.Buffer)
|
||||
*/
|
||||
public int flush(Buffer buffer) throws IOException
|
||||
public int flush(ByteBuffer buffer) throws IOException
|
||||
{
|
||||
if (_closed)
|
||||
throw new IOException("CLOSED");
|
||||
if (_growOutput && buffer.length()>_out.space())
|
||||
|
||||
if (_growOutput && buffer.remaining()>_out.remaining())
|
||||
{
|
||||
_out.compact();
|
||||
|
||||
if (buffer.length()>_out.space())
|
||||
if (buffer.remaining()>_out.remaining())
|
||||
{
|
||||
ByteArrayBuffer n = new ByteArrayBuffer(_out.putIndex()+buffer.length());
|
||||
|
||||
n.put(_out.peek(0,_out.putIndex()));
|
||||
if (_out.getIndex()>0)
|
||||
{
|
||||
n.mark();
|
||||
n.setGetIndex(_out.getIndex());
|
||||
}
|
||||
ByteBuffer n = ByteBuffer.allocate(_out.capacity()+buffer.remaining()*2);
|
||||
n.put(_out);
|
||||
_out=n;
|
||||
}
|
||||
}
|
||||
int len = _out.put(buffer);
|
||||
buffer.skip(len);
|
||||
return len;
|
||||
|
||||
int put=buffer.remaining();
|
||||
_out.put(buffer);
|
||||
return put;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.io.EndPoint#flush(org.eclipse.io.Buffer, org.eclipse.io.Buffer, org.eclipse.io.Buffer)
|
||||
*/
|
||||
public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException
|
||||
public int flush(ByteBuffer header, ByteBuffer buffer) throws IOException
|
||||
{
|
||||
if (_closed)
|
||||
throw new IOException("CLOSED");
|
||||
|
||||
int flushed=0;
|
||||
|
||||
if (header!=null && header.length()>0)
|
||||
if (header!=null && header.remaining()>0)
|
||||
flushed=flush(header);
|
||||
|
||||
if (header==null || header.length()==0)
|
||||
if (header==null || header.remaining()==0)
|
||||
{
|
||||
if (buffer!=null && buffer.length()>0)
|
||||
if (buffer!=null && buffer.remaining()>0)
|
||||
flushed+=flush(buffer);
|
||||
|
||||
if (buffer==null || buffer.length()==0)
|
||||
{
|
||||
if (trailer!=null && trailer.length()>0)
|
||||
{
|
||||
flushed+=flush(trailer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return flushed;
|
||||
|
@ -288,10 +239,8 @@ public class ByteArrayEndPoint implements ConnectedEndPoint
|
|||
public void reset()
|
||||
{
|
||||
_closed=false;
|
||||
_in.clear();
|
||||
_in.rewind();
|
||||
_out.clear();
|
||||
if (_inBytes!=null)
|
||||
_in.setPutIndex(_inBytes.length);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
package org.eclipse.jetty.io;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -42,42 +43,40 @@ public interface EndPoint
|
|||
void close() throws IOException;
|
||||
|
||||
/**
|
||||
* Fill the buffer from the current putIndex to it's capacity from whatever
|
||||
* byte source is backing the buffer. The putIndex is increased if bytes filled.
|
||||
* The buffer may chose to do a compact before filling.
|
||||
* Fill the passed buffer with data from this endpoint. The bytes are appended to any
|
||||
* data already in the buffer by writing from the buffers limit up to it's capacity.
|
||||
* The limit is updated to include the filled bytes.
|
||||
*
|
||||
* @param buffer The buffer to fill. The position and limit are modified during the fill. After the
|
||||
* operation, the position is unchanged and the limit is increased to reflect the new data filled.
|
||||
* @return an <code>int</code> value indicating the number of bytes
|
||||
* 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(ByteBuffer buffer) throws IOException;
|
||||
|
||||
|
||||
/**
|
||||
* Flush the buffer from the current getIndex to it's putIndex using whatever byte
|
||||
* sink is backing the buffer. The getIndex is updated with the number of bytes flushed.
|
||||
* Any mark set is cleared.
|
||||
* If the entire contents of the buffer are flushed, then an implicit empty() is done.
|
||||
* Flush data from the passed buffer to this endpoint. As many bytes as can be consumed
|
||||
* are taken from the buffer position up until the buffer limit. The
|
||||
* buffers position is updated to indicate how many bytes have been consumed.
|
||||
*
|
||||
* @param buffer The buffer to flush. This buffers getIndex is updated.
|
||||
* @param buffer The buffer to flush. This buffers position is updated if it is not read only.
|
||||
* @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(ByteBuffer buffer) throws IOException;
|
||||
|
||||
/**
|
||||
* Flush the buffer from the current getIndex to it's putIndex using whatever byte
|
||||
* sink is backing the buffer. The getIndex is updated with the number of bytes flushed.
|
||||
* Any mark set is cleared.
|
||||
* If the entire contents of the buffer are flushed, then an implicit empty() is done.
|
||||
* The passed header/trailer buffers are written before/after the contents of this buffer. This may be done
|
||||
* either as gather writes, as a poke into this buffer or as several writes. The implementation is free to
|
||||
* select the optimal mechanism.
|
||||
* @param header A buffer to write before flushing this buffer. This buffers getIndex is updated.
|
||||
* @param buffer The buffer to flush. This buffers getIndex is updated.
|
||||
* @param trailer A buffer to write after flushing this buffer. This buffers getIndex is updated.
|
||||
* @return the total number of bytes written.
|
||||
* Flush data from the passed header/buffer to this endpoint. As many bytes as can be consumed
|
||||
* are taken from the header/buffer position up until the buffer limit. The header/buffers position
|
||||
* is updated to indicate how many bytes have been consumed.
|
||||
*
|
||||
* @param buffer The buffer to flush. This buffers position is updated if it is not read only.
|
||||
* @return the number of bytes written
|
||||
* @throws EofException If the endpoint is closed or output is shutdown.
|
||||
*/
|
||||
int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException;
|
||||
int flush(ByteBuffer header, ByteBuffer buffer) throws IOException;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -122,9 +121,6 @@ public interface EndPoint
|
|||
*/
|
||||
public int getRemotePort();
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean isBlocking();
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean blockReadable(long millisecs) throws IOException;
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
package org.eclipse.jetty.io;
|
||||
|
||||
import java.net.Socket;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* <p>A listener for raw network traffic within Jetty.</p>
|
||||
|
@ -47,7 +48,7 @@ public interface NetworkTrafficListener
|
|||
* @param socket the socket associated with the remote client
|
||||
* @param bytes the read-only buffer containing the incoming bytes
|
||||
*/
|
||||
public void incoming(Socket socket, Buffer bytes);
|
||||
public void incoming(Socket socket, ByteBuffer bytes);
|
||||
|
||||
/**
|
||||
* <p>Callback method invoked when bytes are sent to a remote client from the server.</p>
|
||||
|
@ -56,7 +57,7 @@ public interface NetworkTrafficListener
|
|||
* @param socket the socket associated with the remote client
|
||||
* @param bytes the read-only buffer containing the outgoing bytes
|
||||
*/
|
||||
public void outgoing(Socket socket, Buffer bytes);
|
||||
public void outgoing(Socket socket, ByteBuffer bytes);
|
||||
|
||||
/**
|
||||
* <p>Callback method invoked when a connection to a remote client has been closed.</p>
|
||||
|
@ -79,11 +80,11 @@ public interface NetworkTrafficListener
|
|||
{
|
||||
}
|
||||
|
||||
public void incoming(Socket socket, Buffer bytes)
|
||||
public void incoming(Socket socket, ByteBuffer bytes)
|
||||
{
|
||||
}
|
||||
|
||||
public void outgoing(Socket socket, Buffer bytes)
|
||||
public void outgoing(Socket socket, ByteBuffer bytes)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
package org.eclipse.jetty.io;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class PooledBuffers extends AbstractBuffers
|
||||
{
|
||||
private final Queue<Buffer> _headers;
|
||||
private final Queue<Buffer> _buffers;
|
||||
private final Queue<Buffer> _others;
|
||||
private final Queue<ByteBuffer> _headers;
|
||||
private final Queue<ByteBuffer> _buffers;
|
||||
private final Queue<ByteBuffer> _others;
|
||||
private final AtomicInteger _size = new AtomicInteger();
|
||||
private final int _maxSize;
|
||||
private final boolean _otherHeaders;
|
||||
|
@ -18,18 +19,18 @@ public class PooledBuffers extends AbstractBuffers
|
|||
public PooledBuffers(Buffers.Type headerType, int headerSize, Buffers.Type bufferType, int bufferSize, Buffers.Type otherType,int maxSize)
|
||||
{
|
||||
super(headerType,headerSize,bufferType,bufferSize,otherType);
|
||||
_headers=new ConcurrentLinkedQueue<Buffer>();
|
||||
_buffers=new ConcurrentLinkedQueue<Buffer>();
|
||||
_others=new ConcurrentLinkedQueue<Buffer>();
|
||||
_headers=new ConcurrentLinkedQueue<ByteBuffer>();
|
||||
_buffers=new ConcurrentLinkedQueue<ByteBuffer>();
|
||||
_others=new ConcurrentLinkedQueue<ByteBuffer>();
|
||||
_otherHeaders=headerType==otherType;
|
||||
_otherBuffers=bufferType==otherType;
|
||||
_maxSize=maxSize;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public Buffer getHeader()
|
||||
public ByteBuffer getHeader()
|
||||
{
|
||||
Buffer buffer = _headers.poll();
|
||||
ByteBuffer buffer = _headers.poll();
|
||||
if (buffer==null)
|
||||
buffer=newHeader();
|
||||
else
|
||||
|
@ -38,9 +39,9 @@ public class PooledBuffers extends AbstractBuffers
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public Buffer getBuffer()
|
||||
public ByteBuffer getBuffer()
|
||||
{
|
||||
Buffer buffer = _buffers.poll();
|
||||
ByteBuffer buffer = _buffers.poll();
|
||||
if (buffer==null)
|
||||
buffer=newBuffer();
|
||||
else
|
||||
|
@ -49,7 +50,7 @@ public class PooledBuffers extends AbstractBuffers
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public Buffer getBuffer(int size)
|
||||
public ByteBuffer getBuffer(int size)
|
||||
{
|
||||
if (_otherHeaders && size==getHeaderSize())
|
||||
return getHeader();
|
||||
|
@ -57,7 +58,7 @@ public class PooledBuffers extends AbstractBuffers
|
|||
return getBuffer();
|
||||
|
||||
// Look for an other buffer
|
||||
Buffer buffer = _others.poll();
|
||||
ByteBuffer buffer = _others.poll();
|
||||
|
||||
// consume all other buffers until one of the right size is found
|
||||
while (buffer!=null && buffer.capacity()!=size)
|
||||
|
@ -74,10 +75,10 @@ public class PooledBuffers extends AbstractBuffers
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void returnBuffer(Buffer buffer)
|
||||
public void returnBuffer(ByteBuffer buffer)
|
||||
{
|
||||
buffer.clear();
|
||||
if (buffer.isVolatile() || buffer.isImmutable())
|
||||
buffer.clear().limit(0);
|
||||
if (buffer.isReadOnly())
|
||||
return;
|
||||
|
||||
if (_size.incrementAndGet() > _maxSize)
|
||||
|
@ -93,6 +94,7 @@ public class PooledBuffers extends AbstractBuffers
|
|||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public String toString()
|
||||
{
|
||||
return String.format("%s [%d/%d@%d,%d/%d@%d,%d/%d@-]",
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
|
||||
package org.eclipse.jetty.io;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** SimpleBuffers.
|
||||
* Simple implementation of Buffers holder.
|
||||
|
@ -21,8 +23,8 @@ package org.eclipse.jetty.io;
|
|||
*/
|
||||
public class SimpleBuffers implements Buffers
|
||||
{
|
||||
final Buffer _header;
|
||||
final Buffer _buffer;
|
||||
final ByteBuffer _header;
|
||||
final ByteBuffer _buffer;
|
||||
boolean _headerOut;
|
||||
boolean _bufferOut;
|
||||
|
||||
|
@ -30,14 +32,14 @@ public class SimpleBuffers implements Buffers
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public SimpleBuffers(Buffer header, Buffer buffer)
|
||||
public SimpleBuffers(ByteBuffer header, ByteBuffer buffer)
|
||||
{
|
||||
_header=header;
|
||||
_buffer=buffer;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public Buffer getBuffer()
|
||||
public ByteBuffer getBuffer()
|
||||
{
|
||||
synchronized(this)
|
||||
{
|
||||
|
@ -54,13 +56,13 @@ public class SimpleBuffers implements Buffers
|
|||
}
|
||||
|
||||
if (_buffer!=null)
|
||||
return new ByteArrayBuffer(_buffer.capacity());
|
||||
return new ByteArrayBuffer(4096);
|
||||
return ByteBuffer.allocate(_buffer.capacity());
|
||||
return ByteBuffer.allocate(4096);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public Buffer getHeader()
|
||||
public ByteBuffer getHeader()
|
||||
{
|
||||
synchronized(this)
|
||||
{
|
||||
|
@ -77,13 +79,13 @@ public class SimpleBuffers implements Buffers
|
|||
}
|
||||
|
||||
if (_header!=null)
|
||||
return new ByteArrayBuffer(_header.capacity());
|
||||
return new ByteArrayBuffer(4096);
|
||||
return ByteBuffer.allocate(_header.capacity());
|
||||
return ByteBuffer.allocate(4096);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public Buffer getBuffer(int size)
|
||||
public ByteBuffer getBuffer(int size)
|
||||
{
|
||||
synchronized(this)
|
||||
{
|
||||
|
@ -96,11 +98,11 @@ public class SimpleBuffers implements Buffers
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void returnBuffer(Buffer buffer)
|
||||
public void returnBuffer(ByteBuffer buffer)
|
||||
{
|
||||
synchronized(this)
|
||||
{
|
||||
buffer.clear();
|
||||
buffer.clear().limit(0);
|
||||
if (buffer==_header)
|
||||
_headerOut=false;
|
||||
if (buffer==_buffer)
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
|
||||
package org.eclipse.jetty.io;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -39,19 +41,19 @@ public class ThreadLocalBuffers extends AbstractBuffers
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public Buffer getBuffer()
|
||||
public ByteBuffer getBuffer()
|
||||
{
|
||||
ThreadBuffers buffers = _buffers.get();
|
||||
if (buffers._buffer!=null)
|
||||
{
|
||||
Buffer b=buffers._buffer;
|
||||
ByteBuffer b=buffers._buffer;
|
||||
buffers._buffer=null;
|
||||
return b;
|
||||
}
|
||||
|
||||
if (buffers._other!=null && isBuffer(buffers._other))
|
||||
{
|
||||
Buffer b=buffers._other;
|
||||
ByteBuffer b=buffers._other;
|
||||
buffers._other=null;
|
||||
return b;
|
||||
}
|
||||
|
@ -60,19 +62,19 @@ public class ThreadLocalBuffers extends AbstractBuffers
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public Buffer getHeader()
|
||||
public ByteBuffer getHeader()
|
||||
{
|
||||
ThreadBuffers buffers = _buffers.get();
|
||||
if (buffers._header!=null)
|
||||
{
|
||||
Buffer b=buffers._header;
|
||||
ByteBuffer b=buffers._header;
|
||||
buffers._header=null;
|
||||
return b;
|
||||
}
|
||||
|
||||
if (buffers._other!=null && isHeader(buffers._other))
|
||||
{
|
||||
Buffer b=buffers._other;
|
||||
ByteBuffer b=buffers._other;
|
||||
buffers._other=null;
|
||||
return b;
|
||||
}
|
||||
|
@ -81,12 +83,12 @@ public class ThreadLocalBuffers extends AbstractBuffers
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public Buffer getBuffer(int size)
|
||||
public ByteBuffer getBuffer(int size)
|
||||
{
|
||||
ThreadBuffers buffers = _buffers.get();
|
||||
if (buffers._other!=null && buffers._other.capacity()==size)
|
||||
{
|
||||
Buffer b=buffers._other;
|
||||
ByteBuffer b=buffers._other;
|
||||
buffers._other=null;
|
||||
return b;
|
||||
}
|
||||
|
@ -95,10 +97,10 @@ public class ThreadLocalBuffers extends AbstractBuffers
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void returnBuffer(Buffer buffer)
|
||||
public void returnBuffer(ByteBuffer buffer)
|
||||
{
|
||||
buffer.clear();
|
||||
if (buffer.isVolatile() || buffer.isImmutable())
|
||||
buffer.clear().limit(0);
|
||||
if (buffer.isReadOnly())
|
||||
return;
|
||||
|
||||
ThreadBuffers buffers = _buffers.get();
|
||||
|
@ -123,8 +125,8 @@ public class ThreadLocalBuffers extends AbstractBuffers
|
|||
/* ------------------------------------------------------------ */
|
||||
protected static class ThreadBuffers
|
||||
{
|
||||
Buffer _buffer;
|
||||
Buffer _header;
|
||||
Buffer _other;
|
||||
ByteBuffer _buffer;
|
||||
ByteBuffer _header;
|
||||
ByteBuffer _other;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,246 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2004-2009 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.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class View extends AbstractBuffer
|
||||
{
|
||||
Buffer _buffer;
|
||||
|
||||
/**
|
||||
* @param buffer The <code>Buffer</code> on which we are presenting a <code>View</code>.
|
||||
* @param mark The initial value of the {@link Buffer#markIndex mark index}
|
||||
* @param get The initial value of the {@link Buffer#getIndex get index}
|
||||
* @param put The initial value of the {@link Buffer#putIndex put index}
|
||||
* @param access The access level - one of the constants from {@link Buffer}.
|
||||
*/
|
||||
public View(Buffer buffer, int mark, int get, int put,int access)
|
||||
{
|
||||
super(READWRITE,!buffer.isImmutable());
|
||||
_buffer=buffer.buffer();
|
||||
setPutIndex(put);
|
||||
setGetIndex(get);
|
||||
setMarkIndex(mark);
|
||||
_access=access;
|
||||
}
|
||||
|
||||
public View(Buffer buffer)
|
||||
{
|
||||
super(READWRITE,!buffer.isImmutable());
|
||||
_buffer=buffer.buffer();
|
||||
setPutIndex(buffer.putIndex());
|
||||
setGetIndex(buffer.getIndex());
|
||||
setMarkIndex(buffer.markIndex());
|
||||
_access=buffer.isReadOnly()?READONLY:READWRITE;
|
||||
}
|
||||
|
||||
public View()
|
||||
{
|
||||
super(READWRITE,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update view to buffer
|
||||
*/
|
||||
public void update(Buffer buffer)
|
||||
{
|
||||
_access=READWRITE;
|
||||
_buffer=buffer.buffer();
|
||||
setGetIndex(0);
|
||||
setPutIndex(buffer.putIndex());
|
||||
setGetIndex(buffer.getIndex());
|
||||
setMarkIndex(buffer.markIndex());
|
||||
_access=buffer.isReadOnly()?READONLY:READWRITE;
|
||||
}
|
||||
|
||||
public void update(int get, int put)
|
||||
{
|
||||
int a=_access;
|
||||
_access=READWRITE;
|
||||
setGetIndex(0);
|
||||
setPutIndex(put);
|
||||
setGetIndex(get);
|
||||
setMarkIndex(-1);
|
||||
_access=a;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The {@link Buffer#array()} from the underlying buffer.
|
||||
*/
|
||||
public byte[] array()
|
||||
{
|
||||
return _buffer.array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The {@link Buffer#buffer()} from the underlying buffer.
|
||||
*/
|
||||
@Override
|
||||
public Buffer buffer()
|
||||
{
|
||||
return _buffer.buffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The {@link Buffer#capacity} of the underlying buffer.
|
||||
*/
|
||||
public int capacity()
|
||||
{
|
||||
return _buffer.capacity();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
setMarkIndex(-1);
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether the underlying buffer is {@link Buffer#isReadOnly read only}
|
||||
*/
|
||||
@Override
|
||||
public boolean isReadOnly()
|
||||
{
|
||||
return _buffer.isReadOnly();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether the underlying buffer is {@link Buffer#isVolatile volatile}
|
||||
*/
|
||||
@Override
|
||||
public boolean isVolatile()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The result of calling {@link Buffer#peek(int)} on the underlying buffer
|
||||
*/
|
||||
public byte peek(int index)
|
||||
{
|
||||
return _buffer.peek(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The result of calling {@link Buffer#peek(int, byte[], int, int)} on the underlying buffer
|
||||
*/
|
||||
public int peek(int index, byte[] b, int offset, int length)
|
||||
{
|
||||
return _buffer.peek(index,b,offset,length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The result of calling {@link Buffer#peek(int, int)} on the underlying buffer
|
||||
*/
|
||||
@Override
|
||||
public Buffer peek(int index, int length)
|
||||
{
|
||||
return _buffer.peek(index, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param index
|
||||
* @param src
|
||||
*/
|
||||
@Override
|
||||
public int poke(int index, Buffer src)
|
||||
{
|
||||
return _buffer.poke(index,src);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param index
|
||||
* @param b
|
||||
*/
|
||||
public void poke(int index, byte b)
|
||||
{
|
||||
_buffer.poke(index,b);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param index
|
||||
* @param b
|
||||
* @param offset
|
||||
* @param length
|
||||
*/
|
||||
@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();
|
||||
}
|
||||
|
||||
public static class CaseInsensitive extends View implements Buffer.CaseInsensitve
|
||||
{
|
||||
public CaseInsensitive()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public CaseInsensitive(Buffer buffer, int mark, int get, int put, int access)
|
||||
{
|
||||
super(buffer,mark,get,put,access);
|
||||
}
|
||||
|
||||
public CaseInsensitive(Buffer buffer)
|
||||
{
|
||||
super(buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return this==obj ||((obj instanceof Buffer)&&((Buffer)obj).equalsIgnoreCase(this)) || super.equals(obj);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,281 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2004-2010 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.bio;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
|
||||
import javax.net.ssl.SSLSocket;
|
||||
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
public class SocketEndPoint extends StreamEndPoint
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(SocketEndPoint.class);
|
||||
|
||||
final Socket _socket;
|
||||
final InetSocketAddress _local;
|
||||
final InetSocketAddress _remote;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public SocketEndPoint(Socket socket)
|
||||
throws IOException
|
||||
{
|
||||
super(socket.getInputStream(),socket.getOutputStream());
|
||||
_socket=socket;
|
||||
_local=(InetSocketAddress)_socket.getLocalSocketAddress();
|
||||
_remote=(InetSocketAddress)_socket.getRemoteSocketAddress();
|
||||
super.setMaxIdleTime(_socket.getSoTimeout());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected SocketEndPoint(Socket socket, int maxIdleTime)
|
||||
throws IOException
|
||||
{
|
||||
super(socket.getInputStream(),socket.getOutputStream());
|
||||
_socket=socket;
|
||||
_local=(InetSocketAddress)_socket.getLocalSocketAddress();
|
||||
_remote=(InetSocketAddress)_socket.getRemoteSocketAddress();
|
||||
_socket.setSoTimeout(maxIdleTime>0?maxIdleTime:0);
|
||||
super.setMaxIdleTime(maxIdleTime);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.io.BufferIO#isClosed()
|
||||
*/
|
||||
@Override
|
||||
public boolean isOpen()
|
||||
{
|
||||
return super.isOpen() && _socket!=null && !_socket.isClosed();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public boolean isInputShutdown()
|
||||
{
|
||||
if (_socket instanceof SSLSocket)
|
||||
return super.isInputShutdown();
|
||||
return _socket.isClosed() || _socket.isInputShutdown();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public boolean isOutputShutdown()
|
||||
{
|
||||
if (_socket instanceof SSLSocket)
|
||||
return super.isOutputShutdown();
|
||||
|
||||
return _socket.isClosed() || _socket.isOutputShutdown();
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
*/
|
||||
protected final void shutdownSocketOutput() throws IOException
|
||||
{
|
||||
if (!_socket.isClosed())
|
||||
{
|
||||
if (!_socket.isOutputShutdown())
|
||||
_socket.shutdownOutput();
|
||||
if (_socket.isInputShutdown())
|
||||
_socket.close();
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.jetty.io.bio.StreamEndPoint#shutdownOutput()
|
||||
*/
|
||||
@Override
|
||||
public void shutdownOutput() throws IOException
|
||||
{
|
||||
if (_socket instanceof SSLSocket)
|
||||
super.shutdownOutput();
|
||||
else
|
||||
shutdownSocketOutput();
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
*/
|
||||
public void shutdownSocketInput() throws IOException
|
||||
{
|
||||
if (!_socket.isClosed())
|
||||
{
|
||||
if (!_socket.isInputShutdown())
|
||||
_socket.shutdownInput();
|
||||
if (_socket.isOutputShutdown())
|
||||
_socket.close();
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.jetty.io.bio.StreamEndPoint#shutdownOutput()
|
||||
*/
|
||||
@Override
|
||||
public void shutdownInput() throws IOException
|
||||
{
|
||||
if (_socket instanceof SSLSocket)
|
||||
super.shutdownInput();
|
||||
else
|
||||
shutdownSocketInput();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.io.BufferIO#close()
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException
|
||||
{
|
||||
_socket.close();
|
||||
_in=null;
|
||||
_out=null;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.io.EndPoint#getLocalAddr()
|
||||
*/
|
||||
@Override
|
||||
public String getLocalAddr()
|
||||
{
|
||||
if (_local==null || _local.getAddress()==null || _local.getAddress().isAnyLocalAddress())
|
||||
return StringUtil.ALL_INTERFACES;
|
||||
|
||||
return _local.getAddress().getHostAddress();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.io.EndPoint#getLocalHost()
|
||||
*/
|
||||
@Override
|
||||
public String getLocalHost()
|
||||
{
|
||||
if (_local==null || _local.getAddress()==null || _local.getAddress().isAnyLocalAddress())
|
||||
return StringUtil.ALL_INTERFACES;
|
||||
|
||||
return _local.getAddress().getCanonicalHostName();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.io.EndPoint#getLocalPort()
|
||||
*/
|
||||
@Override
|
||||
public int getLocalPort()
|
||||
{
|
||||
if (_local==null)
|
||||
return -1;
|
||||
return _local.getPort();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.io.EndPoint#getRemoteAddr()
|
||||
*/
|
||||
@Override
|
||||
public String getRemoteAddr()
|
||||
{
|
||||
if (_remote==null)
|
||||
return null;
|
||||
InetAddress addr = _remote.getAddress();
|
||||
return ( addr == null ? null : addr.getHostAddress() );
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.io.EndPoint#getRemoteHost()
|
||||
*/
|
||||
@Override
|
||||
public String getRemoteHost()
|
||||
{
|
||||
if (_remote==null)
|
||||
return null;
|
||||
return _remote.getAddress().getCanonicalHostName();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.io.EndPoint#getRemotePort()
|
||||
*/
|
||||
@Override
|
||||
public int getRemotePort()
|
||||
{
|
||||
if (_remote==null)
|
||||
return -1;
|
||||
return _remote.getPort();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.io.EndPoint#getConnection()
|
||||
*/
|
||||
@Override
|
||||
public Object getTransport()
|
||||
{
|
||||
return _socket;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.io.bio.StreamEndPoint#setMaxIdleTime(int)
|
||||
*/
|
||||
@Override
|
||||
public void setMaxIdleTime(int timeMs) throws IOException
|
||||
{
|
||||
if (timeMs!=getMaxIdleTime())
|
||||
_socket.setSoTimeout(timeMs>0?timeMs:0);
|
||||
super.setMaxIdleTime(timeMs);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
protected void idleExpired() throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!isInputShutdown())
|
||||
shutdownInput();
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
LOG.ignore(e);
|
||||
_socket.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return _local + " <--> " + _remote;
|
||||
}
|
||||
}
|
|
@ -1,319 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2004-2009 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.bio;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.SocketTimeoutException;
|
||||
|
||||
import org.eclipse.jetty.io.Buffer;
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
|
||||
public class StreamEndPoint implements EndPoint
|
||||
{
|
||||
InputStream _in;
|
||||
OutputStream _out;
|
||||
int _maxIdleTime;
|
||||
boolean _ishut;
|
||||
boolean _oshut;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StreamEndPoint(InputStream in, OutputStream out)
|
||||
{
|
||||
_in=in;
|
||||
_out=out;
|
||||
}
|
||||
|
||||
public boolean isBlocking()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean blockReadable(long millisecs) throws IOException
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean blockWritable(long millisecs) throws IOException
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.io.BufferIO#isOpen()
|
||||
*/
|
||||
public boolean isOpen()
|
||||
{
|
||||
return _in!=null;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.io.BufferIO#isOpen()
|
||||
*/
|
||||
public final boolean isClosed()
|
||||
{
|
||||
return !isOpen();
|
||||
}
|
||||
|
||||
public void shutdownOutput() throws IOException
|
||||
{
|
||||
_oshut = true;
|
||||
if (_ishut && _out!=null)
|
||||
_out.close();
|
||||
}
|
||||
|
||||
public boolean isInputShutdown()
|
||||
{
|
||||
return _ishut;
|
||||
}
|
||||
|
||||
public void shutdownInput() throws IOException
|
||||
{
|
||||
_ishut = true;
|
||||
if (_oshut&&_in!=null)
|
||||
_in.close();
|
||||
}
|
||||
|
||||
public boolean isOutputShutdown()
|
||||
{
|
||||
return _oshut;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.io.BufferIO#close()
|
||||
*/
|
||||
public void close() throws IOException
|
||||
{
|
||||
if (_in!=null)
|
||||
_in.close();
|
||||
_in=null;
|
||||
if (_out!=null)
|
||||
_out.close();
|
||||
_out=null;
|
||||
}
|
||||
|
||||
protected void idleExpired() throws IOException
|
||||
{
|
||||
if (_in!=null)
|
||||
_in.close();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.io.BufferIO#fill(org.eclipse.io.Buffer)
|
||||
*/
|
||||
public int fill(Buffer buffer) throws IOException
|
||||
{
|
||||
if (_ishut)
|
||||
return -1;
|
||||
if (_in==null)
|
||||
return 0;
|
||||
|
||||
int space=buffer.space();
|
||||
if (space<=0)
|
||||
{
|
||||
if (buffer.hasContent())
|
||||
return 0;
|
||||
throw new IOException("FULL");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
int filled=buffer.readFrom(_in, space);
|
||||
if (filled<0)
|
||||
shutdownInput();
|
||||
return filled;
|
||||
}
|
||||
catch(SocketTimeoutException e)
|
||||
{
|
||||
idleExpired();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.io.BufferIO#flush(org.eclipse.io.Buffer)
|
||||
*/
|
||||
public int flush(Buffer buffer) throws IOException
|
||||
{
|
||||
if (_oshut)
|
||||
return -1;
|
||||
if (_out==null)
|
||||
return 0;
|
||||
int length=buffer.length();
|
||||
if (length>0)
|
||||
buffer.writeTo(_out);
|
||||
buffer.clear();
|
||||
return length;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.io.BufferIO#flush(org.eclipse.io.Buffer, org.eclipse.io.Buffer, org.eclipse.io.Buffer)
|
||||
*/
|
||||
public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException
|
||||
{
|
||||
int len=0;
|
||||
|
||||
if (header!=null)
|
||||
{
|
||||
int tw=header.length();
|
||||
if (tw>0)
|
||||
{
|
||||
int f=flush(header);
|
||||
len=f;
|
||||
if (f<tw)
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
||||
if (buffer!=null)
|
||||
{
|
||||
int tw=buffer.length();
|
||||
if (tw>0)
|
||||
{
|
||||
int f=flush(buffer);
|
||||
if (f<0)
|
||||
return len>0?len:f;
|
||||
len+=f;
|
||||
if (f<tw)
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
||||
if (trailer!=null)
|
||||
{
|
||||
int tw=trailer.length();
|
||||
if (tw>0)
|
||||
{
|
||||
int f=flush(trailer);
|
||||
if (f<0)
|
||||
return len>0?len:f;
|
||||
len+=f;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.io.EndPoint#getLocalAddr()
|
||||
*/
|
||||
public String getLocalAddr()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.io.EndPoint#getLocalHost()
|
||||
*/
|
||||
public String getLocalHost()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.io.EndPoint#getLocalPort()
|
||||
*/
|
||||
public int getLocalPort()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.io.EndPoint#getRemoteAddr()
|
||||
*/
|
||||
public String getRemoteAddr()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.io.EndPoint#getRemoteHost()
|
||||
*/
|
||||
public String getRemoteHost()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.io.EndPoint#getRemotePort()
|
||||
*/
|
||||
public int getRemotePort()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.io.EndPoint#getConnection()
|
||||
*/
|
||||
public Object getTransport()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public InputStream getInputStream()
|
||||
{
|
||||
return _in;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void setInputStream(InputStream in)
|
||||
{
|
||||
_in=in;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public OutputStream getOutputStream()
|
||||
{
|
||||
return _out;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void setOutputStream(OutputStream out)
|
||||
{
|
||||
_out=out;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void flush()
|
||||
throws IOException
|
||||
{
|
||||
if (_out != null)
|
||||
_out.flush();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public int getMaxIdleTime()
|
||||
{
|
||||
return _maxIdleTime;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void setMaxIdleTime(int timeMs) throws IOException
|
||||
{
|
||||
_maxIdleTime=timeMs;
|
||||
}
|
||||
|
||||
}
|
|
@ -15,7 +15,12 @@ package org.eclipse.jetty.io.bio;
|
|||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.eclipse.jetty.io.BufferUtil;
|
||||
import org.eclipse.jetty.io.ByteArrayEndPoint;
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
|
||||
/**
|
||||
|
@ -24,37 +29,26 @@ import org.eclipse.jetty.util.StringUtil;
|
|||
* To change the template for this generated type comment go to
|
||||
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||
*/
|
||||
public class StringEndPoint extends StreamEndPoint
|
||||
public class StringEndPoint extends ByteArrayEndPoint
|
||||
{
|
||||
String _encoding=StringUtil.__UTF8;
|
||||
ByteArrayInputStream _bin = new ByteArrayInputStream(new byte[0]);
|
||||
ByteArrayOutputStream _bout = new ByteArrayOutputStream();
|
||||
Charset _charset=StringUtil.__UTF8_CHARSET;
|
||||
|
||||
public StringEndPoint()
|
||||
{
|
||||
super(null,null);
|
||||
_in=_bin;
|
||||
_out=_bout;
|
||||
}
|
||||
|
||||
public StringEndPoint(String encoding)
|
||||
{
|
||||
this();
|
||||
if (encoding!=null)
|
||||
_encoding=encoding;
|
||||
_charset=Charset.forName(encoding);
|
||||
}
|
||||
|
||||
public void setInput(String s)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] bytes = s.getBytes(_encoding);
|
||||
_bin=new ByteArrayInputStream(bytes);
|
||||
_in=_bin;
|
||||
_bout = new ByteArrayOutputStream();
|
||||
_out=_bout;
|
||||
_ishut=false;
|
||||
_oshut=false;
|
||||
super.setIn(BufferUtil.toBuffer(s,_charset));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
@ -64,17 +58,11 @@ public class StringEndPoint extends StreamEndPoint
|
|||
|
||||
public String getOutput()
|
||||
{
|
||||
try
|
||||
{
|
||||
String s = new String(_bout.toByteArray(),_encoding);
|
||||
_bout.reset();
|
||||
return s;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
throw new IllegalStateException(_encoding+": "+e.toString());
|
||||
}
|
||||
ByteBuffer b = getOut();
|
||||
b.flip();
|
||||
String s=BufferUtil.toString(b,_charset);
|
||||
b.clear();
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,6 +70,6 @@ public class StringEndPoint extends StreamEndPoint
|
|||
*/
|
||||
public boolean hasMore()
|
||||
{
|
||||
return _bin.available()>0;
|
||||
return getOut().position()>0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import java.nio.channels.GatheringByteChannel;
|
|||
import java.nio.channels.SelectableChannel;
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
||||
import org.eclipse.jetty.io.Buffer;
|
||||
import org.eclipse.jetty.io.BufferUtil;
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
|
@ -208,210 +208,61 @@ public class ChannelEndPoint implements EndPoint
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.io.EndPoint#fill(org.eclipse.io.Buffer)
|
||||
*/
|
||||
public int fill(Buffer buffer) throws IOException
|
||||
public int fill(ByteBuffer buffer) throws IOException
|
||||
{
|
||||
if (_ishut)
|
||||
return -1;
|
||||
Buffer buf = buffer.buffer();
|
||||
int len=0;
|
||||
if (buf instanceof NIOBuffer)
|
||||
|
||||
int pos=buffer.position();
|
||||
try
|
||||
{
|
||||
final NIOBuffer nbuf = (NIOBuffer)buf;
|
||||
final ByteBuffer bbuf=nbuf.getByteBuffer();
|
||||
buffer.position(buffer.limit());
|
||||
buffer.limit(buffer.capacity());
|
||||
|
||||
//noinspection SynchronizationOnLocalVariableOrMethodParameter
|
||||
try
|
||||
{
|
||||
synchronized(bbuf)
|
||||
{
|
||||
try
|
||||
{
|
||||
bbuf.position(buffer.putIndex());
|
||||
len=_channel.read(bbuf);
|
||||
}
|
||||
finally
|
||||
{
|
||||
buffer.setPutIndex(bbuf.position());
|
||||
bbuf.position(0);
|
||||
}
|
||||
}
|
||||
int filled = _channel.read(buffer);
|
||||
|
||||
if (len<0 && isOpen())
|
||||
{
|
||||
if (!isInputShutdown())
|
||||
shutdownInput();
|
||||
if (isOutputShutdown())
|
||||
_channel.close();
|
||||
}
|
||||
}
|
||||
catch (IOException x)
|
||||
{
|
||||
LOG.debug("Exception while filling", x);
|
||||
try
|
||||
{
|
||||
if (_channel.isOpen())
|
||||
_channel.close();
|
||||
}
|
||||
catch (Exception xx)
|
||||
{
|
||||
LOG.ignore(xx);
|
||||
}
|
||||
if (filled==-1)
|
||||
shutdownInput();
|
||||
|
||||
if (len>0)
|
||||
throw x;
|
||||
len=-1;
|
||||
}
|
||||
return filled;
|
||||
}
|
||||
else
|
||||
finally
|
||||
{
|
||||
throw new IOException("Not Implemented");
|
||||
buffer.limit(buffer.position());
|
||||
buffer.position(pos);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.io.EndPoint#flush(org.eclipse.io.Buffer)
|
||||
*/
|
||||
public int flush(Buffer buffer) throws IOException
|
||||
public int flush(ByteBuffer buffer) throws IOException
|
||||
{
|
||||
Buffer buf = buffer.buffer();
|
||||
int len=0;
|
||||
if (buf instanceof NIOBuffer)
|
||||
{
|
||||
final NIOBuffer nbuf = (NIOBuffer)buf;
|
||||
final ByteBuffer bbuf=nbuf.getByteBuffer();
|
||||
|
||||
//noinspection SynchronizationOnLocalVariableOrMethodParameter
|
||||
synchronized(bbuf)
|
||||
{
|
||||
try
|
||||
{
|
||||
bbuf.position(buffer.getIndex());
|
||||
bbuf.limit(buffer.putIndex());
|
||||
len=_channel.write(bbuf);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (len>0)
|
||||
buffer.skip(len);
|
||||
bbuf.position(0);
|
||||
bbuf.limit(bbuf.capacity());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (buf instanceof RandomAccessFileBuffer)
|
||||
{
|
||||
len = ((RandomAccessFileBuffer)buf).writeTo(_channel,buffer.getIndex(),buffer.length());
|
||||
if (len>0)
|
||||
buffer.skip(len);
|
||||
}
|
||||
else if (buffer.array()!=null)
|
||||
{
|
||||
ByteBuffer b = ByteBuffer.wrap(buffer.array(), buffer.getIndex(), buffer.length());
|
||||
len=_channel.write(b);
|
||||
if (len>0)
|
||||
buffer.skip(len);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IOException("Not Implemented");
|
||||
}
|
||||
int len=_channel.write(buffer);
|
||||
return len;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.io.EndPoint#flush(org.eclipse.io.Buffer, org.eclipse.io.Buffer, org.eclipse.io.Buffer)
|
||||
*/
|
||||
public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException
|
||||
public int flush(ByteBuffer header, ByteBuffer buffer) throws IOException
|
||||
{
|
||||
int length=0;
|
||||
|
||||
Buffer buf0 = header==null?null:header.buffer();
|
||||
Buffer buf1 = buffer==null?null:buffer.buffer();
|
||||
|
||||
if (_channel instanceof GatheringByteChannel &&
|
||||
header!=null && header.length()!=0 && buf0 instanceof NIOBuffer &&
|
||||
buffer!=null && buffer.length()!=0 && buf1 instanceof NIOBuffer)
|
||||
{
|
||||
length = gatheringFlush(header,((NIOBuffer)buf0).getByteBuffer(),buffer,((NIOBuffer)buf1).getByteBuffer());
|
||||
}
|
||||
int len;
|
||||
if (buffer==null||buffer.remaining()==0)
|
||||
len=flush(header);
|
||||
else if (header==null||header.remaining()==0)
|
||||
len=flush(buffer);
|
||||
else if (_channel instanceof GatheringByteChannel)
|
||||
len= (int)((GatheringByteChannel)_channel).write(new ByteBuffer[]{header,buffer},0,2);
|
||||
else
|
||||
{
|
||||
// flush header
|
||||
if (header!=null && header.length()>0)
|
||||
length=flush(header);
|
||||
len=flush(header);
|
||||
|
||||
// flush buffer
|
||||
if ((header==null || header.length()==0) &&
|
||||
buffer!=null && buffer.length()>0)
|
||||
length+=flush(buffer);
|
||||
|
||||
// flush trailer
|
||||
if ((header==null || header.length()==0) &&
|
||||
(buffer==null || buffer.length()==0) &&
|
||||
trailer!=null && trailer.length()>0)
|
||||
length+=flush(trailer);
|
||||
if (header.remaining()==0)
|
||||
len+=flush(buffer);
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
protected int gatheringFlush(Buffer header, ByteBuffer bbuf0, Buffer buffer, ByteBuffer bbuf1) throws IOException
|
||||
{
|
||||
int length;
|
||||
|
||||
synchronized(this)
|
||||
{
|
||||
// We must sync because buffers may be shared (eg nbuf1 is likely to be cached content).
|
||||
//noinspection SynchronizationOnLocalVariableOrMethodParameter
|
||||
synchronized(bbuf0)
|
||||
{
|
||||
//noinspection SynchronizationOnLocalVariableOrMethodParameter
|
||||
synchronized(bbuf1)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Adjust position indexs of buf0 and buf1
|
||||
bbuf0.position(header.getIndex());
|
||||
bbuf0.limit(header.putIndex());
|
||||
bbuf1.position(buffer.getIndex());
|
||||
bbuf1.limit(buffer.putIndex());
|
||||
|
||||
_gather2[0]=bbuf0;
|
||||
_gather2[1]=bbuf1;
|
||||
|
||||
// do the gathering write.
|
||||
length=(int)((GatheringByteChannel)_channel).write(_gather2);
|
||||
|
||||
int hl=header.length();
|
||||
if (length>hl)
|
||||
{
|
||||
header.clear();
|
||||
buffer.skip(length-hl);
|
||||
}
|
||||
else if (length>0)
|
||||
{
|
||||
header.skip(length);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
// adjust buffer 0 and 1
|
||||
if (!header.isImmutable())
|
||||
header.setGetIndex(bbuf0.position());
|
||||
if (!buffer.isImmutable())
|
||||
buffer.setGetIndex(bbuf1.position());
|
||||
|
||||
bbuf0.position(0);
|
||||
bbuf1.position(0);
|
||||
bbuf0.limit(bbuf0.capacity());
|
||||
bbuf1.limit(bbuf1.capacity());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return length;
|
||||
return len;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
|
@ -1,334 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2004-2009 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;
|
||||
|
||||
/* ------------------------------------------------------------------------------- */
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class DirectNIOBuffer extends AbstractBuffer implements NIOBuffer
|
||||
{
|
||||
protected final ByteBuffer _buf;
|
||||
private ReadableByteChannel _in;
|
||||
private InputStream _inStream;
|
||||
private WritableByteChannel _out;
|
||||
private OutputStream _outStream;
|
||||
|
||||
public DirectNIOBuffer(int size)
|
||||
{
|
||||
super(READWRITE,NON_VOLATILE);
|
||||
_buf = ByteBuffer.allocateDirect(size);
|
||||
_buf.position(0);
|
||||
_buf.limit(_buf.capacity());
|
||||
}
|
||||
|
||||
public DirectNIOBuffer(ByteBuffer buffer,boolean immutable)
|
||||
{
|
||||
super(immutable?IMMUTABLE:READWRITE,NON_VOLATILE);
|
||||
if (!buffer.isDirect())
|
||||
throw new IllegalArgumentException();
|
||||
_buf = buffer;
|
||||
setGetIndex(buffer.position());
|
||||
setPutIndex(buffer.limit());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param file
|
||||
*/
|
||||
public DirectNIOBuffer(File file) throws IOException
|
||||
{
|
||||
super(READONLY,NON_VOLATILE);
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
FileChannel fc = fis.getChannel();
|
||||
_buf = fc.map(FileChannel.MapMode.READ_ONLY, 0, file.length());
|
||||
setGetIndex(0);
|
||||
setPutIndex((int)file.length());
|
||||
_access=IMMUTABLE;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean isDirect()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public byte[] array()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public int capacity()
|
||||
{
|
||||
return _buf.capacity();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public byte peek(int position)
|
||||
{
|
||||
return _buf.get(position);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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.length());
|
||||
}
|
||||
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.length();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public void writeTo(OutputStream out) throws IOException
|
||||
{
|
||||
if (_out==null || !_out.isOpen() || out!=_outStream)
|
||||
{
|
||||
_out=Channels.newChannel(out);
|
||||
_outStream=out;
|
||||
}
|
||||
|
||||
synchronized (_buf)
|
||||
{
|
||||
try
|
||||
{
|
||||
int loop=0;
|
||||
while(hasContent() && _out.isOpen())
|
||||
{
|
||||
_buf.position(getIndex());
|
||||
_buf.limit(putIndex());
|
||||
int len=_out.write(_buf);
|
||||
if (len<0)
|
||||
break;
|
||||
else if (len>0)
|
||||
{
|
||||
skip(len);
|
||||
loop=0;
|
||||
}
|
||||
else if (loop++>1)
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
_out=null;
|
||||
_outStream=null;
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (_out!=null && !_out.isOpen())
|
||||
{
|
||||
_out=null;
|
||||
_outStream=null;
|
||||
}
|
||||
_buf.position(0);
|
||||
_buf.limit(_buf.capacity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2008-2009 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 class IndirectNIOBuffer extends ByteArrayBuffer implements NIOBuffer
|
||||
{
|
||||
protected final ByteBuffer _buf;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public IndirectNIOBuffer(int size)
|
||||
{
|
||||
super(size,READWRITE,NON_VOLATILE);
|
||||
_buf = ByteBuffer.wrap(_bytes);
|
||||
_buf.position(0);
|
||||
_buf.limit(_buf.capacity());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public IndirectNIOBuffer(ByteBuffer buffer,boolean immutable)
|
||||
{
|
||||
super(buffer.array(),0,0, immutable?IMMUTABLE:READWRITE,NON_VOLATILE);
|
||||
if (buffer.isDirect())
|
||||
throw new IllegalArgumentException();
|
||||
_buf = buffer;
|
||||
_get=buffer.position();
|
||||
_put=buffer.limit();
|
||||
buffer.position(0);
|
||||
buffer.limit(buffer.capacity());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public ByteBuffer getByteBuffer()
|
||||
{
|
||||
return _buf;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean isDirect()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2004-2009 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();
|
||||
}
|
|
@ -19,7 +19,6 @@ import java.nio.channels.SelectionKey;
|
|||
import java.nio.channels.SocketChannel;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.io.Buffer;
|
||||
import org.eclipse.jetty.io.NetworkTrafficListener;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
@ -37,7 +36,7 @@ public class NetworkTrafficSelectChannelEndPoint extends SelectChannelEndPoint
|
|||
}
|
||||
|
||||
@Override
|
||||
public int fill(Buffer buffer) throws IOException
|
||||
public int fill(ByteBuffer buffer) throws IOException
|
||||
{
|
||||
int read = super.fill(buffer);
|
||||
notifyIncoming(buffer, read);
|
||||
|
@ -45,26 +44,27 @@ public class NetworkTrafficSelectChannelEndPoint extends SelectChannelEndPoint
|
|||
}
|
||||
|
||||
@Override
|
||||
public int flush(Buffer buffer) throws IOException
|
||||
public int flush(ByteBuffer buffer) throws IOException
|
||||
{
|
||||
int position = buffer.getIndex();
|
||||
int position = buffer.position();
|
||||
int written = super.flush(buffer);
|
||||
notifyOutgoing(buffer, position, written);
|
||||
return written;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int gatheringFlush(Buffer header, ByteBuffer bbuf0, Buffer buffer, ByteBuffer bbuf1) throws IOException
|
||||
public int flush(ByteBuffer header, ByteBuffer buffer) throws IOException
|
||||
{
|
||||
int headerPosition = header.getIndex();
|
||||
int headerLength = header.length();
|
||||
int bufferPosition = buffer.getIndex();
|
||||
int written = super.gatheringFlush(header, bbuf0, buffer,bbuf1);
|
||||
int headerPosition = header.position();
|
||||
int headerLength = header.remaining();
|
||||
int bufferPosition = buffer.position();
|
||||
int written = super.flush(header, buffer);
|
||||
notifyOutgoing(header, headerPosition, written > headerLength ? headerLength : written);
|
||||
notifyOutgoing(buffer, bufferPosition, written > headerLength ? written - headerLength : 0);
|
||||
return written;
|
||||
}
|
||||
|
||||
|
||||
public void notifyOpened()
|
||||
{
|
||||
if (listeners != null && !listeners.isEmpty())
|
||||
|
@ -83,7 +83,7 @@ public class NetworkTrafficSelectChannelEndPoint extends SelectChannelEndPoint
|
|||
}
|
||||
}
|
||||
|
||||
public void notifyIncoming(Buffer buffer, int read)
|
||||
public void notifyIncoming(ByteBuffer buffer, int read)
|
||||
{
|
||||
if (listeners != null && !listeners.isEmpty() && read > 0)
|
||||
{
|
||||
|
@ -91,7 +91,7 @@ public class NetworkTrafficSelectChannelEndPoint extends SelectChannelEndPoint
|
|||
{
|
||||
try
|
||||
{
|
||||
Buffer view = buffer.asReadOnlyBuffer();
|
||||
ByteBuffer view = buffer.asReadOnlyBuffer();
|
||||
listener.incoming(_socket, view);
|
||||
}
|
||||
catch (Exception x)
|
||||
|
@ -102,7 +102,7 @@ public class NetworkTrafficSelectChannelEndPoint extends SelectChannelEndPoint
|
|||
}
|
||||
}
|
||||
|
||||
public void notifyOutgoing(Buffer buffer, int position, int written)
|
||||
public void notifyOutgoing(ByteBuffer buffer, int position, int written)
|
||||
{
|
||||
if (listeners != null && !listeners.isEmpty() && written > 0)
|
||||
{
|
||||
|
@ -110,9 +110,9 @@ public class NetworkTrafficSelectChannelEndPoint extends SelectChannelEndPoint
|
|||
{
|
||||
try
|
||||
{
|
||||
Buffer view = buffer.asReadOnlyBuffer();
|
||||
view.setGetIndex(position);
|
||||
view.setPutIndex(position + written);
|
||||
ByteBuffer view = buffer.slice();
|
||||
view.position(position);
|
||||
view.limit(position + written);
|
||||
listener.outgoing(_socket, view);
|
||||
}
|
||||
catch (Exception x)
|
||||
|
|
|
@ -1,190 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2008-2009 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.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
|
||||
import org.eclipse.jetty.io.AbstractBuffer;
|
||||
import org.eclipse.jetty.io.Buffer;
|
||||
|
||||
public class RandomAccessFileBuffer extends AbstractBuffer implements Buffer
|
||||
{
|
||||
final RandomAccessFile _file;
|
||||
final FileChannel _channel;
|
||||
final int _capacity;
|
||||
|
||||
public RandomAccessFileBuffer(File file)
|
||||
throws FileNotFoundException
|
||||
{
|
||||
super(READWRITE,true);
|
||||
assert file.length()<=Integer.MAX_VALUE;
|
||||
_file = new RandomAccessFile(file,"rw");
|
||||
_channel=_file.getChannel();
|
||||
_capacity=Integer.MAX_VALUE;
|
||||
setGetIndex(0);
|
||||
setPutIndex((int)file.length());
|
||||
}
|
||||
|
||||
public RandomAccessFileBuffer(File file,int capacity)
|
||||
throws FileNotFoundException
|
||||
{
|
||||
super(READWRITE,true);
|
||||
assert capacity>=file.length();
|
||||
assert file.length()<=Integer.MAX_VALUE;
|
||||
_capacity=capacity;
|
||||
_file = new RandomAccessFile(file,"rw");
|
||||
_channel=_file.getChannel();
|
||||
setGetIndex(0);
|
||||
setPutIndex((int)file.length());
|
||||
}
|
||||
|
||||
public RandomAccessFileBuffer(File file,int capacity,int access)
|
||||
throws FileNotFoundException
|
||||
{
|
||||
super(access,true);
|
||||
assert capacity>=file.length();
|
||||
assert file.length()<=Integer.MAX_VALUE;
|
||||
_capacity=capacity;
|
||||
_file = new RandomAccessFile(file,access==READWRITE?"rw":"r");
|
||||
_channel=_file.getChannel();
|
||||
setGetIndex(0);
|
||||
setPutIndex((int)file.length());
|
||||
}
|
||||
|
||||
public byte[] array()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public int capacity()
|
||||
{
|
||||
return _capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
try
|
||||
{
|
||||
synchronized (_file)
|
||||
{
|
||||
super.clear();
|
||||
_file.setLength(0);
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public byte peek()
|
||||
{
|
||||
synchronized (_file)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_get!=_file.getFilePointer())
|
||||
_file.seek(_get);
|
||||
return _file.readByte();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public byte peek(int index)
|
||||
{
|
||||
synchronized (_file)
|
||||
{
|
||||
try
|
||||
{
|
||||
_file.seek(index);
|
||||
return _file.readByte();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int peek(int index, byte[] b, int offset, int length)
|
||||
{
|
||||
synchronized (_file)
|
||||
{
|
||||
try
|
||||
{
|
||||
_file.seek(index);
|
||||
return _file.read(b,offset,length);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void poke(int index, byte b)
|
||||
{
|
||||
synchronized (_file)
|
||||
{
|
||||
try
|
||||
{
|
||||
_file.seek(index);
|
||||
_file.writeByte(b);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int poke(int index, byte[] b, int offset, int length)
|
||||
{
|
||||
synchronized (_file)
|
||||
{
|
||||
try
|
||||
{
|
||||
_file.seek(index);
|
||||
_file.write(b,offset,length);
|
||||
return length;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int writeTo(WritableByteChannel channel,int index, int length)
|
||||
throws IOException
|
||||
{
|
||||
synchronized (_file)
|
||||
{
|
||||
return (int)_channel.transferTo(index,length,channel);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -14,13 +14,13 @@
|
|||
package org.eclipse.jetty.io.nio;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.nio.channels.SelectableChannel;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
||||
import org.eclipse.jetty.io.AsyncEndPoint;
|
||||
import org.eclipse.jetty.io.Buffer;
|
||||
import org.eclipse.jetty.io.ConnectedEndPoint;
|
||||
import org.eclipse.jetty.io.Connection;
|
||||
import org.eclipse.jetty.io.EofException;
|
||||
|
@ -304,7 +304,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
|
|||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public int fill(Buffer buffer) throws IOException
|
||||
public int fill(ByteBuffer buffer) throws IOException
|
||||
{
|
||||
int fill=super.fill(buffer);
|
||||
if (fill>0)
|
||||
|
@ -314,12 +314,12 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
|
|||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException
|
||||
public int flush(ByteBuffer header, ByteBuffer buffer) throws IOException
|
||||
{
|
||||
int l = super.flush(header, buffer, trailer);
|
||||
int l = super.flush(header, buffer);
|
||||
|
||||
// If there was something to write and it wasn't written, then we are not writable.
|
||||
if (l==0 && ( header!=null && header.hasContent() || buffer!=null && buffer.hasContent() || trailer!=null && trailer.hasContent()))
|
||||
if (l==0 && ( header!=null && header.remaining()>0 || buffer!=null && buffer.remaining()>0))
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
|
@ -339,12 +339,12 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
|
|||
/*
|
||||
*/
|
||||
@Override
|
||||
public int flush(Buffer buffer) throws IOException
|
||||
public int flush(ByteBuffer buffer) throws IOException
|
||||
{
|
||||
int l = super.flush(buffer);
|
||||
|
||||
// If there was something to write and it wasn't written, then we are not writable.
|
||||
if (l==0 && buffer!=null && buffer.hasContent())
|
||||
if (l==0 && buffer!=null && buffer.remaining()>0)
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
|
|
|
@ -24,7 +24,7 @@ import javax.net.ssl.SSLSession;
|
|||
|
||||
import org.eclipse.jetty.io.AbstractConnection;
|
||||
import org.eclipse.jetty.io.AsyncEndPoint;
|
||||
import org.eclipse.jetty.io.Buffer;
|
||||
import org.eclipse.jetty.io.BufferUtil;
|
||||
import org.eclipse.jetty.io.Connection;
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
|
@ -44,7 +44,7 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
|
|||
{
|
||||
private final Logger _logger = Log.getLogger("org.eclipse.jetty.io.nio.ssl");
|
||||
|
||||
private static final NIOBuffer __ZERO_BUFFER=new IndirectNIOBuffer(0);
|
||||
private static final ByteBuffer __ZERO_BUFFER=BufferUtil.allocate(0);
|
||||
|
||||
private static final ThreadLocal<SslBuffers> __buffers = new ThreadLocal<SslBuffers>();
|
||||
private final SSLEngine _engine;
|
||||
|
@ -53,9 +53,9 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
|
|||
private final SslEndPoint _sslEndPoint;
|
||||
private int _allocations;
|
||||
private SslBuffers _buffers;
|
||||
private NIOBuffer _inbound;
|
||||
private NIOBuffer _unwrapBuf;
|
||||
private NIOBuffer _outbound;
|
||||
private ByteBuffer _inbound;
|
||||
private ByteBuffer _unwrapBuf;
|
||||
private ByteBuffer _outbound;
|
||||
private AsyncEndPoint _aEndp;
|
||||
private boolean _allowRenegotiate=true;
|
||||
private boolean _handshook;
|
||||
|
@ -68,15 +68,15 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
|
|||
*/
|
||||
private static class SslBuffers
|
||||
{
|
||||
final NIOBuffer _in;
|
||||
final NIOBuffer _out;
|
||||
final NIOBuffer _unwrap;
|
||||
final ByteBuffer _in;
|
||||
final ByteBuffer _out;
|
||||
final ByteBuffer _unwrap;
|
||||
|
||||
SslBuffers(int packetSize, int appSize)
|
||||
{
|
||||
_in=new IndirectNIOBuffer(packetSize);
|
||||
_out=new IndirectNIOBuffer(packetSize);
|
||||
_unwrap=new IndirectNIOBuffer(appSize);
|
||||
_in=BufferUtil.allocate(packetSize);
|
||||
_out=BufferUtil.allocate(packetSize);
|
||||
_unwrap=BufferUtil.allocate(appSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,9 +156,9 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
|
|||
if (--_allocations==0)
|
||||
{
|
||||
if (_buffers!=null &&
|
||||
_inbound.length()==0 &&
|
||||
_outbound.length()==0 &&
|
||||
_unwrapBuf.length()==0)
|
||||
_inbound.remaining()==0 &&
|
||||
_outbound.remaining()==0 &&
|
||||
_unwrapBuf.remaining()==0)
|
||||
{
|
||||
_inbound=null;
|
||||
_outbound=null;
|
||||
|
@ -265,7 +265,7 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
private synchronized boolean process(Buffer toFill, Buffer toFlush) throws IOException
|
||||
private synchronized boolean process(ByteBuffer toFill, ByteBuffer toFlush) throws IOException
|
||||
{
|
||||
boolean some_progress=false;
|
||||
try
|
||||
|
@ -277,7 +277,7 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
|
|||
if (toFill==null)
|
||||
{
|
||||
// use the unwrapbuffer to hold received data.
|
||||
_unwrapBuf.compact();
|
||||
_unwrapBuf.compact().flip();
|
||||
toFill=_unwrapBuf;
|
||||
}
|
||||
// Else if the fill buffer is too small for the SSL session
|
||||
|
@ -287,10 +287,10 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
|
|||
boolean progress=process(null,toFlush);
|
||||
|
||||
// if we received any data,
|
||||
if (_unwrapBuf!=null && _unwrapBuf.hasContent())
|
||||
if (!BufferUtil.isEmpty(_unwrapBuf))
|
||||
{
|
||||
// transfer from temp buffer to fill buffer
|
||||
_unwrapBuf.skip(toFill.put(_unwrapBuf));
|
||||
BufferUtil.put(_unwrapBuf,toFill);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -298,10 +298,10 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
|
|||
return progress;
|
||||
}
|
||||
// Else if there is some temporary data
|
||||
else if (_unwrapBuf!=null && _unwrapBuf.hasContent())
|
||||
else if (!BufferUtil.isEmpty(_unwrapBuf))
|
||||
{
|
||||
// transfer from temp buffer to fill buffer
|
||||
_unwrapBuf.skip(toFill.put(_unwrapBuf));
|
||||
BufferUtil.put(_unwrapBuf,toFill);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -322,11 +322,11 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
|
|||
try
|
||||
{
|
||||
// Read any available data
|
||||
if (_inbound.space()>0 && (filled=_endp.fill(_inbound))>0)
|
||||
if (!BufferUtil.isAtCapacity(_inbound) && (filled=_endp.fill(_inbound))>0)
|
||||
progress = true;
|
||||
|
||||
// flush any output data
|
||||
if (_outbound.hasContent() && (flushed=_endp.flush(_outbound))>0)
|
||||
if (!BufferUtil.isEmpty(_outbound) && (flushed=_endp.flush(_outbound))>0)
|
||||
progress = true;
|
||||
}
|
||||
catch (IOException e)
|
||||
|
@ -336,7 +336,7 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
|
|||
}
|
||||
finally
|
||||
{
|
||||
_logger.debug("{} {} {} filled={}/{} flushed={}/{}",_session,this,_engine.getHandshakeStatus(),filled,_inbound.length(),flushed,_outbound.length());
|
||||
_logger.debug("{} {} {} filled={}/{} flushed={}/{}",_session,this,_engine.getHandshakeStatus(),filled,_inbound.remaining(),flushed,_outbound.remaining());
|
||||
}
|
||||
|
||||
// handle the current hand share status
|
||||
|
@ -348,11 +348,11 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
|
|||
case NOT_HANDSHAKING:
|
||||
{
|
||||
// Try unwrapping some application data
|
||||
if (toFill.space()>0 && _inbound.hasContent() && unwrap(toFill))
|
||||
if (!BufferUtil.isAtCapacity(toFill) && !BufferUtil.isEmpty(_inbound) && unwrap(toFill))
|
||||
progress=true;
|
||||
|
||||
// Try wrapping some application data
|
||||
if (toFlush.hasContent() && _outbound.space()>0 && wrap(toFlush))
|
||||
if (!BufferUtil.isEmpty(toFlush) && !BufferUtil.isAtCapacity(_outbound) && wrap(toFlush))
|
||||
progress=true;
|
||||
}
|
||||
break;
|
||||
|
@ -385,7 +385,7 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
|
|||
// The SSL needs to receive some handshake data from the other side
|
||||
if (_handshook && !_allowRenegotiate)
|
||||
_endp.close();
|
||||
else if (!_inbound.hasContent()&&filled==-1)
|
||||
else if (BufferUtil.isEmpty(_inbound)&&filled==-1)
|
||||
{
|
||||
// No more input coming
|
||||
_endp.shutdownInput();
|
||||
|
@ -397,10 +397,10 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
|
|||
}
|
||||
|
||||
// pass on ishut/oshut state
|
||||
if (_endp.isOpen() && _endp.isInputShutdown() && !_inbound.hasContent())
|
||||
if (_endp.isOpen() && _endp.isInputShutdown() && BufferUtil.isEmpty(_inbound))
|
||||
_engine.closeInbound();
|
||||
|
||||
if (_endp.isOpen() && _engine.isOutboundDone() && !_outbound.hasContent())
|
||||
if (_endp.isOpen() && _engine.isOutboundDone() && BufferUtil.isEmpty(_outbound))
|
||||
_endp.shutdownOutput();
|
||||
|
||||
// remember if any progress has been made
|
||||
|
@ -408,7 +408,7 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
|
|||
}
|
||||
|
||||
// If we are reading into the temp buffer and it has some content, then we should be dispatched.
|
||||
if (toFill==_unwrapBuf && _unwrapBuf.hasContent())
|
||||
if (toFill==_unwrapBuf && !BufferUtil.isEmpty(_unwrapBuf))
|
||||
_aEndp.asyncDispatch();
|
||||
}
|
||||
finally
|
||||
|
@ -420,51 +420,20 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
|
|||
return some_progress;
|
||||
}
|
||||
|
||||
private synchronized boolean wrap(final Buffer buffer) throws IOException
|
||||
private synchronized boolean wrap(final ByteBuffer buffer) throws IOException
|
||||
{
|
||||
ByteBuffer bbuf=extractByteBuffer(buffer);
|
||||
final SSLEngineResult result;
|
||||
|
||||
synchronized(bbuf)
|
||||
{
|
||||
_outbound.compact();
|
||||
ByteBuffer out_buffer=_outbound.getByteBuffer();
|
||||
synchronized(out_buffer)
|
||||
{
|
||||
try
|
||||
{
|
||||
bbuf.position(buffer.getIndex());
|
||||
bbuf.limit(buffer.putIndex());
|
||||
out_buffer.position(_outbound.putIndex());
|
||||
out_buffer.limit(out_buffer.capacity());
|
||||
result=_engine.wrap(bbuf,out_buffer);
|
||||
if (_logger.isDebugEnabled())
|
||||
_logger.debug("{} wrap {} {} consumed={} produced={}",
|
||||
_session,
|
||||
result.getStatus(),
|
||||
result.getHandshakeStatus(),
|
||||
result.bytesConsumed(),
|
||||
result.bytesProduced());
|
||||
|
||||
|
||||
buffer.skip(result.bytesConsumed());
|
||||
_outbound.setPutIndex(_outbound.putIndex()+result.bytesProduced());
|
||||
}
|
||||
catch(SSLException e)
|
||||
{
|
||||
_logger.debug(String.valueOf(_endp), e);
|
||||
_endp.close();
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
out_buffer.position(0);
|
||||
out_buffer.limit(out_buffer.capacity());
|
||||
bbuf.position(0);
|
||||
bbuf.limit(bbuf.capacity());
|
||||
}
|
||||
}
|
||||
}
|
||||
_outbound.compact();
|
||||
result=_engine.wrap(buffer,_outbound);
|
||||
if (_logger.isDebugEnabled())
|
||||
_logger.debug("{} wrap {} {} consumed={} produced={}",
|
||||
_session,
|
||||
result.getStatus(),
|
||||
result.getHandshakeStatus(),
|
||||
result.bytesConsumed(),
|
||||
result.bytesProduced());
|
||||
_outbound.flip();
|
||||
|
||||
switch(result.getStatus())
|
||||
{
|
||||
|
@ -493,53 +462,31 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
|
|||
return result.bytesConsumed()>0 || result.bytesProduced()>0;
|
||||
}
|
||||
|
||||
private synchronized boolean unwrap(final Buffer buffer) throws IOException
|
||||
private synchronized boolean unwrap(final ByteBuffer buffer) throws IOException
|
||||
{
|
||||
if (!_inbound.hasContent())
|
||||
if (BufferUtil.isEmpty(_inbound))
|
||||
return false;
|
||||
|
||||
ByteBuffer bbuf=extractByteBuffer(buffer);
|
||||
final SSLEngineResult result;
|
||||
|
||||
synchronized(bbuf)
|
||||
try
|
||||
{
|
||||
ByteBuffer in_buffer=_inbound.getByteBuffer();
|
||||
synchronized(in_buffer)
|
||||
{
|
||||
try
|
||||
{
|
||||
bbuf.position(buffer.putIndex());
|
||||
bbuf.limit(buffer.capacity());
|
||||
in_buffer.position(_inbound.getIndex());
|
||||
in_buffer.limit(_inbound.putIndex());
|
||||
|
||||
result=_engine.unwrap(in_buffer,bbuf);
|
||||
if (_logger.isDebugEnabled())
|
||||
_logger.debug("{} unwrap {} {} consumed={} produced={}",
|
||||
_session,
|
||||
result.getStatus(),
|
||||
result.getHandshakeStatus(),
|
||||
result.bytesConsumed(),
|
||||
result.bytesProduced());
|
||||
|
||||
_inbound.skip(result.bytesConsumed());
|
||||
_inbound.compact();
|
||||
buffer.setPutIndex(buffer.putIndex()+result.bytesProduced());
|
||||
}
|
||||
catch(SSLException e)
|
||||
{
|
||||
_logger.debug(String.valueOf(_endp), e);
|
||||
_endp.close();
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
in_buffer.position(0);
|
||||
in_buffer.limit(in_buffer.capacity());
|
||||
bbuf.position(0);
|
||||
bbuf.limit(bbuf.capacity());
|
||||
}
|
||||
}
|
||||
buffer.compact();
|
||||
result=_engine.unwrap(_inbound,buffer);
|
||||
if (_logger.isDebugEnabled())
|
||||
_logger.debug("{} unwrap {} {} consumed={} produced={}",
|
||||
_session,
|
||||
result.getStatus(),
|
||||
result.getHandshakeStatus(),
|
||||
result.bytesConsumed(),
|
||||
result.bytesProduced());
|
||||
buffer.flip();
|
||||
}
|
||||
catch(SSLException e)
|
||||
{
|
||||
_logger.debug(String.valueOf(_endp), e);
|
||||
_endp.close();
|
||||
throw e;
|
||||
}
|
||||
|
||||
switch(result.getStatus())
|
||||
|
@ -550,7 +497,7 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
|
|||
break;
|
||||
|
||||
case BUFFER_OVERFLOW:
|
||||
_logger.debug("{} unwrap {} {}->{}",_session,result.getStatus(),_inbound.toDetailString(),buffer.toDetailString());
|
||||
_logger.debug("{} unwrap {} {}->{}",_session,result.getStatus(),_inbound,buffer);
|
||||
break;
|
||||
|
||||
case OK:
|
||||
|
@ -575,15 +522,6 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
|
|||
return result.bytesConsumed()>0 || result.bytesProduced()>0;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
private ByteBuffer extractByteBuffer(Buffer buffer)
|
||||
{
|
||||
if (buffer.buffer() instanceof NIOBuffer)
|
||||
return ((NIOBuffer)buffer.buffer()).getByteBuffer();
|
||||
return ByteBuffer.wrap(buffer.array());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public AsyncEndPoint getSslEndPoint()
|
||||
{
|
||||
|
@ -641,8 +579,8 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
|
|||
synchronized (SslConnection.this)
|
||||
{
|
||||
return _endp.isInputShutdown() &&
|
||||
!(_unwrapBuf!=null&&_unwrapBuf.hasContent()) &&
|
||||
!(_inbound!=null&&_inbound.hasContent());
|
||||
!(_unwrapBuf!=null&&!BufferUtil.isEmpty(_unwrapBuf)) &&
|
||||
!(_inbound!=null&&!BufferUtil.isEmpty(_inbound));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -652,33 +590,31 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
|
|||
_endp.close();
|
||||
}
|
||||
|
||||
public int fill(Buffer buffer) throws IOException
|
||||
public int fill(ByteBuffer buffer) throws IOException
|
||||
{
|
||||
int size=buffer.length();
|
||||
int size=buffer.remaining();
|
||||
process(buffer, null);
|
||||
|
||||
int filled=buffer.length()-size;
|
||||
int filled=buffer.remaining()-size;
|
||||
|
||||
if (filled==0 && isInputShutdown())
|
||||
return -1;
|
||||
return filled;
|
||||
}
|
||||
|
||||
public int flush(Buffer buffer) throws IOException
|
||||
public int flush(ByteBuffer buffer) throws IOException
|
||||
{
|
||||
int size = buffer.length();
|
||||
int size = buffer.remaining();
|
||||
process(null, buffer);
|
||||
return size-buffer.length();
|
||||
return size-buffer.remaining();
|
||||
}
|
||||
|
||||
public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException
|
||||
public int flush(ByteBuffer header, ByteBuffer buffer) throws IOException
|
||||
{
|
||||
if (header!=null && header.hasContent())
|
||||
if (!BufferUtil.isEmpty(header))
|
||||
return flush(header);
|
||||
if (buffer!=null && buffer.hasContent())
|
||||
if (!BufferUtil.isEmpty(buffer))
|
||||
return flush(buffer);
|
||||
if (trailer!=null && trailer.hasContent())
|
||||
return flush(trailer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -823,12 +759,12 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
|
|||
// 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;
|
||||
int i = inbound == null? -1 : inbound.length();
|
||||
int o = outbound == null ? -1 : outbound.length();
|
||||
int u = unwrap == null ? -1 : unwrap.length();
|
||||
ByteBuffer inbound = _inbound;
|
||||
ByteBuffer outbound = _outbound;
|
||||
ByteBuffer unwrap = _unwrapBuf;
|
||||
int i = inbound == null? -1 : inbound.remaining();
|
||||
int o = outbound == null ? -1 : outbound.remaining();
|
||||
int u = unwrap == null ? -1 : unwrap.remaining();
|
||||
return String.format("SSL %s i/o/u=%d/%d/%d ishut=%b oshut=%b {%s}",
|
||||
_engine.getHandshakeStatus(),
|
||||
i, o, u,
|
||||
|
|
|
@ -18,8 +18,11 @@ import static org.junit.Assert.assertNotSame;
|
|||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.eclipse.jetty.io.BufferCache.CachedBuffer;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -44,8 +47,8 @@ public class BufferCacheTest
|
|||
{
|
||||
for (int i=0; i<S.length; i++)
|
||||
{
|
||||
String s="S0S1s2s3";
|
||||
ByteArrayBuffer buf=new ByteArrayBuffer(s.getBytes(),i*2,2);
|
||||
String s="S0S1s2s3s0s1S2S3";
|
||||
ByteBuffer buf=ByteBuffer.wrap(s.getBytes(StringUtil.__ISO_8859_1_CHARSET),i*2,2);
|
||||
BufferCache.CachedBuffer b=cache.get(buf);
|
||||
int index=b==null?-1:b.getOrdinal();
|
||||
|
||||
|
@ -61,12 +64,26 @@ public class BufferCacheTest
|
|||
{
|
||||
for (int i=0; i<S.length; i++)
|
||||
{
|
||||
String s="S0S1s2s3";
|
||||
ByteArrayBuffer buf=new ByteArrayBuffer(s.getBytes(),i*2,2);
|
||||
Buffer b=cache.get(buf);
|
||||
String s="S0S1s2s3s0s1S2S3";
|
||||
ByteBuffer buf=ByteBuffer.wrap(s.getBytes(StringUtil.__ISO_8859_1_CHARSET),i*2,2);
|
||||
ByteBuffer b=cache.getBuffer(buf);
|
||||
|
||||
assertEquals(i,b.get(1)-'0');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGet()
|
||||
{
|
||||
for (int i=0; i<S.length; i++)
|
||||
{
|
||||
String s="S0S1s2s3s0s1S2S3";
|
||||
ByteBuffer buf=ByteBuffer.wrap(s.getBytes(StringUtil.__ISO_8859_1_CHARSET),i*2,2);
|
||||
CachedBuffer b=cache.get(buf);
|
||||
|
||||
if (i>0)
|
||||
assertEquals(i,b.peek(1)-'0');
|
||||
assertEquals(S[i],b.toString());
|
||||
else
|
||||
assertEquals(null,b);
|
||||
}
|
||||
|
@ -77,17 +94,17 @@ public class BufferCacheTest
|
|||
{
|
||||
for (int i=0; i<S.length; i++)
|
||||
{
|
||||
String s="S0S1s2s3";
|
||||
ByteArrayBuffer buf=new ByteArrayBuffer(s.getBytes(),i*2,2);
|
||||
Buffer b=cache.lookup(buf);
|
||||
String s="S0S1s2s3s0s1S2S3";
|
||||
ByteBuffer buf=ByteBuffer.wrap(s.getBytes(StringUtil.__ISO_8859_1_CHARSET),i*2,2);
|
||||
ByteBuffer b=cache.lookup(buf);
|
||||
|
||||
assertEquals(S[i],b.toString());
|
||||
assertEquals(S[i],BufferUtil.toString(b));
|
||||
if (i>0)
|
||||
assertSame(""+i, S[i], b.toString());
|
||||
assertEquals(""+i, S[i], BufferUtil.toString(b));
|
||||
else
|
||||
{
|
||||
assertNotSame(""+i, S[i], b.toString());
|
||||
assertEquals(""+i, S[i], b.toString());
|
||||
assertNotSame(""+i, S[i], BufferUtil.toString(b));
|
||||
assertEquals(""+i, S[i], BufferUtil.toString(b));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -95,39 +112,23 @@ public class BufferCacheTest
|
|||
@Test
|
||||
public void testLookupPartialBuffer()
|
||||
{
|
||||
cache.add("44444",4);
|
||||
String key="44444";
|
||||
cache.add(key,4);
|
||||
|
||||
ByteArrayBuffer buf=new ByteArrayBuffer("44444");
|
||||
Buffer b=cache.lookup(buf);
|
||||
assertEquals("44444",b.toString());
|
||||
ByteBuffer buf=BufferUtil.toBuffer("44444");
|
||||
ByteBuffer b=cache.get(buf).getBuffer();
|
||||
assertEquals("44444",BufferUtil.toString(b));
|
||||
assertEquals(4,cache.getOrdinal(b));
|
||||
|
||||
buf=new ByteArrayBuffer("4444");
|
||||
b=cache.lookup(buf);
|
||||
assertEquals(-1,cache.getOrdinal(b));
|
||||
buf=BufferUtil.toBuffer("4444");
|
||||
assertEquals(null,cache.get(buf));
|
||||
assertSame(buf,cache.getBuffer(buf));
|
||||
assertEquals(-1,cache.getOrdinal(buf));
|
||||
|
||||
buf=new ByteArrayBuffer("44444x");
|
||||
b=cache.lookup(buf);
|
||||
assertEquals(-1,cache.getOrdinal(b));
|
||||
buf=BufferUtil.toBuffer("44444x");
|
||||
assertEquals("44444",cache.get(buf).toString());
|
||||
assertEquals(4,cache.getOrdinal(buf));
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsensitiveLookupBuffer()
|
||||
{
|
||||
for (int i=0; i<S.length; i++)
|
||||
{
|
||||
String s="s0s1S2S3";
|
||||
ByteArrayBuffer buf=new ByteArrayBuffer(s.getBytes(),i*2,2);
|
||||
Buffer b=cache.lookup(buf);
|
||||
|
||||
assertTrue("test"+i,S[i].equalsIgnoreCase(b.toString()));
|
||||
if (i>0)
|
||||
assertSame("test"+i, S[i], b.toString());
|
||||
else
|
||||
assertNotSame("test"+i, S[i], b.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -135,15 +136,15 @@ public class BufferCacheTest
|
|||
{
|
||||
for (int i=0; i<S.length; i++)
|
||||
{
|
||||
String s="S0S1s2s3";
|
||||
ByteArrayBuffer buf=new ByteArrayBuffer(s.getBytes(),i*2,2);
|
||||
String b=cache.toString(buf);
|
||||
String s="S0S1s2s3s0s1S2S3";
|
||||
ByteBuffer buf=ByteBuffer.wrap(s.getBytes(StringUtil.__ISO_8859_1_CHARSET),i*2,2);
|
||||
String str=cache.getString(buf);
|
||||
|
||||
assertEquals(S[i],b);
|
||||
assertEquals(S[i],str);
|
||||
if (i>0)
|
||||
assertSame(S[i], b);
|
||||
assertSame(S[i], str);
|
||||
else
|
||||
assertNotSame(S[i], b);
|
||||
assertNotSame(S[i], str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,260 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2004-2009 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 static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.jetty.io.nio.DirectNIOBuffer;
|
||||
import org.eclipse.jetty.io.nio.IndirectNIOBuffer;
|
||||
import org.eclipse.jetty.io.nio.RandomAccessFileBuffer;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class BufferTest
|
||||
{
|
||||
private Buffer[] buffer;
|
||||
|
||||
@Before
|
||||
public void init() throws Exception
|
||||
{
|
||||
File file = File.createTempFile("test",".buf");
|
||||
file.deleteOnExit();
|
||||
|
||||
buffer=new Buffer[]{
|
||||
new RandomAccessFileBuffer(file,10),
|
||||
new ByteArrayBuffer(10),
|
||||
new IndirectNIOBuffer(10),
|
||||
new DirectNIOBuffer(10)
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuffer() throws Exception
|
||||
{
|
||||
for (int i=0;i<buffer.length;i++)
|
||||
{
|
||||
String t="t"+i;
|
||||
Buffer b = buffer[i];
|
||||
|
||||
assertEquals(t,0,b.length());
|
||||
assertEquals(t,10,b.capacity());
|
||||
assertEquals(t,10,b.space());
|
||||
|
||||
b.put((byte)0);
|
||||
b.put((byte)1);
|
||||
b.put((byte)2);
|
||||
assertEquals(t,3,b.length());
|
||||
assertEquals(t,10,b.capacity());
|
||||
assertEquals(t,7,b.space());
|
||||
|
||||
assertEquals(t,0,b.get());
|
||||
assertEquals(t,1,b.get());
|
||||
assertEquals(t,1,b.length());
|
||||
assertEquals(t,10,b.capacity());
|
||||
assertEquals(t,7,b.space());
|
||||
b.compact();
|
||||
assertEquals(t,9,b.space());
|
||||
|
||||
byte[] ba = { (byte)-1, (byte)3,(byte)4,(byte)5,(byte)6 };
|
||||
|
||||
b.put(ba,1,3);
|
||||
assertEquals(t,4,b.length());
|
||||
assertEquals(t,6,b.space());
|
||||
|
||||
byte[] bg = new byte[4];
|
||||
b.get(bg,1,2);
|
||||
assertEquals(t,2,bg[1]);
|
||||
assertEquals(t,3,bg[2]);
|
||||
|
||||
//test getting 0 bytes returns 0
|
||||
int count = b.get(bg,0,0);
|
||||
assertEquals(t,0, count);
|
||||
|
||||
//read up to end
|
||||
count = b.get(bg,0,2);
|
||||
assertEquals(t, 2, count);
|
||||
|
||||
//test reading past end returns -1
|
||||
count = b.get(bg,0,1);
|
||||
assertEquals(t, -1, count);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHash() throws Exception
|
||||
{
|
||||
Buffer[] b=
|
||||
{
|
||||
new ByteArrayBuffer("Test1234 "),
|
||||
new ByteArrayBuffer("tEST1234 "),
|
||||
new DirectNIOBuffer(4096),
|
||||
};
|
||||
b[2].put("TeSt1234 ".getBytes(StringUtil.__UTF8));
|
||||
|
||||
for (int i=0;i<b.length;i++)
|
||||
assertEquals("t"+i,b[0].hashCode(),b[i].hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGet () throws Exception
|
||||
{
|
||||
Buffer buff = new ByteArrayBuffer(new byte[]{(byte)0,(byte)1,(byte)2,(byte)3,(byte)4,(byte)5});
|
||||
|
||||
byte[] readbuff = new byte[2];
|
||||
|
||||
int count = buff.get(readbuff, 0, 2);
|
||||
assertEquals(2, count);
|
||||
assertEquals(readbuff[0], (byte)0);
|
||||
assertEquals(readbuff[1], (byte)1);
|
||||
|
||||
count = buff.get(readbuff, 0, 2);
|
||||
assertEquals(2, count);
|
||||
assertEquals(readbuff[0], (byte)2);
|
||||
assertEquals(readbuff[1], (byte)3);
|
||||
|
||||
count = buff.get(readbuff, 0, 0);
|
||||
assertEquals(0, count);
|
||||
|
||||
readbuff[0]=(byte)9;
|
||||
readbuff[1]=(byte)9;
|
||||
|
||||
count = buff.get(readbuff, 0, 2);
|
||||
assertEquals(2, count);
|
||||
|
||||
count = buff.get(readbuff, 0, 2);
|
||||
assertEquals(-1, count);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsensitive()
|
||||
{
|
||||
Buffer cs0 = new ByteArrayBuffer("Test 1234");
|
||||
Buffer cs1 = new ByteArrayBuffer("Test 1234");
|
||||
Buffer cs2 = new ByteArrayBuffer("tEst 1234");
|
||||
Buffer cs3 = new ByteArrayBuffer("Other ");
|
||||
Buffer ci0 = new ByteArrayBuffer.CaseInsensitive("Test 1234");
|
||||
Buffer ci1 = new ByteArrayBuffer.CaseInsensitive("Test 1234");
|
||||
Buffer ci2 = new ByteArrayBuffer.CaseInsensitive("tEst 1234");
|
||||
Buffer ci3 = new ByteArrayBuffer.CaseInsensitive("oTher ");
|
||||
|
||||
assertTrue( cs0.equals(cs0));
|
||||
assertTrue( cs0.equals(cs1));
|
||||
assertTrue(!cs0.equals(cs2));
|
||||
assertTrue(!cs0.equals(cs3));
|
||||
assertTrue( cs0.equals(ci0));
|
||||
assertTrue( cs0.equals(ci1));
|
||||
assertTrue( cs0.equals(ci2));
|
||||
assertTrue(!cs0.equals(ci3));
|
||||
|
||||
assertTrue( cs1.equals(cs0));
|
||||
assertTrue( cs1.equals(cs1));
|
||||
assertTrue(!cs1.equals(cs2));
|
||||
assertTrue(!cs1.equals(cs3));
|
||||
assertTrue( cs1.equals(ci0));
|
||||
assertTrue( cs1.equals(ci1));
|
||||
assertTrue( cs1.equals(ci2));
|
||||
assertTrue(!cs1.equals(ci3));
|
||||
|
||||
assertTrue(!cs2.equals(cs0));
|
||||
assertTrue(!cs2.equals(cs1));
|
||||
assertTrue( cs2.equals(cs2));
|
||||
assertTrue(!cs2.equals(cs3));
|
||||
assertTrue( cs2.equals(ci0));
|
||||
assertTrue( cs2.equals(ci1));
|
||||
assertTrue( cs2.equals(ci2));
|
||||
assertTrue(!cs2.equals(ci3));
|
||||
|
||||
assertTrue(!cs3.equals(cs0));
|
||||
assertTrue(!cs3.equals(cs1));
|
||||
assertTrue(!cs3.equals(cs2));
|
||||
assertTrue( cs3.equals(cs3));
|
||||
assertTrue(!cs3.equals(ci0));
|
||||
assertTrue(!cs3.equals(ci1));
|
||||
assertTrue(!cs3.equals(ci2));
|
||||
assertTrue( cs3.equals(ci3));
|
||||
|
||||
|
||||
assertTrue( ci0.equals(cs0));
|
||||
assertTrue( ci0.equals(cs1));
|
||||
assertTrue( ci0.equals(cs2));
|
||||
assertTrue(!ci0.equals(cs3));
|
||||
assertTrue( ci0.equals(ci0));
|
||||
assertTrue( ci0.equals(ci1));
|
||||
assertTrue( ci0.equals(ci2));
|
||||
assertTrue(!ci0.equals(ci3));
|
||||
|
||||
assertTrue( ci1.equals(cs0));
|
||||
assertTrue( ci1.equals(cs1));
|
||||
assertTrue( ci1.equals(cs2));
|
||||
assertTrue(!ci1.equals(cs3));
|
||||
assertTrue( ci1.equals(ci0));
|
||||
assertTrue( ci1.equals(ci1));
|
||||
assertTrue( ci1.equals(ci2));
|
||||
assertTrue(!ci1.equals(ci3));
|
||||
|
||||
assertTrue( ci2.equals(cs0));
|
||||
assertTrue( ci2.equals(cs1));
|
||||
assertTrue( ci2.equals(cs2));
|
||||
assertTrue(!ci2.equals(cs3));
|
||||
assertTrue( ci2.equals(ci0));
|
||||
assertTrue( ci2.equals(ci1));
|
||||
assertTrue( ci2.equals(ci2));
|
||||
assertTrue(!ci2.equals(ci3));
|
||||
|
||||
assertTrue(!ci3.equals(cs0));
|
||||
assertTrue(!ci3.equals(cs1));
|
||||
assertTrue(!ci3.equals(cs2));
|
||||
assertTrue( ci3.equals(cs3));
|
||||
assertTrue(!ci3.equals(ci0));
|
||||
assertTrue(!ci3.equals(ci1));
|
||||
assertTrue(!ci3.equals(ci2));
|
||||
assertTrue( ci3.equals(ci3));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testView()
|
||||
{
|
||||
Buffer b = new ByteArrayBuffer(" Test 1234 ".getBytes());
|
||||
b.setGetIndex(b.getIndex()+1);
|
||||
b.setPutIndex(b.putIndex()-1);
|
||||
View v0 = new View(b);
|
||||
View v1 = new View(b);
|
||||
View v2 = new View(v0);
|
||||
|
||||
String s=b.toString();
|
||||
String s0=v0.toString();
|
||||
String s1=v1.toString();
|
||||
String s2=v2.toString();
|
||||
String s3=v0.toString();
|
||||
String s4=v1.toString();
|
||||
String s5=v2.toString();
|
||||
|
||||
assertEquals(s, s0);
|
||||
assertEquals(s0, s1);
|
||||
assertEquals(s1, s2);
|
||||
assertEquals(s2, s3);
|
||||
assertEquals(s3, s4);
|
||||
assertEquals(s4, s5);
|
||||
|
||||
}
|
||||
}
|
|
@ -16,6 +16,8 @@ package org.eclipse.jetty.io;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -26,15 +28,15 @@ public class BufferUtilTest
|
|||
@Test
|
||||
public void testToInt() throws Exception
|
||||
{
|
||||
Buffer buf[] =
|
||||
ByteBuffer buf[] =
|
||||
{
|
||||
new ByteArrayBuffer("0"),
|
||||
new ByteArrayBuffer(" 42 "),
|
||||
new ByteArrayBuffer(" 43abc"),
|
||||
new ByteArrayBuffer("-44"),
|
||||
new ByteArrayBuffer(" - 45;"),
|
||||
new ByteArrayBuffer("-2147483648"),
|
||||
new ByteArrayBuffer("2147483647"),
|
||||
BufferUtil.toBuffer("0"),
|
||||
BufferUtil.toBuffer(" 42 "),
|
||||
BufferUtil.toBuffer(" 43abc"),
|
||||
BufferUtil.toBuffer("-44"),
|
||||
BufferUtil.toBuffer(" - 45;"),
|
||||
BufferUtil.toBuffer("-2147483648"),
|
||||
BufferUtil.toBuffer("2147483647"),
|
||||
};
|
||||
|
||||
int val[] =
|
||||
|
@ -59,13 +61,14 @@ public class BufferUtilTest
|
|||
"0","42","43","-44","-45",""+Integer.MIN_VALUE,""+Integer.MAX_VALUE
|
||||
};
|
||||
|
||||
Buffer buffer = new ByteArrayBuffer(12);
|
||||
ByteBuffer buffer = ByteBuffer.allocate(24);
|
||||
|
||||
for (int i=0;i<val.length;i++)
|
||||
{
|
||||
buffer.clear();
|
||||
BufferUtil.putDecInt(buffer,val[i]);
|
||||
assertEquals("t"+i,str[i],BufferUtil.to8859_1_String(buffer));
|
||||
buffer.flip();
|
||||
assertEquals("t"+i,str[i],BufferUtil.toString(buffer));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,13 +85,14 @@ public class BufferUtilTest
|
|||
"0","42","43","-44","-45",""+Long.MIN_VALUE,""+Long.MAX_VALUE
|
||||
};
|
||||
|
||||
Buffer buffer = new ByteArrayBuffer(50);
|
||||
ByteBuffer buffer = ByteBuffer.allocate(50);
|
||||
|
||||
for (int i=0;i<val.length;i++)
|
||||
{
|
||||
buffer.clear();
|
||||
BufferUtil.putDecLong(buffer,val[i]);
|
||||
assertEquals("t"+i,str[i],BufferUtil.to8859_1_String(buffer));
|
||||
buffer.flip();
|
||||
assertEquals("t"+i,str[i],BufferUtil.toString(buffer));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,13 +109,14 @@ public class BufferUtilTest
|
|||
"0","2A","2B","-2C","-2D","-80000000","7FFFFFFF"
|
||||
};
|
||||
|
||||
Buffer buffer = new ByteArrayBuffer(12);
|
||||
ByteBuffer buffer = ByteBuffer.allocate(50);
|
||||
|
||||
for (int i=0;i<val.length;i++)
|
||||
{
|
||||
buffer.clear();
|
||||
BufferUtil.putHexInt(buffer,val[i]);
|
||||
assertEquals("t"+i,str[i],BufferUtil.to8859_1_String(buffer));
|
||||
buffer.flip();
|
||||
assertEquals("t"+i,str[i],BufferUtil.toString(buffer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,8 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.eclipse.jetty.io.nio.IndirectNIOBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public abstract class EndPointTest<T extends EndPoint>
|
||||
|
@ -22,15 +23,15 @@ public abstract class EndPointTest<T extends EndPoint>
|
|||
public void testClientServerExchange() throws Exception
|
||||
{
|
||||
EndPointPair<T> c = newConnection();
|
||||
Buffer buffer = new IndirectNIOBuffer(4096);
|
||||
ByteBuffer buffer = BufferUtil.allocate(4096);
|
||||
|
||||
// Client sends a request
|
||||
c.client.flush(new ByteArrayBuffer("request"));
|
||||
c.client.flush(BufferUtil.toBuffer("request"));
|
||||
|
||||
// Server receives the request
|
||||
int len = c.server.fill(buffer);
|
||||
assertEquals(7,len);
|
||||
assertEquals("request",buffer.toString());
|
||||
assertEquals("request",BufferUtil.toString(buffer));
|
||||
|
||||
// Client and server are open
|
||||
assertTrue(c.client.isOpen());
|
||||
|
@ -41,7 +42,7 @@ public abstract class EndPointTest<T extends EndPoint>
|
|||
assertFalse(c.server.isOutputShutdown());
|
||||
|
||||
// Server sends response and closes output
|
||||
c.server.flush(new ByteArrayBuffer("response"));
|
||||
c.server.flush(BufferUtil.toBuffer("response"));
|
||||
c.server.shutdownOutput();
|
||||
|
||||
// client server are open, server is oshut
|
||||
|
@ -53,10 +54,10 @@ public abstract class EndPointTest<T extends EndPoint>
|
|||
assertTrue(c.server.isOutputShutdown());
|
||||
|
||||
// Client reads response
|
||||
buffer.clear();
|
||||
BufferUtil.clear(buffer);
|
||||
len = c.client.fill(buffer);
|
||||
assertEquals(8,len);
|
||||
assertEquals("response",buffer.toString());
|
||||
assertEquals("response",BufferUtil.toString(buffer));
|
||||
|
||||
// Client and server are open, server is oshut
|
||||
assertTrue(c.client.isOpen());
|
||||
|
@ -67,7 +68,7 @@ public abstract class EndPointTest<T extends EndPoint>
|
|||
assertTrue(c.server.isOutputShutdown());
|
||||
|
||||
// Client reads -1
|
||||
buffer.clear();
|
||||
BufferUtil.clear(buffer);
|
||||
len = c.client.fill(buffer);
|
||||
assertEquals(-1,len);
|
||||
|
||||
|
@ -91,7 +92,7 @@ public abstract class EndPointTest<T extends EndPoint>
|
|||
assertTrue(c.server.isOutputShutdown());
|
||||
|
||||
// Server reads close
|
||||
buffer.clear();
|
||||
BufferUtil.clear(buffer);
|
||||
len = c.server.fill(buffer);
|
||||
assertEquals(-1,len);
|
||||
|
||||
|
@ -111,12 +112,12 @@ public abstract class EndPointTest<T extends EndPoint>
|
|||
public void testClientClose() throws Exception
|
||||
{
|
||||
EndPointPair<T> c = newConnection();
|
||||
Buffer buffer = new IndirectNIOBuffer(4096);
|
||||
ByteBuffer buffer = BufferUtil.allocate(4096);
|
||||
|
||||
c.client.flush(new ByteArrayBuffer("request"));
|
||||
c.client.flush(BufferUtil.toBuffer("request"));
|
||||
int len = c.server.fill(buffer);
|
||||
assertEquals(7,len);
|
||||
assertEquals("request",buffer.toString());
|
||||
assertEquals("request",BufferUtil.toString(buffer));
|
||||
|
||||
assertTrue(c.client.isOpen());
|
||||
assertFalse(c.client.isInputShutdown());
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.eclipse.jetty.io;
|
|||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
@ -87,11 +88,11 @@ public class ThreadLocalBuffersTest
|
|||
{
|
||||
InnerBuffers buffers = new InnerBuffers(128,256);
|
||||
|
||||
Buffer h1 = buffers.getHeader();
|
||||
Buffer h2 = buffers.getHeader();
|
||||
Buffer b1 = buffers.getBuffer();
|
||||
Buffer b2 = buffers.getBuffer();
|
||||
Buffer b3 = buffers.getBuffer(512);
|
||||
ByteBuffer h1 = buffers.getHeader();
|
||||
ByteBuffer h2 = buffers.getHeader();
|
||||
ByteBuffer b1 = buffers.getBuffer();
|
||||
ByteBuffer b2 = buffers.getBuffer();
|
||||
ByteBuffer b3 = buffers.getBuffer(512);
|
||||
|
||||
buffers.returnBuffer(h1);
|
||||
buffers.returnBuffer(h2);
|
||||
|
@ -134,12 +135,12 @@ public class ThreadLocalBuffersTest
|
|||
{
|
||||
InnerBuffers buffers = new InnerBuffers(128,128);
|
||||
|
||||
Buffer h1 = buffers.getHeader();
|
||||
Buffer h2 = buffers.getHeader();
|
||||
Buffer b1 = buffers.getBuffer();
|
||||
Buffer b2 = buffers.getBuffer();
|
||||
Buffer b3 = buffers.getBuffer(128);
|
||||
List<Buffer> known = new ArrayList<Buffer>();
|
||||
ByteBuffer h1 = buffers.getHeader();
|
||||
ByteBuffer h2 = buffers.getHeader();
|
||||
ByteBuffer b1 = buffers.getBuffer();
|
||||
ByteBuffer b2 = buffers.getBuffer();
|
||||
ByteBuffer b3 = buffers.getBuffer(128);
|
||||
List<ByteBuffer> known = new ArrayList<ByteBuffer>();
|
||||
known.add(h1);
|
||||
known.add(h2);
|
||||
known.add(b1);
|
||||
|
@ -153,29 +154,24 @@ public class ThreadLocalBuffersTest
|
|||
buffers.returnBuffer(b3); // other slot *
|
||||
|
||||
assertTrue(h1==buffers.getHeader()); // pooled header
|
||||
Buffer buffer = buffers.getHeader();
|
||||
for (Buffer b:known) assertTrue(b!=buffer); // new buffer
|
||||
assertTrue(b3==buffers.getHeader()); // pooled other
|
||||
ByteBuffer buffer = buffers.getHeader();
|
||||
for (ByteBuffer b:known) assertTrue(b!=buffer); // new buffer
|
||||
|
||||
assertTrue(b1==buffers.getBuffer()); // b1 used from buffer slot
|
||||
buffer = buffers.getBuffer();
|
||||
for (Buffer b:known) assertTrue(b!=buffer); // new buffer
|
||||
|
||||
assertTrue(b3==buffers.getBuffer(128)); // b3 from other slot
|
||||
for (ByteBuffer b:known) assertTrue(b!=buffer); // new buffer
|
||||
|
||||
buffer = buffers.getBuffer(128);
|
||||
for (ByteBuffer b:known) assertTrue(b!=buffer); // new buffer
|
||||
}
|
||||
|
||||
private static class HeaderBuffer extends ByteArrayBuffer
|
||||
{
|
||||
public HeaderBuffer(int size)
|
||||
{
|
||||
super(size);
|
||||
}
|
||||
}
|
||||
|
||||
private static class InnerBuffers extends ThreadLocalBuffers
|
||||
{
|
||||
InnerBuffers(int headerSize,int bufferSize)
|
||||
{
|
||||
super(Type.DIRECT,headerSize,Type.BYTE_ARRAY,bufferSize,Type.INDIRECT);
|
||||
super(Type.INDIRECT,headerSize,Type.DIRECT,bufferSize,Type.INDIRECT);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -198,10 +194,10 @@ public class ThreadLocalBuffersTest
|
|||
{
|
||||
if ( runTest )
|
||||
{
|
||||
Buffer buf = httpBuffers.getHeader();
|
||||
ByteBuffer buf = httpBuffers.getHeader();
|
||||
buffersRetrieved.getAndIncrement();
|
||||
|
||||
buf.put(new Byte("2"));
|
||||
buf.compact().put(new Byte("2")).flip();
|
||||
|
||||
// sleep( threadWaitTime );
|
||||
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
package org.eclipse.jetty.io.bio;
|
||||
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
|
||||
import org.eclipse.jetty.io.EndPointTest;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public class SocketEndPointTest extends EndPointTest<SocketEndPoint>
|
||||
{
|
||||
static ServerSocket connector;
|
||||
|
||||
@BeforeClass
|
||||
public static void open() throws Exception
|
||||
{
|
||||
connector = new ServerSocket();
|
||||
connector.bind(null);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void close() throws Exception
|
||||
{
|
||||
connector.close();
|
||||
connector=null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EndPointPair<SocketEndPoint> newConnection() throws Exception
|
||||
{
|
||||
EndPointPair<SocketEndPoint> c = new EndPointPair<SocketEndPoint>();
|
||||
c.client=new SocketEndPoint(new Socket(connector.getInetAddress(),connector.getLocalPort()));
|
||||
c.server=new SocketEndPoint(connector.accept());
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -13,6 +13,7 @@ import java.io.InputStream;
|
|||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
@ -21,6 +22,7 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import org.eclipse.jetty.io.AbstractConnection;
|
||||
import org.eclipse.jetty.io.AsyncEndPoint;
|
||||
import org.eclipse.jetty.io.BufferUtil;
|
||||
import org.eclipse.jetty.io.ConnectedEndPoint;
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
|
@ -105,8 +107,8 @@ public class SelectChannelEndPointTest
|
|||
|
||||
public class TestConnection extends AbstractConnection implements AsyncConnection
|
||||
{
|
||||
NIOBuffer _in = new IndirectNIOBuffer(32*1024);
|
||||
NIOBuffer _out = new IndirectNIOBuffer(32*1024);
|
||||
ByteBuffer _in = BufferUtil.allocate(32*1024);
|
||||
ByteBuffer _out = BufferUtil.allocate(32*1024);
|
||||
|
||||
public TestConnection(EndPoint endp)
|
||||
{
|
||||
|
@ -119,26 +121,29 @@ public class SelectChannelEndPointTest
|
|||
while(progress)
|
||||
{
|
||||
progress=false;
|
||||
_in.compact();
|
||||
if (_in.space()>0 && _endp.fill(_in)>0)
|
||||
_in.compact().flip();
|
||||
if (!BufferUtil.isAtCapacity(_in) && _endp.fill(_in)>0)
|
||||
{
|
||||
progress=true;
|
||||
}
|
||||
|
||||
while (_blockAt>0 && _in.length()>0 && _in.length()<_blockAt)
|
||||
|
||||
while (_blockAt>0 && _in.remaining()>0 && _in.remaining()<_blockAt)
|
||||
{
|
||||
_endp.blockReadable(10000);
|
||||
if (_in.space()>0 && _endp.fill(_in)>0)
|
||||
if (!BufferUtil.isAtCapacity(_in) && _endp.fill(_in)>0)
|
||||
progress=true;
|
||||
}
|
||||
|
||||
if (_in.hasContent() && _in.skip(_out.put(_in))>0)
|
||||
if (!BufferUtil.isEmpty(_in) && BufferUtil.put(_in,_out)>0)
|
||||
progress=true;
|
||||
|
||||
if (_out.hasContent() && _endp.flush(_out)>0)
|
||||
if (!BufferUtil.isEmpty(_out) && _endp.flush(_out)>0)
|
||||
progress=true;
|
||||
|
||||
_out.compact();
|
||||
_out.compact().flip();
|
||||
|
||||
if (!_out.hasContent() && _endp.isInputShutdown())
|
||||
if (!!BufferUtil.isEmpty(_out) && _endp.isInputShutdown())
|
||||
_endp.shutdownOutput();
|
||||
}
|
||||
return this;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-jaspi</artifactId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-jmx</artifactId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-jndi</artifactId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-jsp</artifactId>
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-monitor</artifactId>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>jetty-nested</artifactId>
|
||||
<name>Jetty :: Nested</name>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-nosql</artifactId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty.osgi</groupId>
|
||||
<artifactId>jetty-osgi-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty.osgi</groupId>
|
||||
<artifactId>jetty-osgi-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty.osgi</groupId>
|
||||
<artifactId>jetty-osgi-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty.osgi</groupId>
|
||||
<artifactId>jetty-osgi-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<groupId>org.eclipse.jetty.osgi</groupId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty.osgi</groupId>
|
||||
<artifactId>jetty-osgi-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-overlay-deployer</artifactId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-plus</artifactId>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>jetty-policy</artifactId>
|
||||
<name>Jetty :: Policy Tool</name>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-rewrite</artifactId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-security</artifactId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<parent>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-servlet</artifactId>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<parent>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-servlets</artifactId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-start</artifactId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-util</artifactId>
|
||||
|
|
|
@ -18,6 +18,10 @@ import java.text.SimpleDateFormat;
|
|||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Date Format Cache.
|
||||
|
@ -34,34 +38,37 @@ import java.util.TimeZone;
|
|||
* If consecutive calls are frequently very different, then this
|
||||
* may be a little slower than a normal DateFormat.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class DateCache
|
||||
{
|
||||
public static String DEFAULT_FORMAT="EEE MMM dd HH:mm:ss zzz yyyy";
|
||||
private static long __hitWindow=60*60;
|
||||
|
||||
private String _formatString;
|
||||
private String _tzFormatString;
|
||||
private SimpleDateFormat _tzFormat;
|
||||
|
||||
private String _minFormatString;
|
||||
private SimpleDateFormat _minFormat;
|
||||
|
||||
private String _secFormatString;
|
||||
private String _secFormatString0;
|
||||
private String _secFormatString1;
|
||||
|
||||
private long _lastMinutes = -1;
|
||||
private long _lastSeconds = -1;
|
||||
private int _lastMs = -1;
|
||||
private String _lastResult = null;
|
||||
private volatile Tick _tick;
|
||||
|
||||
private Locale _locale = null;
|
||||
private DateFormatSymbols _dfs = null;
|
||||
|
||||
private static Timer __timer;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------ */
|
||||
private static class Tick
|
||||
{
|
||||
final long _seconds;
|
||||
final String _string;
|
||||
public Tick(long seconds, String string)
|
||||
{
|
||||
_seconds = seconds;
|
||||
_string = string;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Constructor.
|
||||
* Make a DateCache that will use a default format. The default format
|
||||
|
@ -70,7 +77,6 @@ public class DateCache
|
|||
public DateCache()
|
||||
{
|
||||
this(DEFAULT_FORMAT);
|
||||
getFormat().setTimeZone(TimeZone.getDefault());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -82,12 +88,29 @@ public class DateCache
|
|||
_formatString=format;
|
||||
setTimeZone(TimeZone.getDefault());
|
||||
|
||||
synchronized (DateCache.class)
|
||||
{
|
||||
if (__timer==null)
|
||||
__timer=new Timer("DateCache@"+Integer.toHexString(hashCode()),true);
|
||||
|
||||
Date start = new Date((2+(System.currentTimeMillis()/1000))*1000);
|
||||
__timer.scheduleAtFixedRate(new TimerTask()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
formatNow();
|
||||
}
|
||||
},
|
||||
start,
|
||||
1000);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public DateCache(String format,Locale l)
|
||||
{
|
||||
_formatString=format;
|
||||
this(format);
|
||||
_locale = l;
|
||||
setTimeZone(TimeZone.getDefault());
|
||||
}
|
||||
|
@ -95,7 +118,7 @@ public class DateCache
|
|||
/* ------------------------------------------------------------ */
|
||||
public DateCache(String format,DateFormatSymbols s)
|
||||
{
|
||||
_formatString=format;
|
||||
this(format);
|
||||
_dfs = s;
|
||||
setTimeZone(TimeZone.getDefault());
|
||||
}
|
||||
|
@ -104,28 +127,23 @@ public class DateCache
|
|||
/** Set the timezone.
|
||||
* @param tz TimeZone
|
||||
*/
|
||||
public synchronized void setTimeZone(TimeZone tz)
|
||||
public void setTimeZone(TimeZone tz)
|
||||
{
|
||||
setTzFormatString(tz);
|
||||
if( _locale != null )
|
||||
{
|
||||
_tzFormat=new SimpleDateFormat(_tzFormatString,_locale);
|
||||
_minFormat=new SimpleDateFormat(_minFormatString,_locale);
|
||||
}
|
||||
else if( _dfs != null )
|
||||
{
|
||||
_tzFormat=new SimpleDateFormat(_tzFormatString,_dfs);
|
||||
_minFormat=new SimpleDateFormat(_minFormatString,_dfs);
|
||||
}
|
||||
else
|
||||
{
|
||||
_tzFormat=new SimpleDateFormat(_tzFormatString);
|
||||
_minFormat=new SimpleDateFormat(_minFormatString);
|
||||
}
|
||||
_tzFormat.setTimeZone(tz);
|
||||
_minFormat.setTimeZone(tz);
|
||||
_lastSeconds=-1;
|
||||
_lastMinutes=-1;
|
||||
_tick=null;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -145,7 +163,7 @@ public class DateCache
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
private synchronized void setTzFormatString(final TimeZone tz )
|
||||
private void setTzFormatString(final TimeZone tz )
|
||||
{
|
||||
int zIndex = _formatString.indexOf( "ZZZ" );
|
||||
if( zIndex >= 0 )
|
||||
|
@ -182,24 +200,32 @@ public class DateCache
|
|||
}
|
||||
else
|
||||
_tzFormatString=_formatString;
|
||||
setMinFormatString();
|
||||
_tick=null;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
private void setMinFormatString()
|
||||
/** Format a date according to our stored formatter.
|
||||
* @param inDate
|
||||
* @return Formatted date
|
||||
*/
|
||||
public String format(Date inDate)
|
||||
{
|
||||
int i = _tzFormatString.indexOf("ss.SSS");
|
||||
int l = 6;
|
||||
if (i>=0)
|
||||
throw new IllegalStateException("ms not supported");
|
||||
i = _tzFormatString.indexOf("ss");
|
||||
l=2;
|
||||
long seconds = inDate.getTime() / 1000;
|
||||
|
||||
// Build a formatter that formats a second format string
|
||||
String ss1=_tzFormatString.substring(0,i);
|
||||
String ss2=_tzFormatString.substring(i+l);
|
||||
_minFormatString =ss1+"'ss'"+ss2;
|
||||
Tick tick=_tick;
|
||||
|
||||
// Is this the cached time
|
||||
if (tick==null || seconds!=tick._seconds)
|
||||
{
|
||||
// It's a cache miss
|
||||
synchronized (this)
|
||||
{
|
||||
return _tzFormat.format(inDate);
|
||||
}
|
||||
}
|
||||
|
||||
return tick._string;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -207,63 +233,38 @@ public class DateCache
|
|||
* @param inDate
|
||||
* @return Formatted date
|
||||
*/
|
||||
public synchronized String format(Date inDate)
|
||||
{
|
||||
return format(inDate.getTime());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Format a date according to our stored formatter.
|
||||
* @param inDate
|
||||
* @return Formatted date
|
||||
*/
|
||||
public synchronized String format(long inDate)
|
||||
public String format(long inDate)
|
||||
{
|
||||
long seconds = inDate / 1000;
|
||||
|
||||
// Is it not suitable to cache?
|
||||
if (seconds<_lastSeconds ||
|
||||
_lastSeconds>0 && seconds>_lastSeconds+__hitWindow)
|
||||
Tick tick=_tick;
|
||||
|
||||
// Is this the cached time
|
||||
if (tick==null || seconds!=tick._seconds)
|
||||
{
|
||||
// It's a cache miss
|
||||
Date d = new Date(inDate);
|
||||
return _tzFormat.format(d);
|
||||
|
||||
synchronized (this)
|
||||
{
|
||||
return _tzFormat.format(d);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we are in the same second
|
||||
// and don't care about millis
|
||||
if (_lastSeconds==seconds )
|
||||
return _lastResult;
|
||||
return tick._string;
|
||||
}
|
||||
|
||||
Date d = new Date(inDate);
|
||||
|
||||
// Check if we need a new format string
|
||||
long minutes = seconds/60;
|
||||
if (_lastMinutes != minutes)
|
||||
/* ------------------------------------------------------------ */
|
||||
private void formatNow()
|
||||
{
|
||||
long now = System.currentTimeMillis();
|
||||
long seconds = now / 1000;
|
||||
|
||||
synchronized (this)
|
||||
{
|
||||
_lastMinutes = minutes;
|
||||
_secFormatString=_minFormat.format(d);
|
||||
|
||||
int i=_secFormatString.indexOf("ss");
|
||||
int l=2;
|
||||
_secFormatString0=_secFormatString.substring(0,i);
|
||||
_secFormatString1=_secFormatString.substring(i+l);
|
||||
String s= _tzFormat.format(new Date(now));
|
||||
_tick=new Tick(seconds,s);
|
||||
}
|
||||
|
||||
// Always format if we get here
|
||||
_lastSeconds = seconds;
|
||||
StringBuilder sb=new StringBuilder(_secFormatString.length());
|
||||
sb.append(_secFormatString0);
|
||||
int s=(int)(seconds%60);
|
||||
if (s<10)
|
||||
sb.append('0');
|
||||
sb.append(s);
|
||||
sb.append(_secFormatString1);
|
||||
_lastResult=sb.toString();
|
||||
|
||||
|
||||
return _lastResult;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -276,31 +277,10 @@ public class DateCache
|
|||
buffer.append(format(inDate));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Get the format.
|
||||
*/
|
||||
public SimpleDateFormat getFormat()
|
||||
{
|
||||
return _minFormat;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public String getFormatString()
|
||||
{
|
||||
return _formatString;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public String now()
|
||||
{
|
||||
long now=System.currentTimeMillis();
|
||||
_lastMs=(int)(now%1000);
|
||||
return format(now);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public int lastMs()
|
||||
{
|
||||
return _lastMs;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
package org.eclipse.jetty.util;
|
||||
|
||||
import java.io.Externalizable;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
@ -33,19 +34,19 @@ import java.util.Set;
|
|||
*
|
||||
* This map is NOT synchronized.
|
||||
*/
|
||||
public class StringMap extends AbstractMap implements Externalizable
|
||||
public class StringMap<O> extends AbstractMap<String,O> implements Externalizable
|
||||
{
|
||||
public static final boolean CASE_INSENSTIVE=true;
|
||||
protected static final int __HASH_WIDTH=17;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected int _width=__HASH_WIDTH;
|
||||
protected Node _root=new Node();
|
||||
protected Node<O> _root=new Node<>();
|
||||
protected boolean _ignoreCase=false;
|
||||
protected NullEntry _nullEntry=null;
|
||||
protected Object _nullValue=null;
|
||||
protected HashSet _entrySet=new HashSet(3);
|
||||
protected Set _umEntrySet=Collections.unmodifiableSet(_entrySet);
|
||||
protected O _nullValue=null;
|
||||
protected HashSet<Map.Entry<String,O>> _entrySet=new HashSet<>(3);
|
||||
protected Set<Map.Entry<String,O>> _umEntrySet=Collections.unmodifiableSet(_entrySet);
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Constructor.
|
||||
|
@ -111,19 +112,11 @@ public class StringMap extends AbstractMap implements Externalizable
|
|||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public Object put(Object key, Object value)
|
||||
{
|
||||
if (key==null)
|
||||
return put(null,value);
|
||||
return put(key.toString(),value);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public Object put(String key, Object value)
|
||||
public O put(String key, O value)
|
||||
{
|
||||
if (key==null)
|
||||
{
|
||||
Object oldValue=_nullValue;
|
||||
O oldValue=_nullValue;
|
||||
_nullValue=value;
|
||||
if (_nullEntry==null)
|
||||
{
|
||||
|
@ -133,10 +126,10 @@ public class StringMap extends AbstractMap implements Externalizable
|
|||
return oldValue;
|
||||
}
|
||||
|
||||
Node node = _root;
|
||||
Node<O> node = _root;
|
||||
int ni=-1;
|
||||
Node prev = null;
|
||||
Node parent = null;
|
||||
Node<O> prev = null;
|
||||
Node<O> parent = null;
|
||||
|
||||
// look for best match
|
||||
charLoop:
|
||||
|
@ -185,7 +178,7 @@ public class StringMap extends AbstractMap implements Externalizable
|
|||
}
|
||||
|
||||
// We have run out of nodes, so as this is a put, make one
|
||||
node = new Node(_ignoreCase,key,i);
|
||||
node = new Node<O>(_ignoreCase,key,i);
|
||||
|
||||
if (prev!=null) // add to end of chain
|
||||
prev._next=node;
|
||||
|
@ -201,7 +194,7 @@ public class StringMap extends AbstractMap implements Externalizable
|
|||
parent._children[oi]=node;
|
||||
else
|
||||
{
|
||||
Node n=parent._children[oi];
|
||||
Node<O> n=parent._children[oi];
|
||||
while(n._next!=null)
|
||||
n=n._next;
|
||||
n._next=node;
|
||||
|
@ -220,7 +213,7 @@ public class StringMap extends AbstractMap implements Externalizable
|
|||
if(ni>0)
|
||||
node.split(this,ni);
|
||||
|
||||
Object old = node._value;
|
||||
O old = node._value;
|
||||
node._key=key;
|
||||
node._value=value;
|
||||
_entrySet.add(node);
|
||||
|
@ -231,22 +224,20 @@ public class StringMap extends AbstractMap implements Externalizable
|
|||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public Object get(Object key)
|
||||
public O get(Object key)
|
||||
{
|
||||
if (key==null)
|
||||
return _nullValue;
|
||||
if (key instanceof String)
|
||||
return get((String)key);
|
||||
return get(key.toString());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public Object get(String key)
|
||||
public O get(String key)
|
||||
{
|
||||
if (key==null)
|
||||
return _nullValue;
|
||||
|
||||
Map.Entry entry = getEntry(key,0,key.length());
|
||||
Map.Entry<String,O> entry = getEntry(key,0,key.length());
|
||||
if (entry==null)
|
||||
return null;
|
||||
return entry.getValue();
|
||||
|
@ -260,12 +251,12 @@ public class StringMap extends AbstractMap implements Externalizable
|
|||
* @return The Map.Entry for the key or null if the key is not in
|
||||
* the map.
|
||||
*/
|
||||
public Map.Entry getEntry(String key,int offset, int length)
|
||||
public Map.Entry<String,O> getEntry(String key,int offset, int length)
|
||||
{
|
||||
if (key==null)
|
||||
return _nullEntry;
|
||||
|
||||
Node node = _root;
|
||||
Node<O> node = _root;
|
||||
int ni=-1;
|
||||
|
||||
// look for best match
|
||||
|
@ -316,12 +307,12 @@ public class StringMap extends AbstractMap implements Externalizable
|
|||
* @return The Map.Entry for the key or null if the key is not in
|
||||
* the map.
|
||||
*/
|
||||
public Map.Entry getEntry(char[] key,int offset, int length)
|
||||
public Map.Entry<String, O> getEntry(char[] key,int offset, int length)
|
||||
{
|
||||
if (key==null)
|
||||
return _nullEntry;
|
||||
|
||||
Node node = _root;
|
||||
Node<O> node = _root;
|
||||
int ni=-1;
|
||||
|
||||
// look for best match
|
||||
|
@ -367,18 +358,18 @@ public class StringMap extends AbstractMap implements Externalizable
|
|||
/* ------------------------------------------------------------ */
|
||||
/** Get a map entry by byte array key, using as much of the passed key as needed for a match.
|
||||
* A simple 8859-1 byte to char mapping is assumed.
|
||||
* @param key char array containing the key
|
||||
* @param key byte array containing the key
|
||||
* @param offset Offset of the key within the array.
|
||||
* @param maxLength The length of the key
|
||||
* @return The Map.Entry for the key or null if the key is not in
|
||||
* the map.
|
||||
*/
|
||||
public Map.Entry getBestEntry(byte[] key,int offset, int maxLength)
|
||||
public Map.Entry<String,O> getBestEntry(byte[] key,int offset, int maxLength)
|
||||
{
|
||||
if (key==null)
|
||||
return _nullEntry;
|
||||
|
||||
Node node = _root;
|
||||
Node<O> node = _root;
|
||||
int ni=-1;
|
||||
|
||||
// look for best match
|
||||
|
@ -392,7 +383,7 @@ public class StringMap extends AbstractMap implements Externalizable
|
|||
{
|
||||
ni=0;
|
||||
|
||||
Node child = (node._children==null)?null:node._children[c%_width];
|
||||
Node<O> child = (node._children==null)?null:node._children[c%_width];
|
||||
|
||||
if (child==null && i>0)
|
||||
return node; // This is the best match
|
||||
|
@ -426,22 +417,89 @@ public class StringMap extends AbstractMap implements Externalizable
|
|||
return node;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Get a map entry by ByteBuffer key, using as much of the passed key as needed for a match.
|
||||
* A simple 8859-1 byte to char mapping is assumed.
|
||||
* @param key ByteBuffer containing the key
|
||||
* @return The Map.Entry for the key or null if the key is not in
|
||||
* the map.
|
||||
*/
|
||||
public Map.Entry<String,O> getBestEntry(ByteBuffer key)
|
||||
{
|
||||
if (key==null)
|
||||
return _nullEntry;
|
||||
|
||||
if (!key.isReadOnly() && !key.isDirect())
|
||||
return getBestEntry(key.array(),key.position(),key.remaining());
|
||||
|
||||
|
||||
Node<O> node = _root;
|
||||
int ni=-1;
|
||||
|
||||
// look for best match
|
||||
int position=key.position();
|
||||
int remaining=key.remaining();
|
||||
|
||||
charLoop:
|
||||
for (int i=0;i<remaining;i++)
|
||||
{
|
||||
char c=(char)key.get(position+i);
|
||||
|
||||
// Advance node
|
||||
if (ni==-1)
|
||||
{
|
||||
ni=0;
|
||||
|
||||
Node<O> child = (node._children==null)?null:node._children[c%_width];
|
||||
|
||||
if (child==null && i>0)
|
||||
return node; // This is the best match
|
||||
node=child;
|
||||
}
|
||||
|
||||
// While we have a node to try
|
||||
while (node!=null)
|
||||
{
|
||||
// If it is a matching node, goto next char
|
||||
if (node._char[ni]==c || _ignoreCase&&node._ochar[ni]==c)
|
||||
{
|
||||
ni++;
|
||||
if (ni==node._char.length)
|
||||
ni=-1;
|
||||
continue charLoop;
|
||||
}
|
||||
|
||||
// No char match, so if mid node then no match at all.
|
||||
if (ni>0) return null;
|
||||
|
||||
// try next in chain
|
||||
node=node._next;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (ni>0) return null;
|
||||
if (node!=null && node._key==null)
|
||||
return null;
|
||||
return node;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public Object remove(Object key)
|
||||
public O remove(Object key)
|
||||
{
|
||||
if (key==null)
|
||||
return remove(null);
|
||||
return remove(key.toString());
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public Object remove(String key)
|
||||
public O remove(String key)
|
||||
{
|
||||
if (key==null)
|
||||
{
|
||||
Object oldValue=_nullValue;
|
||||
O oldValue=_nullValue;
|
||||
if (_nullEntry!=null)
|
||||
{
|
||||
_entrySet.remove(_nullEntry);
|
||||
|
@ -451,7 +509,7 @@ public class StringMap extends AbstractMap implements Externalizable
|
|||
return oldValue;
|
||||
}
|
||||
|
||||
Node node = _root;
|
||||
Node<O> node = _root;
|
||||
int ni=-1;
|
||||
|
||||
// look for best match
|
||||
|
@ -492,7 +550,7 @@ public class StringMap extends AbstractMap implements Externalizable
|
|||
if (node!=null && node._key==null)
|
||||
return null;
|
||||
|
||||
Object old = node._value;
|
||||
O old = node._value;
|
||||
_entrySet.remove(node);
|
||||
node._value=null;
|
||||
node._key=null;
|
||||
|
@ -502,7 +560,7 @@ public class StringMap extends AbstractMap implements Externalizable
|
|||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public Set entrySet()
|
||||
public Set<Map.Entry<String,O>> entrySet()
|
||||
{
|
||||
return _umEntrySet;
|
||||
}
|
||||
|
@ -535,7 +593,7 @@ public class StringMap extends AbstractMap implements Externalizable
|
|||
@Override
|
||||
public void clear()
|
||||
{
|
||||
_root=new Node();
|
||||
_root=new Node<O>();
|
||||
_nullEntry=null;
|
||||
_nullValue=null;
|
||||
_entrySet.clear();
|
||||
|
@ -545,14 +603,14 @@ public class StringMap extends AbstractMap implements Externalizable
|
|||
/* ------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------ */
|
||||
private static class Node implements Map.Entry
|
||||
private static class Node<O> implements Map.Entry<String,O>
|
||||
{
|
||||
char[] _char;
|
||||
char[] _ochar;
|
||||
Node _next;
|
||||
Node[] _children;
|
||||
Node<O> _next;
|
||||
Node<O>[] _children;
|
||||
String _key;
|
||||
Object _value;
|
||||
O _value;
|
||||
|
||||
Node(){}
|
||||
|
||||
|
@ -577,9 +635,9 @@ public class StringMap extends AbstractMap implements Externalizable
|
|||
}
|
||||
}
|
||||
|
||||
Node split(StringMap map,int offset)
|
||||
Node<O> split(StringMap<O> map,int offset)
|
||||
{
|
||||
Node split = new Node();
|
||||
Node<O> split = new Node<O>();
|
||||
int sl=_char.length-offset;
|
||||
|
||||
char[] tmp=this._char;
|
||||
|
@ -613,9 +671,9 @@ public class StringMap extends AbstractMap implements Externalizable
|
|||
return split;
|
||||
}
|
||||
|
||||
public Object getKey(){return _key;}
|
||||
public Object getValue(){return _value;}
|
||||
public Object setValue(Object o){Object old=_value;_value=o;return old;}
|
||||
public String getKey(){return _key;}
|
||||
public O getValue(){return _value;}
|
||||
public O setValue(O o){O old=_value;_value=o;return old;}
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
@ -659,12 +717,12 @@ public class StringMap extends AbstractMap implements Externalizable
|
|||
|
||||
/* ------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------ */
|
||||
private class NullEntry implements Map.Entry
|
||||
private class NullEntry implements Map.Entry<String,O>
|
||||
{
|
||||
public Object getKey(){return null;}
|
||||
public Object getValue(){return _nullValue;}
|
||||
public Object setValue(Object o)
|
||||
{Object old=_nullValue;_nullValue=o;return old;}
|
||||
public String getKey(){return null;}
|
||||
public O getValue(){return _nullValue;}
|
||||
public O setValue(O o)
|
||||
{O old=_nullValue;_nullValue=o;return old;}
|
||||
@Override
|
||||
public String toString(){return "[:null="+_nullValue+"]";}
|
||||
}
|
||||
|
@ -673,7 +731,7 @@ public class StringMap extends AbstractMap implements Externalizable
|
|||
public void writeExternal(java.io.ObjectOutput out)
|
||||
throws java.io.IOException
|
||||
{
|
||||
HashMap map = new HashMap(this);
|
||||
HashMap<String,O> map = new HashMap<String,O>(this);
|
||||
out.writeBoolean(_ignoreCase);
|
||||
out.writeObject(map);
|
||||
}
|
||||
|
@ -683,7 +741,7 @@ public class StringMap extends AbstractMap implements Externalizable
|
|||
throws java.io.IOException, ClassNotFoundException
|
||||
{
|
||||
boolean ic=in.readBoolean();
|
||||
HashMap map = (HashMap)in.readObject();
|
||||
HashMap<String,O> map = (HashMap<String,O>)in.readObject();
|
||||
setIgnoreCase(ic);
|
||||
this.putAll(map);
|
||||
}
|
||||
|
|
|
@ -428,7 +428,11 @@ public class Log
|
|||
public static Logger getLogger(String name)
|
||||
{
|
||||
if (!initialized())
|
||||
return null;
|
||||
{
|
||||
IllegalStateException e = new IllegalStateException();
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
|
||||
if(name==null)
|
||||
return LOG;
|
||||
|
|
|
@ -399,8 +399,9 @@ public class StdErrLog extends AbstractLogger
|
|||
|
||||
private void format(StringBuilder buffer, String level, String msg, Object... args)
|
||||
{
|
||||
String d = _dateCache.now();
|
||||
int ms = _dateCache.lastMs();
|
||||
long now = System.currentTimeMillis();
|
||||
int ms=(int)(now%1000);
|
||||
String d = _dateCache.format(now);
|
||||
tag(buffer,d,ms,level);
|
||||
format(buffer,msg,args);
|
||||
}
|
||||
|
|
|
@ -13,12 +13,12 @@
|
|||
|
||||
package org.eclipse.jetty.util;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -35,61 +35,33 @@ public class DateCacheTest
|
|||
{
|
||||
//@WAS: Test t = new Test("org.eclipse.jetty.util.DateCache");
|
||||
// 012345678901234567890123456789
|
||||
DateCache dc = new DateCache("EEE, dd MMM yyyy HH:mm:ss zzz ZZZ",
|
||||
Locale.US);
|
||||
dc.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
String last=dc.format(System.currentTimeMillis());
|
||||
boolean change=false;
|
||||
for (int i=0;i<15;i++)
|
||||
{
|
||||
Thread.sleep(100);
|
||||
String date=dc.format(System.currentTimeMillis());
|
||||
DateCache dc = new DateCache("EEE, dd MMM yyyy HH:mm:ss zzz ZZZ",Locale.US);
|
||||
dc.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
|
||||
assertEquals( "Same Date",
|
||||
last.substring(0,17),
|
||||
date.substring(0,17));
|
||||
Thread.sleep(2000);
|
||||
|
||||
if (!last.substring(17).equals(date.substring(17)))
|
||||
change=true;
|
||||
else
|
||||
{
|
||||
int lh=Integer.parseInt(last.substring(17,19));
|
||||
int dh=Integer.parseInt(date.substring(17,19));
|
||||
int lm=Integer.parseInt(last.substring(20,22));
|
||||
int dm=Integer.parseInt(date.substring(20,22));
|
||||
int ls=Integer.parseInt(last.substring(23,25));
|
||||
int ds=Integer.parseInt(date.substring(23,25));
|
||||
long now=System.currentTimeMillis();
|
||||
long end=now+3000;
|
||||
String f=dc.format(now);
|
||||
String last=f;
|
||||
|
||||
// This won't work at midnight!
|
||||
change|= ds!=ls || dm!=lm || dh!=lh;
|
||||
}
|
||||
last=date;
|
||||
}
|
||||
assertTrue("time changed", change);
|
||||
int hits=0;
|
||||
int misses=0;
|
||||
|
||||
while (now<end)
|
||||
{
|
||||
last=f;
|
||||
f=dc.format(now);
|
||||
// System.err.printf("%s %s%n",f,last==f);
|
||||
if (last==f)
|
||||
hits++;
|
||||
else
|
||||
misses++;
|
||||
|
||||
// Test string is cached
|
||||
dc = new DateCache();
|
||||
long now = 1000L*(System.currentTimeMillis()%1000L)+123;
|
||||
// format a time for now
|
||||
String s1=dc.format(now);
|
||||
|
||||
// format a time in the past (this should not reset cached date)
|
||||
dc.format(now-2000);
|
||||
|
||||
// format a time a little later than now
|
||||
String s2=dc.format(now+10);
|
||||
|
||||
// format a time in future (this should reset cached data)
|
||||
dc.format(now+2000);
|
||||
|
||||
// format time a little later than now
|
||||
String s3=dc.format(now+20);
|
||||
|
||||
assertEquals(s1,s2);
|
||||
assertEquals(s2,s3);
|
||||
assertTrue(s1==s2);
|
||||
assertFalse(s2==s3);
|
||||
TimeUnit.MILLISECONDS.sleep(50);
|
||||
now=System.currentTimeMillis();
|
||||
}
|
||||
Assert.assertTrue(hits/10 > misses);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,10 +34,10 @@ import org.junit.Test;
|
|||
*/
|
||||
public class StringMapTest
|
||||
{
|
||||
StringMap m0;
|
||||
StringMap m1;
|
||||
StringMap m5;
|
||||
StringMap m5i;
|
||||
StringMap<String> m0;
|
||||
StringMap<String> m1;
|
||||
StringMap<String> m5;
|
||||
StringMap<String> m5i;
|
||||
|
||||
/*
|
||||
* @see TestCase#setUp()
|
||||
|
@ -46,18 +46,18 @@ public class StringMapTest
|
|||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
m0=new StringMap();
|
||||
m1=new StringMap(false);
|
||||
m0=new StringMap<String>();
|
||||
m1=new StringMap<String>(false);
|
||||
m1.put("abc", "0");
|
||||
|
||||
m5=new StringMap(false);
|
||||
m5=new StringMap<String>(false);
|
||||
m5.put("a", "0");
|
||||
m5.put("ab", "1");
|
||||
m5.put("abc", "2");
|
||||
m5.put("abb", "3");
|
||||
m5.put("bbb", "4");
|
||||
|
||||
m5i=new StringMap(true);
|
||||
m5i=new StringMap<String>(true);
|
||||
m5i.put(null, "0");
|
||||
m5i.put("ab", "1");
|
||||
m5i.put("abc", "2");
|
||||
|
@ -142,7 +142,7 @@ public class StringMapTest
|
|||
@Test
|
||||
public void testGetEntryStringintint()
|
||||
{
|
||||
Map.Entry entry;
|
||||
Map.Entry<String,String> entry;
|
||||
|
||||
entry=m5.getEntry("xabcyz",1,3);
|
||||
assertTrue(entry!=null);
|
||||
|
@ -181,7 +181,7 @@ public class StringMapTest
|
|||
{
|
||||
char[] xabcyz = {'x','a','b','c','y','z'};
|
||||
char[] xaBcyz = {'x','a','B','c','y','z'};
|
||||
Map.Entry entry;
|
||||
Map.Entry<String,String> entry;
|
||||
|
||||
entry=m5.getEntry(xabcyz,1,3);
|
||||
assertTrue(entry!=null);
|
||||
|
@ -266,17 +266,17 @@ public class StringMapTest
|
|||
oo.writeObject(m5i);
|
||||
|
||||
oi=new ObjectInputStream(new ByteArrayInputStream(bout.toByteArray()));
|
||||
m0=(StringMap)oi.readObject();
|
||||
m1=(StringMap)oi.readObject();
|
||||
m5=(StringMap)oi.readObject();
|
||||
m5i=(StringMap)oi.readObject();
|
||||
m0=(StringMap<String>)oi.readObject();
|
||||
m1=(StringMap<String>)oi.readObject();
|
||||
m5=(StringMap<String>)oi.readObject();
|
||||
m5i=(StringMap<String>)oi.readObject();
|
||||
testSize();
|
||||
|
||||
oi=new ObjectInputStream(new ByteArrayInputStream(bout.toByteArray()));
|
||||
m0=(StringMap)oi.readObject();
|
||||
m1=(StringMap)oi.readObject();
|
||||
m5=(StringMap)oi.readObject();
|
||||
m5i=(StringMap)oi.readObject();
|
||||
m0=(StringMap<String>)oi.readObject();
|
||||
m1=(StringMap<String>)oi.readObject();
|
||||
m5=(StringMap<String>)oi.readObject();
|
||||
m5i=(StringMap<String>)oi.readObject();
|
||||
testPutGet();
|
||||
|
||||
}
|
||||
|
@ -292,7 +292,7 @@ public class StringMapTest
|
|||
@Test
|
||||
public void testIgnoreCase()
|
||||
{
|
||||
StringMap map = new StringMap(true);
|
||||
StringMap<String> map = new StringMap<String>(true);
|
||||
map.put("POST","1");
|
||||
map.put("HEAD","2");
|
||||
map.put("PUT","3");
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-webapp</artifactId>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<parent>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-xml</artifactId>
|
||||
|
|
17
pom.xml
17
pom.xml
|
@ -6,7 +6,7 @@
|
|||
<version>19</version>
|
||||
</parent>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
<name>Jetty :: Project</name>
|
||||
<url>${jetty.url}</url>
|
||||
<packaging>pom</packaging>
|
||||
|
@ -29,8 +29,8 @@
|
|||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
<verbose>false</verbose>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
@ -345,6 +345,7 @@
|
|||
<module>jetty-jmx</module>
|
||||
<module>jetty-io</module>
|
||||
<module>jetty-http</module>
|
||||
<!--
|
||||
<module>jetty-websocket</module>
|
||||
<module>jetty-continuation</module>
|
||||
<module>jetty-server</module>
|
||||
|
@ -372,13 +373,13 @@
|
|||
<module>jetty-jsp</module>
|
||||
<module>jetty-distribution</module>
|
||||
<module>test-continuation</module>
|
||||
<!--module>test-continuation-jetty6</module-->
|
||||
<module>test-jetty-servlet</module>
|
||||
<module>test-jetty-webapp</module>
|
||||
<module>test-jetty-nested</module>
|
||||
<module>example-jetty-embedded</module>
|
||||
<module>example-async-rest</module>
|
||||
<module>tests</module>
|
||||
-->
|
||||
</modules>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
|
@ -512,10 +513,12 @@
|
|||
duplicate hits on aggregated classes) -->
|
||||
<id>aggregates</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
<activeByDefault>false</activeByDefault>
|
||||
<!--
|
||||
<file>
|
||||
<exists>${basedir}/pom.xml</exists>
|
||||
</file>
|
||||
-->
|
||||
</activation>
|
||||
<modules>
|
||||
<module>jetty-aggregate</module>
|
||||
|
@ -529,10 +532,12 @@
|
|||
-->
|
||||
<id>osgi</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
<activeByDefault>false</activeByDefault>
|
||||
<!--
|
||||
<file>
|
||||
<exists>${basedir}/pom.xml</exists>
|
||||
</file>
|
||||
-->
|
||||
</activation>
|
||||
<modules>
|
||||
<module>jetty-osgi</module>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>test-continuation</artifactId>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>test-jetty-nested</artifactId>
|
||||
<name>Jetty :: Nested Test</name>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>test-jetty-servlet</artifactId>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>test-jetty-webapp</artifactId>
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>tests-parent</artifactId>
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>tests-parent</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>test-integration</artifactId>
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>tests-parent</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>test-loginservice</artifactId>
|
||||
<name>Jetty Tests :: Login Service</name>
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>tests-parent</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>test-sessions-parent</artifactId>
|
||||
<name>Jetty Tests :: Sessions :: Parent</name>
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-sessions-parent</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>test-hash-sessions</artifactId>
|
||||
<name>Jetty Tests :: Sessions :: Hash</name>
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-sessions-parent</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>test-jdbc-sessions</artifactId>
|
||||
<name>Jetty Tests :: Sessions :: JDBC</name>
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-sessions-parent</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>test-sessions-common</artifactId>
|
||||
<name>Jetty Tests :: Sessions :: Common</name>
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>tests-parent</artifactId>
|
||||
<version>8.1.1-SNAPSHOT</version>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>test-webapps-parent</artifactId>
|
||||
<name>Jetty Tests :: WebApps :: Parent</name>
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue