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 2005/08/21 21:54:47 UTC
svn commit: r234331 - in
/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/io:
NIOHttpDataReceiver.java NIOHttpDataTransmitter.java
Author: olegk
Date: Sun Aug 21 12:54:42 2005
New Revision: 234331
URL: http://svn.apache.org/viewcvs?rev=234331&view=rev
Log:
Changed to keep char encoder / decoder
Modified:
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/io/NIOHttpDataReceiver.java
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/io/NIOHttpDataTransmitter.java
Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/io/NIOHttpDataReceiver.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/io/NIOHttpDataReceiver.java?rev=234331&r1=234330&r2=234331&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/io/NIOHttpDataReceiver.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/io/NIOHttpDataReceiver.java Sun Aug 21 12:54:42 2005
@@ -58,6 +58,7 @@
private ByteBuffer buffer = null;
private Charset charset = null;
+ private CharsetDecoder chardecoder;
protected void initBuffer(int buffersize) {
if (buffersize < 2048) {
@@ -66,10 +67,12 @@
this.buffer = ByteBuffer.allocateDirect(buffersize);
this.buffer.flip();
this.charset = Charset.forName("US-ASCII");
+ this.chardecoder = createCharDecoder();
}
public void reset(final HttpParams params) {
this.charset = Charset.forName(HttpProtocolParams.getHttpElementCharset(params));
+ this.chardecoder = createCharDecoder();
}
private CharsetDecoder createCharDecoder() {
@@ -145,9 +148,9 @@
public String readLine() throws IOException {
int noRead = 0;
- CharsetDecoder chardecoder = createCharDecoder();
+ this.chardecoder.reset();
StringBuffer line = new StringBuffer();
- CharBuffer tmp = CharBuffer.allocate(128);
+ CharBuffer tmp = CharBuffer.allocate(1024);
boolean retry = true;
while (retry) {
// attempt to find end of line (LF)
@@ -159,7 +162,7 @@
int origLimit = this.buffer.limit();
this.buffer.limit(i + 1);
for (;;) {
- CoderResult result = chardecoder.decode(this.buffer, tmp, true);
+ CoderResult result = this.chardecoder.decode(this.buffer, tmp, true);
if (result.isOverflow()) {
tmp.flip();
line.append(tmp.array(), tmp.position(), tmp.remaining());
@@ -174,14 +177,14 @@
// end of line not found
if (this.buffer.hasRemaining()) {
// decode the entire buffer content
- chardecoder.decode(this.buffer, tmp, false);
+ this.chardecoder.decode(this.buffer, tmp, false);
}
// discard the decoded content
noRead = fillBuffer();
if (noRead == -1) {
retry = false;
// terminate the decoding process
- chardecoder.decode(this.buffer, tmp, true);
+ this.chardecoder.decode(this.buffer, tmp, true);
}
}
// append the decoded content to the line buffer
@@ -192,7 +195,7 @@
tmp.clear();
}
// flush the decoder
- chardecoder.flush(tmp);
+ this.chardecoder.flush(tmp);
tmp.flip();
// append the decoded content to the line buffer
if (tmp.hasRemaining()) {
Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/io/NIOHttpDataTransmitter.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/io/NIOHttpDataTransmitter.java?rev=234331&r1=234330&r2=234331&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/io/NIOHttpDataTransmitter.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/io/NIOHttpDataTransmitter.java Sun Aug 21 12:54:42 2005
@@ -59,6 +59,7 @@
private ByteBuffer buffer = null;
private Charset charset = null;
+ private CharsetEncoder charencoder = null;
protected void initBuffer(int buffersize) {
if (buffersize < 2048) {
@@ -66,10 +67,12 @@
}
this.buffer = ByteBuffer.allocateDirect(buffersize);
this.charset = Charset.forName("US-ASCII");
+ this.charencoder = createCharEncoder();
}
public void reset(final HttpParams params) {
this.charset = Charset.forName(HttpProtocolParams.getHttpElementCharset(params));
+ this.charencoder = createCharEncoder();
}
protected abstract void writeToChannel(ByteBuffer src) throws IOException;
@@ -167,8 +170,8 @@
}
// Do not bother if the string is empty
if (s.length() > 0 ) {
- CharsetEncoder charencoder = createCharEncoder();
- CharBuffer tmp = CharBuffer.allocate(128);
+ this.charencoder.reset();
+ CharBuffer tmp = CharBuffer.allocate(1024);
// transfer the string in small chunks
int remaining = s.length();
int offset = 0;
@@ -182,13 +185,13 @@
}
tmp.put(s, offset, offset + l);
tmp.flip();
- write(charencoder, tmp, eol);
+ write(this.charencoder, tmp, eol);
tmp.compact();
offset += l;
remaining -= l;
}
// flush the encoder
- flushCharEncoder(charencoder);
+ flushCharEncoder(this.charencoder);
}
writeCRLF();
}