hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1385158 - in /httpcomponents/httpcore/trunk: httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/ httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/ httpcore/src/test/java/org/apache/http/impl/io/
Date Sat, 15 Sep 2012 19:51:55 GMT
Author: olegk
Date: Sat Sep 15 19:51:54 2012
New Revision: 1385158

URL: http://svn.apache.org/viewvc?rev=1385158&view=rev
Log:
Per default use simple type cast instead of a char codec when converting from byte to char
and back in order to reduce intermediate buffer copying and improve performance

Modified:
    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/reactor/TestSessionInOutBuffers.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/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=1385158&r1=1385157&r2=1385158&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
Sat Sep 15 19:51:54 2012
@@ -59,9 +59,10 @@ import org.apache.http.util.CharArrayBuf
 @NotThreadSafe
 public class SessionInputBufferImpl extends ExpandableBuffer implements SessionInputBuffer
{
 
-    private CharBuffer charbuffer = null;
-    private Charset charset = null;
-    private CharsetDecoder chardecoder = null;
+    private final CharBuffer charbuffer;
+    private final Charset charset;
+    private final boolean ascii;
+    private final CharsetDecoder chardecoder;
 
     /**
      *  Creates SessionInputBufferImpl instance.
@@ -89,6 +90,7 @@ public class SessionInputBufferImpl exte
         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);
@@ -110,6 +112,7 @@ public class SessionInputBufferImpl exte
         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);
@@ -242,44 +245,59 @@ public class SessionInputBufferImpl exte
         int origLimit = this.buffer.limit();
         this.buffer.limit(pos);
 
-        int len = this.buffer.limit() - this.buffer.position();
+        int requiredCapacity = this.buffer.limit() - this.buffer.position();
         // Ensure capacity of len assuming ASCII as the most likely charset
-        linebuffer.ensureCapacity(len);
+        linebuffer.ensureCapacity(requiredCapacity);
 
-        this.chardecoder.reset();
+        if (this.ascii) {
+            if (this.buffer.hasArray()) {
+                byte[] b = this.buffer.array();
+                int off = this.buffer.position();
+                int len = this.buffer.remaining();
+                linebuffer.append(b, off, len);
+                this.buffer.position(off + len);
+            } else {
+                while (this.buffer.hasRemaining()) {
+                    linebuffer.append((char) (this.buffer.get() & 0xff));
+                }
+            }
+        } else {
+            this.chardecoder.reset();
 
-        for (;;) {
-            CoderResult result = this.chardecoder.decode(
-                    this.buffer,
-                    this.charbuffer,
-                    true);
-            if (result.isError()) {
-                result.throwException();
+            for (;;) {
+                CoderResult result = this.chardecoder.decode(
+                        this.buffer,
+                        this.charbuffer,
+                        true);
+                if (result.isError()) {
+                    result.throwException();
+                }
+                if (result.isOverflow()) {
+                    this.charbuffer.flip();
+                    linebuffer.append(
+                            this.charbuffer.array(),
+                            this.charbuffer.position(),
+                            this.charbuffer.remaining());
+                    this.charbuffer.clear();
+                }
+                if (result.isUnderflow()) {
+                    break;
+                }
             }
-            if (result.isOverflow()) {
-                this.charbuffer.flip();
+
+            // flush the decoder
+            this.chardecoder.flush(this.charbuffer);
+            this.charbuffer.flip();
+            // append the decoded content to the line buffer
+            if (this.charbuffer.hasRemaining()) {
                 linebuffer.append(
                         this.charbuffer.array(),
                         this.charbuffer.position(),
                         this.charbuffer.remaining());
-                this.charbuffer.clear();
-            }
-            if (result.isUnderflow()) {
-                break;
             }
-        }
-        this.buffer.limit(origLimit);
 
-        // flush the decoder
-        this.chardecoder.flush(this.charbuffer);
-        this.charbuffer.flip();
-        // append the decoded content to the line buffer
-        if (this.charbuffer.hasRemaining()) {
-            linebuffer.append(
-                    this.charbuffer.array(),
-                    this.charbuffer.position(),
-                    this.charbuffer.remaining());
         }
+        this.buffer.limit(origLimit);
 
         // discard LF if found
         int l = linebuffer.length();

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=1385158&r1=1385157&r2=1385158&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
Sat Sep 15 19:51:54 2012
@@ -61,9 +61,10 @@ public class SessionOutputBufferImpl ext
 
     private static final byte[] CRLF = new byte[] {HTTP.CR, HTTP.LF};
 
-    private CharBuffer charbuffer = null;
-    private Charset charset = null;
-    private CharsetEncoder charencoder = null;
+    private final CharBuffer charbuffer;
+    private final Charset charset;
+    private final boolean ascii;
+    private final CharsetEncoder charencoder;
 
     /**
      *  Creates SessionOutputBufferImpl instance.
@@ -91,6 +92,7 @@ public class SessionOutputBufferImpl ext
         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);
@@ -112,6 +114,7 @@ public class SessionOutputBufferImpl ext
         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);
@@ -203,27 +206,60 @@ public class SessionOutputBufferImpl ext
         if (linebuffer == null) {
             return;
         }
+        setInputMode();
         // Do not bother if the buffer is empty
         if (linebuffer.length() > 0 ) {
-            setInputMode();
-            this.charencoder.reset();
-            // transfer the string in small chunks
-            int remaining = linebuffer.length();
-            int offset = 0;
-            while (remaining > 0) {
-                int l = this.charbuffer.remaining();
-                boolean eol = false;
-                if (remaining <= l) {
-                    l = remaining;
-                    // terminate the encoding process
-                    eol = true;
+            if (this.ascii) {
+                int requiredCapacity = this.buffer.position() + linebuffer.length();
+                ensureCapacity(requiredCapacity);
+                if (this.buffer.hasArray()) {
+                    byte[] b = this.buffer.array();
+                    int len = linebuffer.length();
+                    int off = this.buffer.position();
+                    for (int i = 0; i < len; i++) {
+                        b[off + i]  = (byte) linebuffer.charAt(i);
+                    }
+                    this.buffer.position(off + len);
+                } else {
+                    for (int i = 0; i < linebuffer.length(); i++) {
+                        this.buffer.put((byte) linebuffer.charAt(i));
+                    }
                 }
-                this.charbuffer.put(linebuffer.buffer(), offset, l);
-                this.charbuffer.flip();
+            } else {
+                this.charencoder.reset();
+                // transfer the string in small chunks
+                int remaining = linebuffer.length();
+                int offset = 0;
+                while (remaining > 0) {
+                    int l = this.charbuffer.remaining();
+                    boolean eol = false;
+                    if (remaining <= l) {
+                        l = remaining;
+                        // terminate the encoding process
+                        eol = true;
+                    }
+                    this.charbuffer.put(linebuffer.buffer(), offset, l);
+                    this.charbuffer.flip();
 
+                    boolean retry = true;
+                    while (retry) {
+                        CoderResult result = this.charencoder.encode(this.charbuffer, this.buffer,
eol);
+                        if (result.isError()) {
+                            result.throwException();
+                        }
+                        if (result.isOverflow()) {
+                            expand();
+                        }
+                        retry = !result.isUnderflow();
+                    }
+                    this.charbuffer.compact();
+                    offset += l;
+                    remaining -= l;
+                }
+                // flush the encoder
                 boolean retry = true;
                 while (retry) {
-                    CoderResult result = this.charencoder.encode(this.charbuffer, this.buffer,
eol);
+                    CoderResult result = this.charencoder.flush(this.buffer);
                     if (result.isError()) {
                         result.throwException();
                     }
@@ -232,21 +268,6 @@ public class SessionOutputBufferImpl ext
                     }
                     retry = !result.isUnderflow();
                 }
-                this.charbuffer.compact();
-                offset += l;
-                remaining -= l;
-            }
-            // flush the encoder
-            boolean retry = true;
-            while (retry) {
-                CoderResult result = this.charencoder.flush(this.buffer);
-                if (result.isError()) {
-                    result.throwException();
-                }
-                if (result.isOverflow()) {
-                    expand();
-                }
-                retry = !result.isUnderflow();
             }
         }
         writeCRLF();

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=1385158&r1=1385157&r2=1385158&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
Sat Sep 15 19:51:54 2012
@@ -36,19 +36,43 @@ import java.nio.channels.ReadableByteCha
 import java.nio.channels.WritableByteChannel;
 import java.nio.charset.CharacterCodingException;
 import java.nio.charset.CodingErrorAction;
+import java.util.Arrays;
+import java.util.Collection;
 
 import org.apache.http.Consts;
 import org.apache.http.nio.reactor.SessionInputBuffer;
 import org.apache.http.nio.reactor.SessionOutputBuffer;
+import org.apache.http.nio.util.ByteBufferAllocator;
+import org.apache.http.nio.util.DirectByteBufferAllocator;
+import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.util.CharArrayBuffer;
 import org.junit.Assert;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
 
 /**
  * Simple tests for {@link SessionInputBuffer} and {@link SessionOutputBuffer}.
  */
+@RunWith(Parameterized.class)
 public class TestSessionInOutBuffers {
 
+    private ByteBufferAllocator allocator;
+    
+    public TestSessionInOutBuffers(final ByteBufferAllocator allocator) {
+        super();
+        this.allocator = allocator;
+    }
+    
+    @Parameters
+    public static Collection<Object[]> getParameters() {
+        
+        return Arrays.asList(
+                new Object[] { HeapByteBufferAllocator.INSTANCE }, 
+                new Object[] { DirectByteBufferAllocator.INSTANCE });
+    }
+    
     private static WritableByteChannel newChannel(final ByteArrayOutputStream outstream)
{
         return Channels.newChannel(outstream);
     }
@@ -69,7 +93,7 @@ public class TestSessionInOutBuffers {
 
     @Test
     public void testReadLineChunks() throws Exception {
-        SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16);
+        SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, null, null, null, this.allocator);
 
