You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2012/09/16 20:44:51 UTC
svn commit: r1385341 [1/2] - in /httpcomponents/httpcore/trunk:
httpcore-nio/src/main/java/org/apache/http/impl/nio/
httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/
httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/ httpcore-nio/s...
Author: olegk
Date: Sun Sep 16 18:44:51 2012
New Revision: 1385341
URL: http://svn.apache.org/viewvc?rev=1385341&view=rev
Log:
Streamlined session i/o buffer construction
Modified:
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionInputBufferImpl.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionOutputBufferImpl.java
httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestChunkDecoder.java
httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestChunkEncoder.java
httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestHttpMessageParser.java
httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestIdentityDecoder.java
httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestIdentityEncoder.java
httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedDecoder.java
httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedEncoder.java
httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestSessionInOutBuffers.java
httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/util/TestBuffers.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionOutputBufferImpl.java
httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/SessionInputBufferMock.java
httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/SessionOutputBufferMock.java
httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestSessionInOutBuffers.java
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java?rev=1385341&r1=1385340&r2=1385341&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java Sun Sep 16 18:44:51 2012
@@ -35,6 +35,8 @@ import java.net.SocketAddress;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
import java.nio.charset.CodingErrorAction;
import org.apache.http.ConnectionClosedException;
@@ -145,20 +147,25 @@ public class NHttpConnectionBase
linebuffersize = 512;
}
+ CharsetDecoder decoder = null;
+ CharsetEncoder encoder = null;
Charset charset = CharsetUtils.lookup(
(String) params.getParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET));
- if (charset == null) {
+ if (charset != null) {
charset = Consts.ASCII;
+ decoder = charset.newDecoder();
+ encoder = charset.newEncoder();
+ CodingErrorAction malformedCharAction = (CodingErrorAction) params.getParameter(
+ CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION);
+ CodingErrorAction unmappableCharAction = (CodingErrorAction) params.getParameter(
+ CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION);
+ decoder.onMalformedInput(malformedCharAction);
+ decoder.onUnmappableCharacter(unmappableCharAction);
+ encoder.onMalformedInput(malformedCharAction);
+ encoder.onUnmappableCharacter(unmappableCharAction);
}
- CodingErrorAction malformedCharAction = (CodingErrorAction) params.getParameter(
- CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION);
- CodingErrorAction unmappableCharAction = (CodingErrorAction) params.getParameter(
- CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION);
-
- this.inbuf = new SessionInputBufferImpl(buffersize, linebuffersize,
- charset, malformedCharAction, unmappableCharAction, allocator);
- this.outbuf = new SessionOutputBufferImpl(buffersize, linebuffersize,
- charset, malformedCharAction, unmappableCharAction, allocator);
+ this.inbuf = new SessionInputBufferImpl(buffersize, linebuffersize, decoder, allocator);
+ this.outbuf = new SessionOutputBufferImpl(buffersize, linebuffersize, encoder, allocator);
this.incomingContentStrategy = createIncomingContentStrategy();
this.outgoingContentStrategy = createOutgoingContentStrategy();
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionInputBufferImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionInputBufferImpl.java?rev=1385341&r1=1385340&r2=1385341&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionInputBufferImpl.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionInputBufferImpl.java Sun Sep 16 18:44:51 2012
@@ -38,7 +38,6 @@ import java.nio.charset.CharsetDecoder;
import java.nio.charset.CoderResult;
import java.nio.charset.CodingErrorAction;
-import org.apache.http.Consts;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.nio.reactor.SessionInputBuffer;
import org.apache.http.nio.util.ByteBufferAllocator;
@@ -49,6 +48,7 @@ import org.apache.http.params.HttpParams
import org.apache.http.protocol.HTTP;
import org.apache.http.util.Args;
import org.apache.http.util.CharArrayBuffer;
+import org.apache.http.util.CharsetUtils;
/**
* Default implementation of {@link SessionInputBuffer} based on
@@ -59,22 +59,19 @@ import org.apache.http.util.CharArrayBuf
@NotThreadSafe
public class SessionInputBufferImpl extends ExpandableBuffer implements SessionInputBuffer {
- private final CharBuffer charbuffer;
- private final Charset charset;
- private final boolean ascii;
private final CharsetDecoder chardecoder;
+ private final int lineBuffersize;
+
+ private CharBuffer charbuffer;
/**
* Creates SessionInputBufferImpl instance.
*
* @param buffersize input buffer size
- * @param linebuffersize buffer size for line operations
- * @param charset charset to be used for decoding HTTP protocol elements.
- * If <code>null</code> US-ASCII will be used.
- * @param malformedCharAction action to perform upon receiving a malformed input.
- * If <code>null</code> {@link CodingErrorAction#REPORT} will be used.
- * @param unmappableCharAction action to perform upon receiving an unmappable input.
- * If <code>null</code> {@link CodingErrorAction#REPORT} will be used.
+ * @param lineBuffersize buffer size for line operations. Has effect only if
+ * <code>chardecoder</code> is not <code>null</code>.
+ * @param chardecoder chardecoder to be used for decoding HTTP protocol elements.
+ * If <code>null</code> simple type cast will be used for byte to char conversion.
* @param allocator memory allocator.
* If <code>null</code> {@link HeapByteBufferAllocator#INSTANCE} will be used.
*
@@ -82,20 +79,12 @@ public class SessionInputBufferImpl exte
*/
public SessionInputBufferImpl(
int buffersize,
- int linebuffersize,
- final Charset charset,
- final CodingErrorAction malformedCharAction,
- final CodingErrorAction unmappableCharAction,
+ int lineBuffersize,
+ final CharsetDecoder chardecoder,
final ByteBufferAllocator allocator) {
super(buffersize, allocator != null ? allocator : HeapByteBufferAllocator.INSTANCE);
- this.charbuffer = CharBuffer.allocate(linebuffersize);
- this.charset = charset != null ? charset : Consts.ASCII;
- this.ascii = this.charset.equals(Consts.ASCII);
- this.chardecoder = this.charset.newDecoder();
- this.chardecoder.onMalformedInput(malformedCharAction != null ? malformedCharAction :
- CodingErrorAction.REPORT);
- this.chardecoder.onUnmappableCharacter(unmappableCharAction != null? unmappableCharAction :
- CodingErrorAction.REPORT);
+ this.lineBuffersize = Args.positive(lineBuffersize, "Line buffer size");
+ this.chardecoder = chardecoder;
}
/**
@@ -105,21 +94,24 @@ public class SessionInputBufferImpl exte
@Deprecated
public SessionInputBufferImpl(
int buffersize,
- int linebuffersize,
+ int lineBuffersize,
final ByteBufferAllocator allocator,
final HttpParams params) {
super(buffersize, allocator);
- this.charbuffer = CharBuffer.allocate(linebuffersize);
- String charset = (String) params.getParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET);
- this.charset = charset != null ? Charset.forName(charset) : Consts.ASCII;
- this.ascii = this.charset.equals(Consts.ASCII);
- this.chardecoder = this.charset.newDecoder();
- CodingErrorAction a1 = (CodingErrorAction) params.getParameter(
- CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION);
- this.chardecoder.onMalformedInput(a1 != null ? a1 : CodingErrorAction.REPORT);
- CodingErrorAction a2 = (CodingErrorAction) params.getParameter(
- CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION);
- this.chardecoder.onUnmappableCharacter(a2 != null? a2 : CodingErrorAction.REPORT);
+ this.lineBuffersize = Args.positive(lineBuffersize, "Line buffer size");
+ String charsetName = (String) params.getParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET);
+ Charset charset = CharsetUtils.lookup(charsetName);
+ if (charset != null) {
+ this.chardecoder = charset.newDecoder();
+ CodingErrorAction a1 = (CodingErrorAction) params.getParameter(
+ CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION);
+ this.chardecoder.onMalformedInput(a1 != null ? a1 : CodingErrorAction.REPORT);
+ CodingErrorAction a2 = (CodingErrorAction) params.getParameter(
+ CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION);
+ this.chardecoder.onUnmappableCharacter(a2 != null? a2 : CodingErrorAction.REPORT);
+ } else {
+ this.chardecoder = null;
+ }
}
/**
@@ -137,10 +129,8 @@ public class SessionInputBufferImpl exte
/**
* @since 4.3
*/
- public SessionInputBufferImpl(
- int buffersize,
- int linebuffersize) {
- this(buffersize, linebuffersize, null, null, null, null);
+ public SessionInputBufferImpl(int buffersize) {
+ this(buffersize, 256, null, HeapByteBufferAllocator.INSTANCE);
}
/**
@@ -148,11 +138,10 @@ public class SessionInputBufferImpl exte
*/
public SessionInputBufferImpl(
int buffersize,
- int linebuffersize,
- final Charset charset,
- final CodingErrorAction malformedCharAction,
- final CodingErrorAction unmappableCharAction) {
- this(buffersize, linebuffersize, charset, malformedCharAction, unmappableCharAction, null);
+ int lineBuffersize,
+ final Charset charset) {
+ this(buffersize, lineBuffersize,
+ charset != null ? charset.newDecoder() : null, HeapByteBufferAllocator.INSTANCE);
}
public int fill(final ReadableByteChannel channel) throws IOException {
@@ -249,7 +238,7 @@ public class SessionInputBufferImpl exte
// Ensure capacity of len assuming ASCII as the most likely charset
linebuffer.ensureCapacity(requiredCapacity);
- if (this.ascii) {
+ if (this.chardecoder == null) {
if (this.buffer.hasArray()) {
byte[] b = this.buffer.array();
int off = this.buffer.position();
@@ -262,6 +251,9 @@ public class SessionInputBufferImpl exte
}
}
} else {
+ if (this.charbuffer == null) {
+ this.charbuffer = CharBuffer.allocate(this.lineBuffersize);
+ }
this.chardecoder.reset();
for (;;) {
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionOutputBufferImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionOutputBufferImpl.java?rev=1385341&r1=1385340&r2=1385341&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionOutputBufferImpl.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionOutputBufferImpl.java Sun Sep 16 18:44:51 2012
@@ -38,7 +38,6 @@ import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult;
import java.nio.charset.CodingErrorAction;
-import org.apache.http.Consts;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.nio.reactor.SessionOutputBuffer;
import org.apache.http.nio.util.ByteBufferAllocator;
@@ -49,6 +48,7 @@ import org.apache.http.params.HttpParams
import org.apache.http.protocol.HTTP;
import org.apache.http.util.Args;
import org.apache.http.util.CharArrayBuffer;
+import org.apache.http.util.CharsetUtils;
/**
* Default implementation of {@link SessionOutputBuffer} based on
@@ -61,22 +61,19 @@ public class SessionOutputBufferImpl ext
private static final byte[] CRLF = new byte[] {HTTP.CR, HTTP.LF};
- private final CharBuffer charbuffer;
- private final Charset charset;
- private final boolean ascii;
private final CharsetEncoder charencoder;
+ private final int lineBuffersize;
+
+ private CharBuffer charbuffer;
/**
* Creates SessionOutputBufferImpl instance.
*
* @param buffersize input buffer size
- * @param linebuffersize buffer size for line operations
- * @param charset charset to be used for decoding HTTP protocol elements.
- * If <code>null</code> US-ASCII will be used.
- * @param malformedCharAction action to perform upon receiving a malformed input.
- * If <code>null</code> {@link CodingErrorAction#REPORT} will be used.
- * @param unmappableCharAction action to perform upon receiving an unmappable input.
- * If <code>null</code> {@link CodingErrorAction#REPORT} will be used.
+ * @param lineBuffersize buffer size for line operations. Has effect only if
+ * <code>charencoder</code> is not <code>null</code>.
+ * @param charencoder charencoder to be used for encoding HTTP protocol elements.
+ * If <code>null</code> simple type cast will be used for char to byte conversion.
* @param allocator memory allocator.
* If <code>null</code> {@link HeapByteBufferAllocator#INSTANCE} will be used.
*
@@ -84,20 +81,12 @@ public class SessionOutputBufferImpl ext
*/
public SessionOutputBufferImpl(
int buffersize,
- int linebuffersize,
- final Charset charset,
- final CodingErrorAction malformedCharAction,
- final CodingErrorAction unmappableCharAction,
+ int lineBuffersize,
+ final CharsetEncoder charencoder,
final ByteBufferAllocator allocator) {
super(buffersize, allocator != null ? allocator : HeapByteBufferAllocator.INSTANCE);
- this.charbuffer = CharBuffer.allocate(linebuffersize);
- this.charset = charset != null ? charset : Consts.ASCII;
- this.ascii = this.charset.equals(Consts.ASCII);
- this.charencoder = this.charset.newEncoder();
- this.charencoder.onMalformedInput(malformedCharAction != null ? malformedCharAction :
- CodingErrorAction.REPORT);
- this.charencoder.onUnmappableCharacter(unmappableCharAction != null? unmappableCharAction :
- CodingErrorAction.REPORT);
+ this.lineBuffersize = Args.positive(lineBuffersize, "Line buffer size");
+ this.charencoder = charencoder;
}
/**
@@ -107,21 +96,24 @@ public class SessionOutputBufferImpl ext
@Deprecated
public SessionOutputBufferImpl(
int buffersize,
- int linebuffersize,
+ int lineBuffersize,
final ByteBufferAllocator allocator,
final HttpParams params) {
super(buffersize, allocator);
- this.charbuffer = CharBuffer.allocate(linebuffersize);
- String charset = (String) params.getParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET);
- this.charset = charset != null ? Charset.forName(charset) : Consts.ASCII;
- this.ascii = this.charset.equals(Consts.ASCII);
- this.charencoder = this.charset.newEncoder();
- CodingErrorAction a1 = (CodingErrorAction) params.getParameter(
- CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION);
- this.charencoder.onMalformedInput(a1 != null ? a1 : CodingErrorAction.REPORT);
- CodingErrorAction a2 = (CodingErrorAction) params.getParameter(
- CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION);
- this.charencoder.onUnmappableCharacter(a2 != null? a2 : CodingErrorAction.REPORT);
+ this.lineBuffersize = Args.positive(lineBuffersize, "Line buffer size");
+ String charsetName = (String) params.getParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET);
+ Charset charset = CharsetUtils.lookup(charsetName);
+ if (charset != null) {
+ this.charencoder = charset.newEncoder();
+ CodingErrorAction a1 = (CodingErrorAction) params.getParameter(
+ CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION);
+ this.charencoder.onMalformedInput(a1 != null ? a1 : CodingErrorAction.REPORT);
+ CodingErrorAction a2 = (CodingErrorAction) params.getParameter(
+ CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION);
+ this.charencoder.onUnmappableCharacter(a2 != null? a2 : CodingErrorAction.REPORT);
+ } else {
+ this.charencoder = null;
+ }
}
/**
@@ -139,10 +131,8 @@ public class SessionOutputBufferImpl ext
/**
* @since 4.3
*/
- public SessionOutputBufferImpl(
- int buffersize,
- int linebuffersize) {
- this(buffersize, linebuffersize, null, null, null, null);
+ public SessionOutputBufferImpl(int buffersize) {
+ this(buffersize, 256, null, HeapByteBufferAllocator.INSTANCE);
}
/**
@@ -151,10 +141,9 @@ public class SessionOutputBufferImpl ext
public SessionOutputBufferImpl(
int buffersize,
int linebuffersize,
- final Charset charset,
- final CodingErrorAction malformedCharAction,
- final CodingErrorAction unmappableCharAction) {
- this(buffersize, linebuffersize, charset, malformedCharAction, unmappableCharAction, null);
+ final Charset charset) {
+ this(buffersize, linebuffersize,
+ charset != null ? charset.newEncoder() : null, HeapByteBufferAllocator.INSTANCE);
}
public void reset(final HttpParams params) {
@@ -209,7 +198,7 @@ public class SessionOutputBufferImpl ext
setInputMode();
// Do not bother if the buffer is empty
if (linebuffer.length() > 0 ) {
- if (this.ascii) {
+ if (this.charencoder == null) {
int requiredCapacity = this.buffer.position() + linebuffer.length();
ensureCapacity(requiredCapacity);
if (this.buffer.hasArray()) {
@@ -226,6 +215,9 @@ public class SessionOutputBufferImpl ext
}
}
} else {
+ if (this.charbuffer == null) {
+ this.charbuffer = CharBuffer.allocate(this.lineBuffersize);
+ }
this.charencoder.reset();
// transfer the string in small chunks
int remaining = linebuffer.length();
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestChunkDecoder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestChunkDecoder.java?rev=1385341&r1=1385340&r2=1385341&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestChunkDecoder.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestChunkDecoder.java Sun Sep 16 18:44:51 2012
@@ -31,6 +31,7 @@ import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
+import org.apache.http.Consts;
import org.apache.http.Header;
import org.apache.http.MalformedChunkCodingException;
import org.apache.http.ReadableByteChannelMock;
@@ -59,7 +60,7 @@ public class TestChunkDecoder {
String s = "5\r\n01234\r\n5\r\n56789\r\n6\r\nabcdef\r\n0\r\n\r\n";
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {s}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
ChunkDecoder decoder = new ChunkDecoder(channel, inbuf, metrics);
@@ -84,7 +85,7 @@ public class TestChunkDecoder {
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {s}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
ChunkDecoder decoder = new ChunkDecoder(channel, inbuf, metrics);
@@ -121,7 +122,7 @@ public class TestChunkDecoder {
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {s1, s2}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
ChunkDecoder decoder = new ChunkDecoder(channel, inbuf, metrics);
@@ -165,7 +166,7 @@ public class TestChunkDecoder {
ReadableByteChannel channel = new ReadableByteChannelMock(
chunks, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
ByteBuffer dst = ByteBuffer.allocate(1024);
@@ -202,7 +203,7 @@ public class TestChunkDecoder {
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {s}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
ChunkDecoder decoder = new ChunkDecoder(channel, inbuf, metrics);
@@ -222,7 +223,7 @@ public class TestChunkDecoder {
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {s}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
ChunkDecoder decoder = new ChunkDecoder(channel, inbuf, metrics);
@@ -242,7 +243,7 @@ public class TestChunkDecoder {
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {s}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
ChunkDecoder decoder = new ChunkDecoder(channel, inbuf, metrics);
@@ -263,7 +264,7 @@ public class TestChunkDecoder {
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {s}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
ChunkDecoder decoder = new ChunkDecoder(channel, inbuf, metrics);
@@ -286,7 +287,7 @@ public class TestChunkDecoder {
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {s}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
ChunkDecoder decoder = new ChunkDecoder(channel, inbuf, metrics);
@@ -307,7 +308,7 @@ public class TestChunkDecoder {
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {s}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
ChunkDecoder decoder = new ChunkDecoder(channel, inbuf, metrics);
@@ -334,7 +335,7 @@ public class TestChunkDecoder {
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {s}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
ChunkDecoder decoder = new ChunkDecoder(channel, inbuf, metrics);
@@ -366,7 +367,7 @@ public class TestChunkDecoder {
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {s}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
ChunkDecoder decoder = new ChunkDecoder(channel, inbuf, metrics);
@@ -390,7 +391,7 @@ public class TestChunkDecoder {
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {"stuff;", "more stuff"}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
try {
new ChunkDecoder(null, null, null);
Assert.fail("IllegalArgumentException should have been thrown");
@@ -418,7 +419,7 @@ public class TestChunkDecoder {
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {s}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
ChunkDecoder decoder = new ChunkDecoder(channel, inbuf, metrics);
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestChunkEncoder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestChunkEncoder.java?rev=1385341&r1=1385340&r2=1385341&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestChunkEncoder.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestChunkEncoder.java Sun Sep 16 18:44:51 2012
@@ -34,6 +34,7 @@ import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.WritableByteChannel;
+import org.apache.http.Consts;
import org.apache.http.impl.io.HttpTransportMetricsImpl;
import org.apache.http.impl.nio.reactor.SessionOutputBufferImpl;
import org.apache.http.nio.reactor.SessionOutputBuffer;
@@ -58,7 +59,7 @@ public class TestChunkEncoder {
public void testBasicCoding() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WritableByteChannel channel = newChannel(baos);
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
ChunkEncoder encoder = new ChunkEncoder(channel, outbuf, metrics);
@@ -79,7 +80,7 @@ public class TestChunkEncoder {
public void testChunkNoExceed() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WritableByteChannel channel = newChannel(baos);
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
ChunkEncoder encoder = new ChunkEncoder(channel, outbuf, metrics);
encoder.write(wrap("1234"));
@@ -96,7 +97,7 @@ public class TestChunkEncoder {
@Test
public void testHttpCore239() throws Exception {
FixedByteChannel channel = new FixedByteChannel(16);
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(16, 16);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(16, 16, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
ChunkEncoder encoder = new ChunkEncoder(channel, outbuf, metrics);
@@ -134,7 +135,7 @@ public class TestChunkEncoder {
public void testChunkExceed() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WritableByteChannel channel = newChannel(baos);
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(16, 16);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(16, 16, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
ChunkEncoder encoder = new ChunkEncoder(channel, outbuf, metrics);
@@ -162,7 +163,7 @@ public class TestChunkEncoder {
public void testCodingEmptyBuffer() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WritableByteChannel channel = newChannel(baos);
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
ChunkEncoder encoder = new ChunkEncoder(channel, outbuf, metrics);
@@ -189,7 +190,7 @@ public class TestChunkEncoder {
public void testCodingCompleted() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WritableByteChannel channel = newChannel(baos);
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
ChunkEncoder encoder = new ChunkEncoder(channel, outbuf, metrics);
@@ -216,7 +217,7 @@ public class TestChunkEncoder {
public void testInvalidConstructor() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WritableByteChannel channel = newChannel(baos);
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, Consts.ASCII);
try {
new ChunkEncoder(null, null, null);
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestHttpMessageParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestHttpMessageParser.java?rev=1385341&r1=1385340&r2=1385341&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestHttpMessageParser.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestHttpMessageParser.java Sun Sep 16 18:44:51 2012
@@ -33,6 +33,7 @@ import java.io.UnsupportedEncodingExcept
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
+import org.apache.http.Consts;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
@@ -60,7 +61,7 @@ public class TestHttpMessageParser {
@Test
public void testSimpleParsing() throws Exception {
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf);
requestParser.fillBuffer(newChannel("GET /whatever HTTP/1.1\r\nSome header: stuff\r\n\r\n"));
HttpRequest request = requestParser.parse();
@@ -71,7 +72,7 @@ public class TestHttpMessageParser {
@Test
public void testParsingChunkedMessages() throws Exception {
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf);
requestParser.fillBuffer(newChannel("GET /whatev"));
@@ -91,7 +92,7 @@ public class TestHttpMessageParser {
@Test
public void testParsingFoldedHeaders() throws Exception {
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf);
requestParser.fillBuffer(newChannel("GET /whatev"));
@@ -120,7 +121,7 @@ public class TestHttpMessageParser {
@Test
public void testParsingBadlyFoldedFirstHeader() throws Exception {
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf);
requestParser.fillBuffer(newChannel("GET /whatev"));
@@ -146,7 +147,7 @@ public class TestHttpMessageParser {
@Test
public void testParsingEmptyFoldedHeader() throws Exception {
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf);
requestParser.fillBuffer(newChannel("GET /whatev"));
@@ -175,7 +176,7 @@ public class TestHttpMessageParser {
@Test
public void testParsingIncompleteRequestLine() throws Exception {
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf);
ReadableByteChannel channel = newChannel("GET /whatever HTTP/1.0");
@@ -188,7 +189,7 @@ public class TestHttpMessageParser {
@Test
public void testParsingIncompleteHeader() throws Exception {
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf);
ReadableByteChannel channel = newChannel("GET /whatever HTTP/1.0\r\nHeader: whatever");
@@ -202,7 +203,7 @@ public class TestHttpMessageParser {
@Test
public void testParsingInvalidRequestLine() throws Exception {
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf);
ReadableByteChannel channel = newChannel("GET garbage\r\n");
@@ -217,7 +218,7 @@ public class TestHttpMessageParser {
@Test
public void testParsingInvalidStatusLine() throws Exception {
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
NHttpMessageParser<HttpResponse> responseParser = new DefaultHttpResponseParser(inbuf);
ReadableByteChannel channel = newChannel("HTTP 200 OK\r\n");
@@ -232,7 +233,7 @@ public class TestHttpMessageParser {
@Test
public void testParsingInvalidHeader() throws Exception {
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
NHttpMessageParser<HttpResponse> responseParser = new DefaultHttpResponseParser(inbuf);
ReadableByteChannel channel = newChannel("HTTP/1.0 200 OK\r\nstuff\r\n\r\n");
@@ -247,7 +248,7 @@ public class TestHttpMessageParser {
@Test
public void testResetParser() throws Exception {
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf);
ReadableByteChannel channel = newChannel("GET /whatever HTTP/1.0\r\nHeader: one\r\n\r\n");
@@ -279,7 +280,7 @@ public class TestHttpMessageParser {
@Test
public void testLineLimitForStatus() throws Exception {
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf, -1, 0, null, null);
requestParser.fillBuffer(newChannel("GET /whatever HTTP/1.0\r\nHeader: one\r\n\r\n"));
requestParser.parse();
@@ -296,7 +297,7 @@ public class TestHttpMessageParser {
@Test
public void testLineLimitForHeader() throws Exception {
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf, -1, 0, null, null);
requestParser.fillBuffer(newChannel("GET /whatever HTTP/1.0\r\nHeader: one\r\n\r\n"));
@@ -317,7 +318,7 @@ public class TestHttpMessageParser {
@Test
public void testLineLimitForFoldedHeader() throws Exception {
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf, 2, 15, null, null);
try {
@@ -330,7 +331,7 @@ public class TestHttpMessageParser {
@Test
public void testMaxHeaderCount() throws Exception {
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf, 2, -1, null, null);
requestParser.fillBuffer(newChannel("GET /whatever HTTP/1.0\r\nHeader: one\r\nHeader: two\r\n\r\n"));
@@ -347,7 +348,7 @@ public class TestHttpMessageParser {
@Test
public void testDetectLineLimitEarly() throws Exception {
- SessionInputBuffer inbuf = new SessionInputBufferImpl(2, 128);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(2, 128, Consts.ASCII);
NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf, -1, 2, null, null);
ReadableByteChannel channel = newChannel("GET / HTTP/1.0\r\nHeader: one\r\n\r\n");
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestIdentityDecoder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestIdentityDecoder.java?rev=1385341&r1=1385340&r2=1385341&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestIdentityDecoder.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestIdentityDecoder.java Sun Sep 16 18:44:51 2012
@@ -36,6 +36,7 @@ import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
+import org.apache.http.Consts;
import org.apache.http.ReadableByteChannelMock;
import org.apache.http.impl.io.HttpTransportMetricsImpl;
import org.apache.http.impl.nio.reactor.SessionInputBufferImpl;
@@ -78,7 +79,7 @@ public class TestIdentityDecoder {
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {"stuff;", "more stuff"}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
IdentityDecoder decoder = new IdentityDecoder(channel, inbuf, metrics);
@@ -115,7 +116,7 @@ public class TestIdentityDecoder {
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {"stuff;", "more stuff"}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
inbuf.fill(channel);
@@ -158,7 +159,7 @@ public class TestIdentityDecoder {
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {"stuff; ", "more stuff; ", "a lot more stuff!"}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
IdentityDecoder decoder = new IdentityDecoder(
channel, inbuf, metrics);
@@ -195,7 +196,7 @@ public class TestIdentityDecoder {
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {"stuff; ", "more stuff; ", "a lot more stuff!"}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
IdentityDecoder decoder = new IdentityDecoder(
channel, inbuf, metrics);
@@ -230,7 +231,7 @@ public class TestIdentityDecoder {
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {"stuff; ", "more stuff; ", "a lot more stuff!"}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
IdentityDecoder decoder = new IdentityDecoder(
channel, inbuf, metrics);
@@ -272,7 +273,7 @@ public class TestIdentityDecoder {
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {"a"}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
IdentityDecoder decoder = new IdentityDecoder(
channel, inbuf, metrics);
@@ -297,7 +298,7 @@ public class TestIdentityDecoder {
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {"stuff;", "more stuff"}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
try {
new IdentityDecoder(null, null, null);
Assert.fail("IllegalArgumentException should have been thrown");
@@ -324,7 +325,7 @@ public class TestIdentityDecoder {
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {s}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
IdentityDecoder decoder = new IdentityDecoder(channel, inbuf, metrics);
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestIdentityEncoder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestIdentityEncoder.java?rev=1385341&r1=1385340&r2=1385341&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestIdentityEncoder.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestIdentityEncoder.java Sun Sep 16 18:44:51 2012
@@ -32,6 +32,7 @@ import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.WritableByteChannel;
+import org.apache.http.Consts;
import org.apache.http.impl.io.HttpTransportMetricsImpl;
import org.apache.http.impl.nio.reactor.SessionOutputBufferImpl;
import org.apache.http.nio.reactor.SessionOutputBuffer;
@@ -56,7 +57,7 @@ public class TestIdentityEncoder {
public void testBasicCoding() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WritableByteChannel channel = newChannel(baos);
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
IdentityEncoder encoder = new IdentityEncoder(channel, outbuf, metrics);
@@ -73,7 +74,7 @@ public class TestIdentityEncoder {
public void testCodingEmptyBuffer() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WritableByteChannel channel = newChannel(baos);
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
IdentityEncoder encoder = new IdentityEncoder(channel, outbuf, metrics);
@@ -96,7 +97,7 @@ public class TestIdentityEncoder {
public void testCodingCompleted() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WritableByteChannel channel = newChannel(baos);
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
IdentityEncoder encoder = new IdentityEncoder(channel, outbuf, metrics);
@@ -115,7 +116,7 @@ public class TestIdentityEncoder {
public void testInvalidConstructor() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WritableByteChannel channel = newChannel(baos);
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, Consts.ASCII);
try {
new IdentityEncoder(null, null, null);
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedDecoder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedDecoder.java?rev=1385341&r1=1385340&r2=1385341&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedDecoder.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedDecoder.java Sun Sep 16 18:44:51 2012
@@ -37,6 +37,7 @@ import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import org.apache.http.ConnectionClosedException;
+import org.apache.http.Consts;
import org.apache.http.ReadableByteChannelMock;
import org.apache.http.impl.io.HttpTransportMetricsImpl;
import org.apache.http.impl.nio.reactor.SessionInputBufferImpl;
@@ -94,7 +95,7 @@ public class TestLengthDelimitedDecoder
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {"stuff;", "more stuff"}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
LengthDelimitedDecoder decoder = new LengthDelimitedDecoder(
channel, inbuf, metrics, 16);
@@ -128,7 +129,7 @@ public class TestLengthDelimitedDecoder
"stuff;",
"more stuff; and a lot more stuff"}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
LengthDelimitedDecoder decoder = new LengthDelimitedDecoder(
channel, inbuf, metrics, 16);
@@ -160,7 +161,7 @@ public class TestLengthDelimitedDecoder
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {"stuff;", "more stuff"}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
LengthDelimitedDecoder decoder = new LengthDelimitedDecoder(
channel, inbuf, metrics, 16);
@@ -213,7 +214,7 @@ public class TestLengthDelimitedDecoder
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {"stuff;", "more stuff"}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
inbuf.fill(channel);
@@ -252,7 +253,7 @@ public class TestLengthDelimitedDecoder
"stuff;",
"more stuff; and a lot more stuff"}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
inbuf.fill(channel);
@@ -283,7 +284,7 @@ public class TestLengthDelimitedDecoder
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {"stuff; ", "more stuff; ", "a lot more stuff!!!"}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
LengthDelimitedDecoder decoder = new LengthDelimitedDecoder(
channel, inbuf, metrics, 36);
@@ -311,7 +312,7 @@ public class TestLengthDelimitedDecoder
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {"stuff; ", "more stuff; ", "a lot more stuff!!!"}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
LengthDelimitedDecoder decoder = new LengthDelimitedDecoder(
channel, inbuf, metrics, 36);
@@ -342,7 +343,7 @@ public class TestLengthDelimitedDecoder
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {"stuff; ", "more stuff; ", "a lot more stuff!"}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
LengthDelimitedDecoder decoder = new LengthDelimitedDecoder(
channel, inbuf, metrics, 36);
@@ -387,7 +388,7 @@ public class TestLengthDelimitedDecoder
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {"a"}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
LengthDelimitedDecoder decoder = new LengthDelimitedDecoder(
channel, inbuf, metrics, 1);
@@ -414,7 +415,7 @@ public class TestLengthDelimitedDecoder
"stuff;",
"more stuff; and a lot more stuff"}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
LengthDelimitedDecoder decoder = new LengthDelimitedDecoder(
channel, inbuf, metrics, 16);
@@ -448,7 +449,7 @@ public class TestLengthDelimitedDecoder
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {"stuff;", "more stuff"}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
try {
new LengthDelimitedDecoder(null, null, null, 10);
@@ -482,7 +483,7 @@ public class TestLengthDelimitedDecoder
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {s}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
LengthDelimitedDecoder decoder = new LengthDelimitedDecoder(
channel, inbuf, metrics, 3);
@@ -500,7 +501,7 @@ public class TestLengthDelimitedDecoder
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {"stuff"}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
LengthDelimitedDecoder decoder = new LengthDelimitedDecoder(
channel, inbuf, metrics, 0);
@@ -518,7 +519,7 @@ public class TestLengthDelimitedDecoder
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {"1234567890"}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
LengthDelimitedDecoder decoder = new LengthDelimitedDecoder(
channel, inbuf, metrics, 20);
@@ -535,7 +536,7 @@ public class TestLengthDelimitedDecoder
ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {"1234567890"}, "US-ASCII");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
LengthDelimitedDecoder decoder = new LengthDelimitedDecoder(
channel, inbuf, metrics, 20);
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedEncoder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedEncoder.java?rev=1385341&r1=1385340&r2=1385341&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedEncoder.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedEncoder.java Sun Sep 16 18:44:51 2012
@@ -37,6 +37,7 @@ import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.WritableByteChannel;
+import org.apache.http.Consts;
import org.apache.http.impl.io.HttpTransportMetricsImpl;
import org.apache.http.impl.nio.reactor.SessionOutputBufferImpl;
import org.apache.http.nio.reactor.SessionOutputBuffer;
@@ -61,7 +62,7 @@ public class TestLengthDelimitedEncoder
public void testBasicCoding() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WritableByteChannel channel = newChannel(baos);
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
LengthDelimitedEncoder encoder = new LengthDelimitedEncoder(
@@ -79,7 +80,7 @@ public class TestLengthDelimitedEncoder
public void testCodingBeyondContentLimit() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WritableByteChannel channel = newChannel(baos);
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
LengthDelimitedEncoder encoder = new LengthDelimitedEncoder(
@@ -97,7 +98,7 @@ public class TestLengthDelimitedEncoder
public void testCodingEmptyBuffer() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WritableByteChannel channel = newChannel(baos);
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
LengthDelimitedEncoder encoder = new LengthDelimitedEncoder(
@@ -121,7 +122,7 @@ public class TestLengthDelimitedEncoder
public void testCodingCompleted() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WritableByteChannel channel = newChannel(baos);
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
LengthDelimitedEncoder encoder = new LengthDelimitedEncoder(
@@ -141,7 +142,7 @@ public class TestLengthDelimitedEncoder
public void testCodingBeyondContentLimitFromFile() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WritableByteChannel channel = newChannel(baos);
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
LengthDelimitedEncoder encoder = new LengthDelimitedEncoder(
@@ -181,7 +182,7 @@ public class TestLengthDelimitedEncoder
public void testCodingEmptyFile() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WritableByteChannel channel = newChannel(baos);
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
LengthDelimitedEncoder encoder = new LengthDelimitedEncoder(
@@ -215,7 +216,7 @@ public class TestLengthDelimitedEncoder
public void testCodingCompletedFromFile() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WritableByteChannel channel = newChannel(baos);
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
LengthDelimitedEncoder encoder = new LengthDelimitedEncoder(
@@ -247,7 +248,7 @@ public class TestLengthDelimitedEncoder
public void testCodingFromFileSmaller() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WritableByteChannel channel = newChannel(baos);
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
LengthDelimitedEncoder encoder = new LengthDelimitedEncoder(
@@ -280,7 +281,7 @@ public class TestLengthDelimitedEncoder
public void testInvalidConstructor() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WritableByteChannel channel = newChannel(baos);
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
try {
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestSessionInOutBuffers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestSessionInOutBuffers.java?rev=1385341&r1=1385340&r2=1385341&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestSessionInOutBuffers.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestSessionInOutBuffers.java Sun Sep 16 18:44:51 2012
@@ -35,6 +35,8 @@ import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
import java.nio.charset.CharacterCodingException;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
import java.nio.charset.CodingErrorAction;
import java.util.Arrays;
import java.util.Collection;
@@ -93,7 +95,7 @@ public class TestSessionInOutBuffers {
@Test
public void testReadLineChunks() throws Exception {
- SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, null, null, null, this.allocator);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, null, this.allocator);
ReadableByteChannel channel = newChannel("One\r\nTwo\r\nThree");
@@ -131,8 +133,8 @@ public class TestSessionInOutBuffers {
@Test
public void testWriteLineChunks() throws Exception {
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(16, 16, null, null, null, this.allocator);
- SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, null, null, null, this.allocator);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(16, 16, null, this.allocator);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, null, this.allocator);
ReadableByteChannel inChannel = newChannel("One\r\nTwo\r\nThree");
@@ -199,7 +201,7 @@ public class TestSessionInOutBuffers {
teststrs[3] = "";
teststrs[4] = "And goodbye";
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, null, null, null, this.allocator);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, null, this.allocator);
for (int i = 0; i < teststrs.length; i++) {
outbuf.writeLine(teststrs[i]);
}
@@ -213,7 +215,7 @@ public class TestSessionInOutBuffers {
ReadableByteChannel channel = newChannel(outstream.toByteArray());
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 16, null, null, null, this.allocator);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 16, null, this.allocator);
inbuf.fill(channel);
for (int i = 0; i < teststrs.length; i++) {
@@ -225,7 +227,7 @@ public class TestSessionInOutBuffers {
@Test
public void testComplexReadWriteLine() throws Exception {
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, null, null, null, this.allocator);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, null, this.allocator);
outbuf.write(ByteBuffer.wrap(new byte[] {'a', '\n'}));
outbuf.write(ByteBuffer.wrap(new byte[] {'\r', '\n'}));
outbuf.write(ByteBuffer.wrap(new byte[] {'\r', '\r', '\n'}));
@@ -263,7 +265,7 @@ public class TestSessionInOutBuffers {
ReadableByteChannel channel = newChannel(outstream.toByteArray());
- SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 16, null, null, null, this.allocator);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 16, null, this.allocator);
inbuf.fill(channel);
Assert.assertEquals("a", inbuf.readLine(true));
@@ -286,7 +288,7 @@ public class TestSessionInOutBuffers {
out[i] = (byte)('0' + i);
}
ReadableByteChannel channel = newChannel(out);
- SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, null, null, null, this.allocator);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, null, this.allocator);
while (inbuf.fill(channel) > 0) {
}
@@ -303,7 +305,7 @@ public class TestSessionInOutBuffers {
public void testReadByteBuffer() throws Exception {
byte[] pattern = "0123456789ABCDEF".getBytes("US-ASCII");
ReadableByteChannel channel = newChannel(pattern);
- SessionInputBuffer inbuf = new SessionInputBufferImpl(4096, 1024, null, null, null, this.allocator);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(4096, 1024, null, this.allocator);
while (inbuf.fill(channel) > 0) {
}
ByteBuffer dst = ByteBuffer.allocate(10);
@@ -320,7 +322,7 @@ public class TestSessionInOutBuffers {
public void testReadByteBufferWithMaxLen() throws Exception {
byte[] pattern = "0123456789ABCDEF".getBytes("US-ASCII");
ReadableByteChannel channel = newChannel(pattern);
- SessionInputBuffer inbuf = new SessionInputBufferImpl(4096, 1024, null, null, null, this.allocator);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(4096, 1024, null, this.allocator);
while (inbuf.fill(channel) > 0) {
}
ByteBuffer dst = ByteBuffer.allocate(16);
@@ -340,7 +342,7 @@ public class TestSessionInOutBuffers {
public void testReadToChannel() throws Exception {
byte[] pattern = "0123456789ABCDEF".getBytes("US-ASCII");
ReadableByteChannel channel = newChannel(pattern);
- SessionInputBuffer inbuf = new SessionInputBufferImpl(4096, 1024, null, null, null, this.allocator);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(4096, 1024, null, this.allocator);
while (inbuf.fill(channel) > 0) {
}
@@ -355,7 +357,7 @@ public class TestSessionInOutBuffers {
public void testReadToChannelWithMaxLen() throws Exception {
byte[] pattern = "0123456789ABCDEF".getBytes("US-ASCII");
ReadableByteChannel channel = newChannel(pattern);
- SessionInputBuffer inbuf = new SessionInputBufferImpl(4096, 1024, null, null, null, this.allocator);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(4096, 1024, null, this.allocator);
while (inbuf.fill(channel) > 0) {
}
@@ -372,7 +374,7 @@ public class TestSessionInOutBuffers {
public void testWriteByteBuffer() throws Exception {
byte[] pattern = "0123456789ABCDEF0123456789ABCDEF".getBytes("US-ASCII");
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(4096, 1024, null, null, null, this.allocator);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(4096, 1024, null, this.allocator);
ReadableByteChannel src = newChannel(pattern);
outbuf.write(src);
@@ -387,7 +389,7 @@ public class TestSessionInOutBuffers {
public void testWriteFromChannel() throws Exception {
byte[] pattern = "0123456789ABCDEF0123456789ABCDEF".getBytes("US-ASCII");
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(4096, 1024, null, null, null, this.allocator);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(4096, 1024, null, this.allocator);
outbuf.write(ByteBuffer.wrap(pattern, 0, 16));
outbuf.write(ByteBuffer.wrap(pattern, 16, 10));
outbuf.write(ByteBuffer.wrap(pattern, 26, 6));
@@ -424,7 +426,8 @@ public class TestSessionInOutBuffers {
String s2 = constructString(RUSSIAN_HELLO);
String s3 = "Like hello and stuff";
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, Consts.UTF_8, null, null, this.allocator);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16,
+ Consts.UTF_8.newEncoder(), this.allocator);
for (int i = 0; i < 10; i++) {
outbuf.writeLine(s1);
@@ -439,7 +442,8 @@ public class TestSessionInOutBuffers {
byte[] tmp = outstream.toByteArray();
ReadableByteChannel channel = newChannel(tmp);
- SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, Consts.UTF_8, null, null, this.allocator);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16,
+ Consts.UTF_8.newDecoder(), this.allocator);
while (inbuf.fill(channel) > 0) {
}
@@ -454,7 +458,7 @@ public class TestSessionInOutBuffers {
@Test
public void testInputMatchesBufferLength() throws Exception {
String s1 = "abcde";
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 5, null, null, null, this.allocator);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 5, null, this.allocator);
outbuf.writeLine(s1);
}
@@ -463,8 +467,10 @@ public class TestSessionInOutBuffers {
String s = constructString(SWISS_GERMAN_HELLO);
byte[] tmp = s.getBytes("ISO-8859-1");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, Consts.UTF_8,
- CodingErrorAction.REPORT, CodingErrorAction.IGNORE, this.allocator);
+ CharsetDecoder decoder = Consts.UTF_8.newDecoder();
+ decoder.onMalformedInput(CodingErrorAction.REPORT);
+ decoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, decoder, this.allocator);
ReadableByteChannel channel = newChannel(tmp);
while (inbuf.fill(channel) > 0) {
}
@@ -476,8 +482,10 @@ public class TestSessionInOutBuffers {
String s = constructString(SWISS_GERMAN_HELLO);
byte[] tmp = s.getBytes("ISO-8859-1");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, Consts.UTF_8,
- CodingErrorAction.IGNORE, CodingErrorAction.IGNORE, this.allocator);
+ CharsetDecoder decoder = Consts.UTF_8.newDecoder();
+ decoder.onMalformedInput(CodingErrorAction.IGNORE);
+ decoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, decoder, this.allocator);
ReadableByteChannel channel = newChannel(tmp);
while (inbuf.fill(channel) > 0) {
}
@@ -490,8 +498,10 @@ public class TestSessionInOutBuffers {
String s = constructString(SWISS_GERMAN_HELLO);
byte[] tmp = s.getBytes("ISO-8859-1");
- SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, Consts.UTF_8,
- CodingErrorAction.REPLACE, CodingErrorAction.IGNORE, this.allocator);
+ CharsetDecoder decoder = Consts.UTF_8.newDecoder();
+ decoder.onMalformedInput(CodingErrorAction.REPLACE);
+ decoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
+ SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, decoder, this.allocator);
ReadableByteChannel channel = newChannel(tmp);
while (inbuf.fill(channel) > 0) {
}
@@ -502,16 +512,20 @@ public class TestSessionInOutBuffers {
@Test(expected=CharacterCodingException.class)
public void testUnmappableInputActionReport() throws Exception {
String s = "This text contains a circumflex \u0302!!!";
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, Consts.ISO_8859_1,
- CodingErrorAction.IGNORE, CodingErrorAction.REPORT, this.allocator);
+ CharsetEncoder encoder = Consts.ISO_8859_1.newEncoder();
+ encoder.onMalformedInput(CodingErrorAction.IGNORE);
+ encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, encoder, this.allocator);
outbuf.writeLine(s);
}
@Test
public void testUnmappableInputActionIgnore() throws Exception {
String s = "This text contains a circumflex \u0302!!!";
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, Consts.ISO_8859_1,
- CodingErrorAction.IGNORE, CodingErrorAction.IGNORE, this.allocator);
+ CharsetEncoder encoder = Consts.ISO_8859_1.newEncoder();
+ encoder.onMalformedInput(CodingErrorAction.IGNORE);
+ encoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, encoder, this.allocator);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WritableByteChannel channel = newChannel(baos);
outbuf.writeLine(s);
@@ -524,8 +538,10 @@ public class TestSessionInOutBuffers {
@Test
public void testUnmappableInputActionReplace() throws Exception {
String s = "This text contains a circumflex \u0302 !!!";
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, Consts.ISO_8859_1,
- CodingErrorAction.IGNORE, CodingErrorAction.REPLACE, this.allocator);
+ CharsetEncoder encoder = Consts.ISO_8859_1.newEncoder();
+ encoder.onMalformedInput(CodingErrorAction.IGNORE);
+ encoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, encoder, this.allocator);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WritableByteChannel channel = newChannel(baos);
outbuf.writeLine(s);
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/util/TestBuffers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/util/TestBuffers.java?rev=1385341&r1=1385340&r2=1385341&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/util/TestBuffers.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/util/TestBuffers.java Sun Sep 16 18:44:51 2012
@@ -34,6 +34,7 @@ import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
+import org.apache.http.Consts;
import org.apache.http.ReadableByteChannelMock;
import org.apache.http.impl.io.HttpTransportMetricsImpl;
import org.apache.http.impl.nio.reactor.SessionOutputBufferImpl;
@@ -88,7 +89,7 @@ public class TestBuffers {
public void testOutputBufferOperations() throws IOException {
ByteArrayOutputStream outstream = new ByteArrayOutputStream();
WritableByteChannel channel = Channels.newChannel(outstream);
- SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128);
+ SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, Consts.ASCII);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
ContentEncoder encoder = new ContentEncoderMock(channel, outbuf, metrics);
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java?rev=1385341&r1=1385340&r2=1385341&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java Sun Sep 16 18:44:51 2012
@@ -35,6 +35,8 @@ import java.net.SocketAddress;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
import java.nio.charset.CodingErrorAction;
import org.apache.http.Consts;
@@ -91,25 +93,31 @@ public class BHttpConnectionBase impleme
if (buffersize <= 0) {
buffersize = 4096;
}
+ int maxLineLen = params.getIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, -1);
+ int minChunkLimit = params.getIntParameter(CoreConnectionPNames.MIN_CHUNK_LIMIT, -1);
+ CharsetDecoder decoder = null;
+ CharsetEncoder encoder = null;
Charset charset = CharsetUtils.lookup(
(String) params.getParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET));
- if (charset == null) {
+ if (charset != null) {
charset = Consts.ASCII;
+ decoder = charset.newDecoder();
+ encoder = charset.newEncoder();
+ CodingErrorAction malformedCharAction = (CodingErrorAction) params.getParameter(
+ CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION);
+ CodingErrorAction unmappableCharAction = (CodingErrorAction) params.getParameter(
+ CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION);
+ decoder.onMalformedInput(malformedCharAction);
+ decoder.onUnmappableCharacter(unmappableCharAction);
+ encoder.onMalformedInput(malformedCharAction);
+ encoder.onUnmappableCharacter(unmappableCharAction);
}
- int maxLineLen = params.getIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, -1);
- int minChunkLimit = params.getIntParameter(CoreConnectionPNames.MIN_CHUNK_LIMIT, -1);
- CodingErrorAction malformedCharAction = (CodingErrorAction) params.getParameter(
- CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION);
- CodingErrorAction unmappableCharAction = (CodingErrorAction) params.getParameter(
- CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION);
this.inTransportMetrics = createTransportMetrics();
this.outTransportMetrics = createTransportMetrics();
this.inbuffer = new SessionInputBufferImpl(
- this.inTransportMetrics, buffersize, maxLineLen, minChunkLimit,
- charset, malformedCharAction, unmappableCharAction);
+ this.inTransportMetrics, buffersize, maxLineLen, minChunkLimit, decoder);
this.outbuffer = new SessionOutputBufferImpl(
- this.outTransportMetrics, buffersize, minChunkLimit,
- charset, malformedCharAction, unmappableCharAction);
+ this.outTransportMetrics, buffersize, minChunkLimit, encoder);
this.connMetrics = createConnectionMetrics(
this.inTransportMetrics,
this.outTransportMetrics);
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java?rev=1385341&r1=1385340&r2=1385341&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java Sun Sep 16 18:44:51 2012
@@ -31,12 +31,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
-import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CoderResult;
-import java.nio.charset.CodingErrorAction;
-import org.apache.http.Consts;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.io.BufferInfo;
import org.apache.http.io.HttpTransportMetrics;
@@ -64,17 +61,13 @@ public class SessionInputBufferImpl impl
private final HttpTransportMetricsImpl metrics;
private final byte[] buffer;
private final ByteArrayBuffer linebuffer;
- private final Charset charset;
- private final boolean ascii;
private final int maxLineLen;
private final int minChunkLimit;
- private final CodingErrorAction onMalformedCharAction;
- private final CodingErrorAction onUnmappableCharAction;
+ private final CharsetDecoder decoder;
private InputStream instream;
private int bufferpos;
private int bufferlen;
- private CharsetDecoder decoder;
private CharBuffer cbuf;
/**
@@ -89,21 +82,15 @@ public class SessionInputBufferImpl impl
* The optimal value of this parameter can be platform specific and defines a trade-off
* between performance of memory copy operations and that of native method invocation.
* If negative default chunk limited will be used.
- * @param charset charset to be used for decoding HTTP protocol elements.
- * If <code>null</code> US-ASCII will be used.
- * @param malformedCharAction action to perform upon receiving a malformed input.
- * If <code>null</code> {@link CodingErrorAction#REPORT} will be used.
- * @param unmappableCharAction action to perform upon receiving an unmappable input.
- * If <code>null</code> {@link CodingErrorAction#REPORT} will be used.
+ * @param chardecoder chardecoder to be used for decoding HTTP protocol elements.
+ * If <code>null</code> simple type cast will be used for byte to char conversion.
*/
public SessionInputBufferImpl(
final HttpTransportMetricsImpl metrics,
int buffersize,
int maxLineLen,
int minChunkLimit,
- final Charset charset,
- final CodingErrorAction malformedCharAction,
- final CodingErrorAction unmappableCharAction) {
+ final CharsetDecoder chardecoder) {
Args.positive(buffersize, "Buffer size");
Args.notNull(metrics, "HTTP transport metrcis");
this.metrics = metrics;
@@ -113,13 +100,7 @@ public class SessionInputBufferImpl impl
this.maxLineLen = maxLineLen >= 0 ? maxLineLen : -1;
this.minChunkLimit = minChunkLimit >= 0 ? minChunkLimit : 512;
this.linebuffer = new ByteArrayBuffer(buffersize);
- this.charset = charset != null ? charset : Consts.ASCII;
- this.ascii = this.charset.equals(Consts.ASCII);
- this.decoder = null;
- this.onMalformedCharAction = malformedCharAction != null ? malformedCharAction :
- CodingErrorAction.REPORT;
- this.onUnmappableCharAction = unmappableCharAction != null? unmappableCharAction :
- CodingErrorAction.REPORT;
+ this.decoder = chardecoder;
}
public void bind(final InputStream instream) {
@@ -313,7 +294,7 @@ public class SessionInputBufferImpl impl
}
}
}
- if (this.ascii) {
+ if (this.decoder == null) {
charbuffer.append(this.linebuffer, 0, len);
} else {
ByteBuffer bbuf = ByteBuffer.wrap(this.linebuffer.buffer(), 0, len);
@@ -333,7 +314,7 @@ public class SessionInputBufferImpl impl
pos--;
}
len = pos - off;
- if (this.ascii) {
+ if (this.decoder == null) {
charbuffer.append(this.buffer, off, len);
} else {
ByteBuffer bbuf = ByteBuffer.wrap(this.buffer, off, len);
@@ -347,11 +328,6 @@ public class SessionInputBufferImpl impl
if (!bbuf.hasRemaining()) {
return 0;
}
- if (this.decoder == null) {
- this.decoder = this.charset.newDecoder();
- this.decoder.onMalformedInput(this.onMalformedCharAction);
- this.decoder.onUnmappableCharacter(this.onUnmappableCharAction);
- }
if (this.cbuf == null) {
this.cbuf = CharBuffer.allocate(1024);
}