         ReadableByteChannel channel = newChannel("One\r\nTwo\r\nThree");
 
@@ -107,8 +131,8 @@ public class TestSessionInOutBuffers {
 
     @Test
     public void testWriteLineChunks() throws Exception {
-        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(16, 16);
-        SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16);
+        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(16, 16, null, null, null,
this.allocator);
+        SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, null, null, null, this.allocator);
 
         ReadableByteChannel inChannel = newChannel("One\r\nTwo\r\nThree");
 
@@ -175,7 +199,7 @@ public class TestSessionInOutBuffers {
         teststrs[3] = "";
         teststrs[4] = "And goodbye";
 
-        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16);
+        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, null, null, null,
this.allocator);
         for (int i = 0; i < teststrs.length; i++) {
             outbuf.writeLine(teststrs[i]);
         }
@@ -189,7 +213,7 @@ public class TestSessionInOutBuffers {
 
         ReadableByteChannel channel = newChannel(outstream.toByteArray());
 
-        SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 16);
+        SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 16, null, null, null,
this.allocator);
         inbuf.fill(channel);
 
         for (int i = 0; i < teststrs.length; i++) {
@@ -201,7 +225,7 @@ public class TestSessionInOutBuffers {
 
     @Test
     public void testComplexReadWriteLine() throws Exception {
-        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16);
+        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, null, null, 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'}));
@@ -239,7 +263,7 @@ public class TestSessionInOutBuffers {
 
         ReadableByteChannel channel = newChannel(outstream.toByteArray());
 
-        SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 16);
+        SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 16, null, null, null,
this.allocator);
         inbuf.fill(channel);
 
         Assert.assertEquals("a", inbuf.readLine(true));
@@ -262,7 +286,7 @@ public class TestSessionInOutBuffers {
             out[i] = (byte)('0' + i);
         }
         ReadableByteChannel channel = newChannel(out);
-        SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16);
+        SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, null, null, null, this.allocator);
         while (inbuf.fill(channel) > 0) {
         }
 
@@ -279,7 +303,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);
+        SessionInputBuffer inbuf = new SessionInputBufferImpl(4096, 1024, null, null, null,
this.allocator);
         while (inbuf.fill(channel) > 0) {
         }
         ByteBuffer dst = ByteBuffer.allocate(10);
@@ -296,7 +320,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);
+        SessionInputBuffer inbuf = new SessionInputBufferImpl(4096, 1024, null, null, null,
this.allocator);
         while (inbuf.fill(channel) > 0) {
         }
         ByteBuffer dst = ByteBuffer.allocate(16);
@@ -316,7 +340,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);
+        SessionInputBuffer inbuf = new SessionInputBufferImpl(4096, 1024, null, null, null,
this.allocator);
         while (inbuf.fill(channel) > 0) {
         }
 
@@ -331,7 +355,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);
+        SessionInputBuffer inbuf = new SessionInputBufferImpl(4096, 1024, null, null, null,
this.allocator);
         while (inbuf.fill(channel) > 0) {
         }
 
@@ -348,7 +372,7 @@ public class TestSessionInOutBuffers {
     public void testWriteByteBuffer() throws Exception {
         byte[] pattern = "0123456789ABCDEF0123456789ABCDEF".getBytes("US-ASCII");
 
-        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(4096, 1024);
+        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(4096, 1024, null, null,
null, this.allocator);
         ReadableByteChannel src = newChannel(pattern);
         outbuf.write(src);
 
@@ -363,7 +387,7 @@ public class TestSessionInOutBuffers {
     public void testWriteFromChannel() throws Exception {
         byte[] pattern = "0123456789ABCDEF0123456789ABCDEF".getBytes("US-ASCII");
 
-        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(4096, 1024);
+        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(4096, 1024, null, null,
null, this.allocator);
         outbuf.write(ByteBuffer.wrap(pattern, 0, 16));
         outbuf.write(ByteBuffer.wrap(pattern, 16, 10));
         outbuf.write(ByteBuffer.wrap(pattern, 26, 6));
@@ -400,7 +424,7 @@ 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);
+        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, Consts.UTF_8,
null, null, this.allocator);
 
         for (int i = 0; i < 10; i++) {
             outbuf.writeLine(s1);
@@ -415,7 +439,7 @@ public class TestSessionInOutBuffers {
         byte[] tmp = outstream.toByteArray();
 
         ReadableByteChannel channel = newChannel(tmp);
-        SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, Consts.UTF_8, null,
null);
+        SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, Consts.UTF_8, null,
null, this.allocator);
 
         while (inbuf.fill(channel) > 0) {
         }
@@ -428,32 +452,9 @@ public class TestSessionInOutBuffers {
     }
 
     @Test
-    public void testMalformedCharacters() throws Exception {
-        String s1 = constructString(SWISS_GERMAN_HELLO);
-        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16);
-        try {
-            outbuf.writeLine(s1);
-            Assert.fail("Expected CharacterCodingException");
-        } catch (CharacterCodingException expected) {
-        }
-
-        byte[] tmp = s1.getBytes("ISO-8859-1");
-        ReadableByteChannel channel = newChannel(tmp);
-        SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16);
-        while (inbuf.fill(channel) > 0) {
-        }
-
-        try {
-            String s = inbuf.readLine(true);
-            Assert.fail("Expected CharacterCodingException, got '" + s + "'");
-        } catch (CharacterCodingException expected) {
-        }
-    }
-
-    @Test
     public void testInputMatchesBufferLength() throws Exception {
         String s1 = "abcde";
-        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 5);
+        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 5, null, null, null,
this.allocator);
         outbuf.writeLine(s1);
     }
 
@@ -462,8 +463,8 @@ public class TestSessionInOutBuffers {
         String s = constructString(SWISS_GERMAN_HELLO);
         byte[] tmp = s.getBytes("ISO-8859-1");
 
-        SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, Consts.ASCII,
-                CodingErrorAction.REPORT, CodingErrorAction.IGNORE);
+        SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, Consts.UTF_8,
+                CodingErrorAction.REPORT, CodingErrorAction.IGNORE, this.allocator);
         ReadableByteChannel channel = newChannel(tmp);
         while (inbuf.fill(channel) > 0) {
         }
@@ -475,8 +476,8 @@ public class TestSessionInOutBuffers {
         String s = constructString(SWISS_GERMAN_HELLO);
         byte[] tmp = s.getBytes("ISO-8859-1");
 
-        SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, Consts.ASCII,
-                CodingErrorAction.IGNORE, CodingErrorAction.IGNORE);
+        SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, Consts.UTF_8,
+                CodingErrorAction.IGNORE, CodingErrorAction.IGNORE, this.allocator);
         ReadableByteChannel channel = newChannel(tmp);
         while (inbuf.fill(channel) > 0) {
         }
@@ -489,8 +490,8 @@ public class TestSessionInOutBuffers {
         String s = constructString(SWISS_GERMAN_HELLO);
         byte[] tmp = s.getBytes("ISO-8859-1");
 
-        SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, Consts.ASCII,
-                CodingErrorAction.REPLACE, CodingErrorAction.IGNORE);
+        SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, Consts.UTF_8,
+                CodingErrorAction.REPLACE, CodingErrorAction.IGNORE, this.allocator);
         ReadableByteChannel channel = newChannel(tmp);
         while (inbuf.fill(channel) > 0) {
         }
@@ -500,38 +501,38 @@ public class TestSessionInOutBuffers {
 
     @Test(expected=CharacterCodingException.class)
     public void testUnmappableInputActionReport() throws Exception {
-        String s = constructString(SWISS_GERMAN_HELLO);
-        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, Consts.ASCII,
-                CodingErrorAction.IGNORE, CodingErrorAction.REPORT);
+        String s = "This text contains a circumflex \u0302!!!";
+        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, Consts.ISO_8859_1,
+                CodingErrorAction.IGNORE, CodingErrorAction.REPORT, this.allocator);
         outbuf.writeLine(s);
     }
 
     @Test
     public void testUnmappableInputActionIgnore() throws Exception {
-        String s = constructString(SWISS_GERMAN_HELLO);
-        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, Consts.ASCII,
-                CodingErrorAction.IGNORE, CodingErrorAction.IGNORE);
+        String s = "This text contains a circumflex \u0302!!!";
+        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, Consts.ISO_8859_1,
+                CodingErrorAction.IGNORE, CodingErrorAction.IGNORE, this.allocator);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         WritableByteChannel channel = newChannel(baos);
         outbuf.writeLine(s);
         outbuf.flush(channel);
 
         String result = new String(baos.toByteArray(), "US-ASCII");
-        Assert.assertEquals("Grezi_zm\r\n", result);
+        Assert.assertEquals("This text contains a circumflex !!!\r\n", result);
     }
 
     @Test
     public void testUnmappableInputActionReplace() throws Exception {
-        String s = constructString(SWISS_GERMAN_HELLO);
-        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, Consts.ASCII,
-                CodingErrorAction.IGNORE, CodingErrorAction.REPLACE);
+        String s = "This text contains a circumflex \u0302 !!!";
+        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, Consts.ISO_8859_1,
+                CodingErrorAction.IGNORE, CodingErrorAction.REPLACE, this.allocator);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         WritableByteChannel channel = newChannel(baos);
         outbuf.writeLine(s);
         outbuf.flush(channel);
 
         String result = new String(baos.toByteArray(), "US-ASCII");
-        Assert.assertEquals("Gr?ezi_z?m?\r\n", result);
+        Assert.assertEquals("This text contains a circumflex ? !!!\r\n", result);
     }
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestSessionInOutBuffers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestSessionInOutBuffers.java?rev=1385158&r1=1385157&r2=1385158&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestSessionInOutBuffers.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestSessionInOutBuffers.java
Sat Sep 15 19:51:54 2012
@@ -484,7 +484,7 @@ public class TestSessionInOutBuffers {
 
     @Test(expected=CharacterCodingException.class)
     public void testUnmappableInputActionReport() throws Exception {
-        String s = "This text contains a circumflex \u0302!!!";
+        String s = "This text contains a circumflex \u0302 !!!";
         SessionOutputBufferMock outbuf = new SessionOutputBufferMock(Consts.ISO_8859_1,
                 CodingErrorAction.IGNORE, CodingErrorAction.REPORT);
         outbuf.writeLine(s);
@@ -530,7 +530,7 @@ public class TestSessionInOutBuffers {
     }
 
     @Test
-    public void testBufferMalformedInputActionIgnore() throws Exception {
+    public void testMalformedInputActionIgnore() throws Exception {
         byte[] tmp = constructString(SWISS_GERMAN_HELLO).getBytes(Consts.ISO_8859_1.name());
         SessionInputBufferMock inbuffer = new SessionInputBufferMock(tmp, Consts.UTF_8,
                 CodingErrorAction.IGNORE, CodingErrorAction.IGNORE);



Mime
View raw message