hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1636718 - in /httpcomponents/httpcore/trunk: httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/ httpcore-nio/src/main/java/org/apache/http/nio/reactor/ httpcore-nio/src/test/java/org/apache/http/impl/nio/ httpcore-nio/src/test/ja...
Date Tue, 04 Nov 2014 20:03:43 GMT
Author: olegk
Date: Tue Nov  4 20:03:42 2014
New Revision: 1636718

URL: http://svn.apache.org/r1636718
Log:
Always use CharArrayBuffer when reading from / writing to session input / output buffers

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/main/java/org/apache/http/nio/reactor/SessionInputBuffer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/SessionOutputBuffer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestNHttpConnectionBase.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/TestLengthDelimitedEncoder.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestSessionInOutBuffers.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/ChunkedOutputStream.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/main/java/org/apache/http/io/SessionInputBuffer.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/SessionOutputBuffer.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=1636718&r1=1636717&r2=1636718&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 Tue Nov  4 20:03:42 2014
@@ -335,15 +335,4 @@ public class SessionInputBufferImpl exte
         return true;
     }
 
-    @Override
-    public String readLine(final boolean endOfStream) throws CharacterCodingException {
-        final CharArrayBuffer buffer = new CharArrayBuffer(64);
-        final boolean found = readLine(buffer, endOfStream);
-        if (found) {
-            return buffer.toString();
-        } else {
-            return null;
-        }
-    }
-
 }

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=1636718&r1=1636717&r2=1636718&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 Tue Nov  4 20:03:42 2014
@@ -230,18 +230,4 @@ public class SessionOutputBufferImpl ext
         writeCRLF();
     }
 
-    @Override
-    public void writeLine(final String s) throws IOException {
-        if (s == null) {
-            return;
-        }
-        if (s.length() > 0) {
-            final CharArrayBuffer tmp = new CharArrayBuffer(s.length());
-            tmp.append(s);
-            writeLine(tmp);
-        } else {
-            write(CRLF);
-        }
-    }
-
 }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/SessionInputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/SessionInputBuffer.java?rev=1636718&r1=1636717&r2=1636718&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/SessionInputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/SessionInputBuffer.java Tue Nov  4 20:03:42 2014
@@ -154,28 +154,4 @@ public interface SessionInputBuffer {
     boolean readLine(CharArrayBuffer dst, boolean endOfStream)
         throws CharacterCodingException;
 
-    /**
-     * Attempts to transfer a complete line of characters up to a line delimiter
-     * from this buffer to a newly created string. If a complete line is
-     * available in the buffer, the sequence of chars is transferred to a newly
-     * created string. The line delimiter itself is discarded. If a complete
-     * line is not available in the buffer, this method returns
-     * {@code null}. If {@code endOfStream} parameter
-     * is set to {@code true} this method assumes the end of stream has
-     * been reached and the content currently stored in the buffer should be
-     * treated as a complete line.
-     * <p>
-     * The choice of a char encoding and line delimiter sequence is up to the
-     * specific implementations of this interface.
-     *
-     * @param endOfStream end of stream flag
-     * @return a string representing a complete line, if available.
-     * {@code null} otherwise.
-     *
-     * @throws CharacterCodingException in case a character encoding or decoding
-     *   error occurs.
-     */
-    String readLine(boolean endOfStream)
-        throws CharacterCodingException;
-
 }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/SessionOutputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/SessionOutputBuffer.java?rev=1636718&r1=1636717&r2=1636718&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/SessionOutputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/SessionOutputBuffer.java Tue Nov  4 20:03:42 2014
@@ -102,18 +102,4 @@ public interface SessionOutputBuffer {
     void writeLine(CharArrayBuffer src)
         throws CharacterCodingException;
 
-    /**
-     * Copies content of the given string into this buffer as one line of text
-     * including a line delimiter.
-     * The capacity of the destination will be expanded in order to accommodate
-     * the entire string.
-     * <p>
-     * The choice of a char encoding and line delimiter sequence is up to the
-     * specific implementations of this interface.
-     *
-     * @param s the string.
-     */
-    void writeLine(String s)
-        throws IOException;
-
 }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestNHttpConnectionBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestNHttpConnectionBase.java?rev=1636718&r1=1636717&r2=1636718&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestNHttpConnectionBase.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestNHttpConnectionBase.java Tue Nov  4 20:03:42 2014
@@ -46,6 +46,7 @@ import org.apache.http.nio.NHttpConnecti
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.protocol.HTTP;
+import org.apache.http.util.CharArrayBuffer;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -128,7 +129,9 @@ public class TestNHttpConnectionBase {
         Mockito.when(session.getRemoteAddress()).thenReturn(remote);
         Mockito.when(session.isClosed()).thenReturn(Boolean.FALSE);
 
-        conn.outbuf.writeLine("stuff");
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
+        chbuffer.append("stuff");
+        conn.outbuf.writeLine(chbuffer);
         conn.close();
 
         Assert.assertEquals(NHttpConnection.CLOSING, conn.getStatus());
@@ -150,7 +153,9 @@ public class TestNHttpConnectionBase {
         Mockito.when(session.getRemoteAddress()).thenReturn(remote);
         Mockito.when(session.isClosed()).thenReturn(Boolean.FALSE);
 
-        conn.outbuf.writeLine("stuff");
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
+        chbuffer.append("stuff");
+        conn.outbuf.writeLine(chbuffer);
         conn.shutdown();
 
         Assert.assertEquals(NHttpConnection.CLOSED, conn.getStatus());

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=1636718&r1=1636717&r2=1636718&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 Tue Nov  4 20:03:42 2014
@@ -38,6 +38,7 @@ import org.apache.http.WritableByteChann
 import org.apache.http.impl.io.HttpTransportMetricsImpl;
 import org.apache.http.impl.nio.reactor.SessionOutputBufferImpl;
 import org.apache.http.nio.reactor.SessionOutputBuffer;
+import org.apache.http.util.CharArrayBuffer;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Test;
@@ -245,7 +246,9 @@ public class TestIdentityEncoder {
 
         final IdentityEncoder encoder = new IdentityEncoder(channel, outbuf, metrics);
 
-        outbuf.writeLine("header");
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
+        chbuffer.append("header");
+        outbuf.writeLine(chbuffer);
 
         createTempFile();
         RandomAccessFile testfile = new RandomAccessFile(this.tmpfile, "rw");
@@ -277,7 +280,9 @@ public class TestIdentityEncoder {
 
         final IdentityEncoder encoder = new IdentityEncoder(channel, outbuf, metrics);
 
-        outbuf.writeLine("header");
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
+        chbuffer.append("header");
+        outbuf.writeLine(chbuffer);
 
         createTempFile();
         RandomAccessFile testfile = new RandomAccessFile(this.tmpfile, "rw");
@@ -307,7 +312,9 @@ public class TestIdentityEncoder {
         final SessionOutputBuffer outbuf = Mockito.spy(new SessionOutputBufferImpl(1024, 128));
         final HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
 
-        outbuf.writeLine("header");
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
+        chbuffer.append("header");
+        outbuf.writeLine(chbuffer);
         final IdentityEncoder encoder = new IdentityEncoder(channel, outbuf, metrics, 0);
         Assert.assertEquals(5, encoder.write(CodecTestUtils.wrap("stuff")));
 
@@ -329,7 +336,9 @@ public class TestIdentityEncoder {
         final SessionOutputBuffer outbuf = Mockito.spy(new SessionOutputBufferImpl(1024, 128));
         final HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
 
-        outbuf.writeLine("header");
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
+        chbuffer.append("header");
+        outbuf.writeLine(chbuffer);
         final IdentityEncoder encoder = new IdentityEncoder(channel, outbuf, metrics, 32);
         Assert.assertEquals(5, encoder.write(CodecTestUtils.wrap("stuff")));
 
@@ -374,7 +383,9 @@ public class TestIdentityEncoder {
         final SessionOutputBuffer outbuf = Mockito.spy(new SessionOutputBufferImpl(1024, 128));
         final HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
 
-        outbuf.writeLine("header");
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
+        chbuffer.append("header");
+        outbuf.writeLine(chbuffer);
         final IdentityEncoder encoder = new IdentityEncoder(channel, outbuf, metrics, 2);
         Assert.assertEquals(5, encoder.write(CodecTestUtils.wrap("stuff")));
 

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=1636718&r1=1636717&r2=1636718&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 Tue Nov  4 20:03:42 2014
@@ -38,6 +38,7 @@ import org.apache.http.WritableByteChann
 import org.apache.http.impl.io.HttpTransportMetricsImpl;
 import org.apache.http.impl.nio.reactor.SessionOutputBufferImpl;
 import org.apache.http.nio.reactor.SessionOutputBuffer;
+import org.apache.http.util.CharArrayBuffer;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Test;
@@ -302,7 +303,9 @@ public class TestLengthDelimitedEncoder 
         final LengthDelimitedEncoder encoder = new LengthDelimitedEncoder(
                 channel, outbuf, metrics, 16);
 
-        outbuf.writeLine("header");
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
+        chbuffer.append("header");
+        outbuf.writeLine(chbuffer);
 
         createTempFile();
         RandomAccessFile testfile = new RandomAccessFile(this.tmpfile, "rw");
@@ -335,7 +338,9 @@ public class TestLengthDelimitedEncoder 
         final LengthDelimitedEncoder encoder = new LengthDelimitedEncoder(
                 channel, outbuf, metrics, 16);
 
-        outbuf.writeLine("header");
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
+        chbuffer.append("header");
+        outbuf.writeLine(chbuffer);
 
         createTempFile();
         RandomAccessFile testfile = new RandomAccessFile(this.tmpfile, "rw");
@@ -365,7 +370,9 @@ public class TestLengthDelimitedEncoder 
         final SessionOutputBuffer outbuf = Mockito.spy(new SessionOutputBufferImpl(1024, 128));
         final HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
 
-        outbuf.writeLine("header");
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
+        chbuffer.append("header");
+        outbuf.writeLine(chbuffer);
         final LengthDelimitedEncoder encoder = new LengthDelimitedEncoder(channel, outbuf, metrics,
             100, 0);
         Assert.assertEquals(5, encoder.write(CodecTestUtils.wrap("stuff")));
@@ -388,7 +395,9 @@ public class TestLengthDelimitedEncoder 
         final SessionOutputBuffer outbuf = Mockito.spy(new SessionOutputBufferImpl(1024, 128));
         final HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
 
-        outbuf.writeLine("header");
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
+        chbuffer.append("header");
+        outbuf.writeLine(chbuffer);
         final LengthDelimitedEncoder encoder = new LengthDelimitedEncoder(channel, outbuf, metrics,
             100, 32);
         Assert.assertEquals(5, encoder.write(CodecTestUtils.wrap("stuff")));
@@ -459,7 +468,9 @@ public class TestLengthDelimitedEncoder 
         final SessionOutputBuffer outbuf = Mockito.spy(new SessionOutputBufferImpl(1024, 128));
         final HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
 
-        outbuf.writeLine("header");
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
+        chbuffer.append("header");
+        outbuf.writeLine(chbuffer);
         final LengthDelimitedEncoder encoder = new LengthDelimitedEncoder(channel, outbuf, metrics,
             100, 2);
         Assert.assertEquals(5, encoder.write(CodecTestUtils.wrap("stuff")));

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=1636718&r1=1636717&r2=1636718&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 Tue Nov  4 20:03:42 2014
@@ -250,13 +250,15 @@ public class TestSessionInOutBuffers {
         teststrs[3] = "";
         teststrs[4] = "And goodbye";
 
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(32);
         final SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, null, this.allocator);
         for (final String teststr : teststrs) {
-            outbuf.writeLine(teststr);
+            chbuffer.clear();
+            chbuffer.append(teststr);
+            outbuf.writeLine(chbuffer);
         }
         //this write operation should have no effect
-        outbuf.writeLine((String)null);
-        outbuf.writeLine((CharArrayBuffer)null);
+        outbuf.writeLine(null);
 
         final ByteArrayOutputStream outstream = new ByteArrayOutputStream();
         final WritableByteChannel outChannel = newChannel(outstream);
@@ -268,10 +270,14 @@ public class TestSessionInOutBuffers {
         inbuf.fill(channel);
 
         for (final String teststr : teststrs) {
-            Assert.assertEquals(teststr, inbuf.readLine(true));
-        }
-        Assert.assertNull(inbuf.readLine(true));
-        Assert.assertNull(inbuf.readLine(true));
+            chbuffer.clear();
+            inbuf.readLine(chbuffer, true);
+            Assert.assertEquals(teststr, chbuffer.toString());
+        }
+        chbuffer.clear();
+        Assert.assertFalse(inbuf.readLine(chbuffer, true));
+        chbuffer.clear();
+        Assert.assertFalse(inbuf.readLine(chbuffer, true));
     }
 
     @Test
@@ -317,16 +323,37 @@ public class TestSessionInOutBuffers {
         final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 16, null, this.allocator);
         inbuf.fill(channel);
 
-        Assert.assertEquals("a", inbuf.readLine(true));
-        Assert.assertEquals("", inbuf.readLine(true));
-        Assert.assertEquals("\r", inbuf.readLine(true));
-        Assert.assertEquals("", inbuf.readLine(true));
-        Assert.assertEquals(s1, inbuf.readLine(true));
-        Assert.assertEquals(s2, inbuf.readLine(true));
-        Assert.assertEquals(s3, inbuf.readLine(true));
-        Assert.assertEquals("a", inbuf.readLine(true));
-        Assert.assertNull(inbuf.readLine(true));
-        Assert.assertNull(inbuf.readLine(true));
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(32);
+        chbuffer.clear();
+        inbuf.readLine(chbuffer, true);
+        Assert.assertEquals("a", chbuffer.toString());
+        chbuffer.clear();
+        inbuf.readLine(chbuffer, true);
+        Assert.assertEquals("", chbuffer.toString());
+        chbuffer.clear();
+        inbuf.readLine(chbuffer, true);
+        Assert.assertEquals("\r", chbuffer.toString());
+        chbuffer.clear();
+        inbuf.readLine(chbuffer, true);
+        Assert.assertEquals("", chbuffer.toString());
+        chbuffer.clear();
+        inbuf.readLine(chbuffer, true);
+        Assert.assertEquals(s1, chbuffer.toString());
+        chbuffer.clear();
+        inbuf.readLine(chbuffer, true);
+        Assert.assertEquals(s2, chbuffer.toString());
+        chbuffer.clear();
+        inbuf.readLine(chbuffer, true);
+        Assert.assertEquals(s3, chbuffer.toString());
+        chbuffer.clear();
+        inbuf.readLine(chbuffer, true);
+        Assert.assertEquals("a", chbuffer.toString());
+        chbuffer.clear();
+        inbuf.readLine(chbuffer, true);
+        Assert.assertFalse(inbuf.readLine(chbuffer, true));
+        chbuffer.clear();
+        inbuf.readLine(chbuffer, true);
+        Assert.assertFalse(inbuf.readLine(chbuffer, true));
     }
 
     @Test
@@ -478,10 +505,17 @@ public class TestSessionInOutBuffers {
         final SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16,
                 Consts.UTF_8.newEncoder(), this.allocator);
 
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(32);
         for (int i = 0; i < 10; i++) {
-            outbuf.writeLine(s1);
-            outbuf.writeLine(s2);
-            outbuf.writeLine(s3);
+            chbuffer.clear();
+            chbuffer.append(s1);
+            outbuf.writeLine(chbuffer);
+            chbuffer.clear();
+            chbuffer.append(s2);
+            outbuf.writeLine(chbuffer);
+            chbuffer.clear();
+            chbuffer.append(s3);
+            outbuf.writeLine(chbuffer);
         }
 
         final ByteArrayOutputStream outstream = new ByteArrayOutputStream();
@@ -498,9 +532,15 @@ public class TestSessionInOutBuffers {
         }
 
         for (int i = 0; i < 10; i++) {
-            Assert.assertEquals(s1, inbuf.readLine(true));
-            Assert.assertEquals(s2, inbuf.readLine(true));
-            Assert.assertEquals(s3, inbuf.readLine(true));
+            chbuffer.clear();
+            inbuf.readLine(chbuffer, true);
+            Assert.assertEquals(s1, chbuffer.toString());
+            chbuffer.clear();
+            inbuf.readLine(chbuffer, true);
+            Assert.assertEquals(s2, chbuffer.toString());
+            chbuffer.clear();
+            inbuf.readLine(chbuffer, true);
+            Assert.assertEquals(s3, chbuffer.toString());
         }
     }
 
@@ -508,7 +548,9 @@ public class TestSessionInOutBuffers {
     public void testInputMatchesBufferLength() throws Exception {
         final String s1 = "abcde";
         final SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 5, null, this.allocator);
-        outbuf.writeLine(s1);
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
+        chbuffer.append(s1);
+        outbuf.writeLine(chbuffer);
     }
 
     @Test(expected=CharacterCodingException.class)
@@ -523,7 +565,8 @@ public class TestSessionInOutBuffers {
         final ReadableByteChannel channel = newChannel(tmp);
         while (inbuf.fill(channel) > 0) {
         }
-        inbuf.readLine(true);
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
+        inbuf.readLine(chbuffer, true);
     }
 
     @Test
@@ -538,8 +581,9 @@ public class TestSessionInOutBuffers {
         final ReadableByteChannel channel = newChannel(tmp);
         while (inbuf.fill(channel) > 0) {
         }
-        final String result = inbuf.readLine(true);
-        Assert.assertEquals("Grezi_zm", result);
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
+        inbuf.readLine(chbuffer, true);
+        Assert.assertEquals("Grezi_zm", chbuffer.toString());
     }
 
     @Test
@@ -554,8 +598,9 @@ public class TestSessionInOutBuffers {
         final ReadableByteChannel channel = newChannel(tmp);
         while (inbuf.fill(channel) > 0) {
         }
-        final String result = inbuf.readLine(true);
-        Assert.assertEquals("Gr\ufffdezi_z\ufffdm\ufffd", result);
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
+        inbuf.readLine(chbuffer, true);
+        Assert.assertEquals("Gr\ufffdezi_z\ufffdm\ufffd", chbuffer.toString());
     }
 
     @Test(expected=CharacterCodingException.class)
@@ -565,7 +610,9 @@ public class TestSessionInOutBuffers {
         encoder.onMalformedInput(CodingErrorAction.IGNORE);
         encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
         final SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, encoder, this.allocator);
-        outbuf.writeLine(s);
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
+        chbuffer.append(s);
+        outbuf.writeLine(chbuffer);
     }
 
     @Test
@@ -577,7 +624,9 @@ public class TestSessionInOutBuffers {
         final SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, encoder, this.allocator);
         final ByteArrayOutputStream baos = new ByteArrayOutputStream();
         final WritableByteChannel channel = newChannel(baos);
-        outbuf.writeLine(s);
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
+        chbuffer.append(s);
+        outbuf.writeLine(chbuffer);
         outbuf.flush(channel);
 
         final String result = new String(baos.toByteArray(), "US-ASCII");
@@ -593,7 +642,9 @@ public class TestSessionInOutBuffers {
         final SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, encoder, this.allocator);
         final ByteArrayOutputStream baos = new ByteArrayOutputStream();
         final WritableByteChannel channel = newChannel(baos);
-        outbuf.writeLine(s);
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
+        chbuffer.append(s);
+        outbuf.writeLine(chbuffer);
         outbuf.flush(channel);
 
         final String result = new String(baos.toByteArray(), "US-ASCII");

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/ChunkedOutputStream.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/ChunkedOutputStream.java?rev=1636718&r1=1636717&r2=1636718&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/ChunkedOutputStream.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/ChunkedOutputStream.java Tue Nov  4 20:03:42 2014
@@ -32,6 +32,7 @@ import java.io.OutputStream;
 
 import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.io.SessionOutputBuffer;
+import org.apache.http.util.CharArrayBuffer;
 
 /**
  * Implements chunked transfer coding. The content is sent in small chunks.
@@ -60,6 +61,8 @@ public class ChunkedOutputStream extends
     /** True if the stream is closed. */
     private boolean closed = false;
 
+    private final CharArrayBuffer linebuffer;
+
     /**
      * Wraps a session output buffer and chunk-encodes the output.
      *
@@ -70,6 +73,7 @@ public class ChunkedOutputStream extends
         super();
         this.cache = new byte[bufferSize];
         this.out = out;
+        this.linebuffer = new CharArrayBuffer(32);
     }
 
     /**
@@ -77,9 +81,12 @@ public class ChunkedOutputStream extends
      */
     protected void flushCache() throws IOException {
         if (this.cachePosition > 0) {
-            this.out.writeLine(Integer.toHexString(this.cachePosition));
+            this.linebuffer.clear();
+            this.linebuffer.append(Integer.toHexString(this.cachePosition));
+            this.out.writeLine(this.linebuffer);
             this.out.write(this.cache, 0, this.cachePosition);
-            this.out.writeLine("");
+            this.linebuffer.clear();
+            this.out.writeLine(this.linebuffer);
             this.cachePosition = 0;
         }
     }
@@ -89,17 +96,23 @@ public class ChunkedOutputStream extends
      * as one large chunk
      */
     protected void flushCacheWithAppend(final byte bufferToAppend[], final int off, final int len) throws IOException {
-        this.out.writeLine(Integer.toHexString(this.cachePosition + len));
+        this.linebuffer.clear();
+        this.linebuffer.append(Integer.toHexString(this.cachePosition + len));
+        this.out.writeLine(this.linebuffer);
         this.out.write(this.cache, 0, this.cachePosition);
         this.out.write(bufferToAppend, off, len);
-        this.out.writeLine("");
+        this.linebuffer.clear();
+        this.out.writeLine(this.linebuffer);
         this.cachePosition = 0;
     }
 
     protected void writeClosingChunk() throws IOException {
         // Write the final chunk.
-        this.out.writeLine("0");
-        this.out.writeLine("");
+        this.linebuffer.clear();
+        this.linebuffer.append('0');
+        this.out.writeLine(this.linebuffer);
+        this.linebuffer.clear();
+        this.out.writeLine(this.linebuffer);
     }
 
     // ----------------------------------------------------------- Public Methods

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=1636718&r1=1636717&r2=1636718&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 Tue Nov  4 20:03:42 2014
@@ -51,8 +51,8 @@ import org.apache.http.util.CharArrayBuf
  * an arbitrary {@link InputStream}. This class buffers input data in
  * an internal byte array for optimal input performance.
  * <p>
- * {@link #readLine(CharArrayBuffer)} and {@link #readLine()} methods of this
- * class treat a lone LF as valid line delimiters in addition to CR-LF required
+ * {@link #readLine(CharArrayBuffer)} method of this class treat a lone
+ * LF as valid line delimiters in addition to CR-LF required
  * by the HTTP specification.
  *
  * @since 4.3
@@ -389,17 +389,6 @@ public class SessionInputBufferImpl impl
     }
 
     @Override
-    public String readLine() throws IOException {
-        final CharArrayBuffer charbuffer = new CharArrayBuffer(64);
-        final int l = readLine(charbuffer);
-        if (l != -1) {
-            return charbuffer.toString();
-        } else {
-            return null;
-        }
-    }
-
-    @Override
     public HttpTransportMetrics getMetrics() {
         return this.metrics;
     }

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionOutputBufferImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionOutputBufferImpl.java?rev=1636718&r1=1636717&r2=1636718&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionOutputBufferImpl.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionOutputBufferImpl.java Tue Nov  4 20:03:42 2014
@@ -49,8 +49,8 @@ import org.apache.http.util.CharArrayBuf
  * an arbitrary {@link OutputStream}. This class buffers small chunks of
  * output data in an internal byte array for optimal output performance.
  * <p>
- * {@link #writeLine(CharArrayBuffer)} and {@link #writeLine(String)} methods
- * of this class use CR-LF as a line delimiter.
+ * {@link #writeLine(CharArrayBuffer)} method of this class uses CR-LF
+ * as a line delimiter.
  *
  * @since 4.3
  */
@@ -195,33 +195,6 @@ public class SessionOutputBufferImpl imp
     }
 
     /**
-     * Writes characters from the specified string followed by a line delimiter
-     * to this session buffer.
-     * <p>
-     * This method uses CR-LF as a line delimiter.
-     *
-     * @param      s   the line.
-     * @exception  IOException  if an I/O error occurs.
-     */
-    @Override
-    public void writeLine(final String s) throws IOException {
-        if (s == null) {
-            return;
-        }
-        if (s.length() > 0) {
-            if (this.encoder == null) {
-                for (int i = 0; i < s.length(); i++) {
-                    write(s.charAt(i));
-                }
-            } else {
-                final CharBuffer cbuf = CharBuffer.wrap(s);
-                writeEncoded(cbuf);
-            }
-        }
-        write(CRLF);
-    }
-
-    /**
      * Writes characters from the specified char array followed by a line
      * delimiter to this session buffer.
      * <p>

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/SessionInputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/SessionInputBuffer.java?rev=1636718&r1=1636717&r2=1636718&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/SessionInputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/SessionInputBuffer.java Tue Nov  4 20:03:42 2014
@@ -113,21 +113,6 @@ public interface SessionInputBuffer {
     int readLine(CharArrayBuffer buffer) throws IOException;
 
     /**
-     * Reads a complete line of characters up to a line delimiter from this
-     * session buffer. The line delimiter itself is discarded. If no char is
-     * available because the end of the stream has been reached,
-     * {@code null} is returned. This method blocks until input data is
-     * available, end of file is detected, or an exception is thrown.
-     * <p>
-     * The choice of a char encoding and line delimiter sequence is up to the
-     * specific implementations of this interface.
-     *
-     * @return HTTP line as a string
-     * @exception  IOException  if an I/O error occurs.
-     */
-    String readLine() throws IOException;
-
-    /**
      * Returns {@link HttpTransportMetrics} for this session buffer.
      *
      * @return transport metrics.

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/SessionOutputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/SessionOutputBuffer.java?rev=1636718&r1=1636717&r2=1636718&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/SessionOutputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/SessionOutputBuffer.java Tue Nov  4 20:03:42 2014
@@ -75,18 +75,6 @@ public interface SessionOutputBuffer {
     void write(int b) throws IOException;
 
     /**
-     * Writes characters from the specified string followed by a line delimiter
-     * to this session buffer.
-     * <p>
-     * The choice of a char encoding and line delimiter sequence is up to the
-     * specific implementations of this interface.
-     *
-     * @param      s   the line.
-     * @exception  IOException  if an I/O error occurs.
-     */
-    void writeLine(String s) throws IOException;
-
-    /**
      * Writes characters from the specified char array followed by a line
      * delimiter to this session buffer.
      * <p>

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=1636718&r1=1636717&r2=1636718&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 Tue Nov  4 20:03:42 2014
@@ -89,8 +89,7 @@ public class TestSessionInOutBuffers {
             outbuffer.writeLine(chbuffer);
         }
         //these write operations should have no effect
-        outbuffer.writeLine((String)null);
-        outbuffer.writeLine((CharArrayBuffer)null);
+        outbuffer.writeLine(null);
         outbuffer.flush();
 
         HttpTransportMetrics tmetrics = outbuffer.getMetrics();
@@ -105,11 +104,15 @@ public class TestSessionInOutBuffers {
                 outbuffer.getData());
 
         for (final String teststr : teststrs) {
-            Assert.assertEquals(teststr, inbuffer.readLine());
+            chbuffer.clear();
+            inbuffer.readLine(chbuffer);
+            Assert.assertEquals(teststr, chbuffer.toString());
         }
 
-        Assert.assertNull(inbuffer.readLine());
-        Assert.assertNull(inbuffer.readLine());
+        chbuffer.clear();
+        Assert.assertEquals(-1, inbuffer.readLine(chbuffer));
+        chbuffer.clear();
+        Assert.assertEquals(-1, inbuffer.readLine(chbuffer));
         tmetrics = inbuffer.getMetrics();
         final long bytesRead = tmetrics.getBytesTransferred();
         Assert.assertEquals(expected, bytesRead);
@@ -169,19 +172,39 @@ public class TestSessionInOutBuffers {
         bytesWritten = outbuffer.getMetrics().getBytesTransferred();
         Assert.assertEquals(8 + 14 + 2 + 15 + 2 + 16 + 2 + 1, bytesWritten);
 
-        final SessionInputBufferMock inbuffer = new SessionInputBufferMock(
-                outbuffer.getData());
+        final SessionInputBufferMock inbuffer = new SessionInputBufferMock(outbuffer.getData());
 
-        Assert.assertEquals("a", inbuffer.readLine());
-        Assert.assertEquals("", inbuffer.readLine());
-        Assert.assertEquals("\r", inbuffer.readLine());
-        Assert.assertEquals("", inbuffer.readLine());
-        Assert.assertEquals(s1, inbuffer.readLine());
-        Assert.assertEquals(s2, inbuffer.readLine());
-        Assert.assertEquals(s3, inbuffer.readLine());
-        Assert.assertEquals("a", inbuffer.readLine());
-        Assert.assertNull(inbuffer.readLine());
-        Assert.assertNull(inbuffer.readLine());
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
+        chbuffer.clear();
+        inbuffer.readLine(chbuffer);
+        Assert.assertEquals("a", chbuffer.toString());
+        chbuffer.clear();
+        inbuffer.readLine(chbuffer);
+        Assert.assertEquals("", chbuffer.toString());
+        chbuffer.clear();
+        inbuffer.readLine(chbuffer);
+        Assert.assertEquals("\r", chbuffer.toString());
+        chbuffer.clear();
+        inbuffer.readLine(chbuffer);
+        Assert.assertEquals("", chbuffer.toString());
+        chbuffer.clear();
+        inbuffer.readLine(chbuffer);
+        Assert.assertEquals(s1, chbuffer.toString());
+        chbuffer.clear();
+        inbuffer.readLine(chbuffer);
+        Assert.assertEquals(s2, chbuffer.toString());
+        chbuffer.clear();
+        inbuffer.readLine(chbuffer);
+        Assert.assertEquals(s3, chbuffer.toString());
+        chbuffer.clear();
+        inbuffer.readLine(chbuffer);
+        Assert.assertEquals("a", chbuffer.toString());
+        chbuffer.clear();
+        inbuffer.readLine(chbuffer);
+        Assert.assertEquals(-1, inbuffer.readLine(chbuffer));
+        chbuffer.clear();
+        inbuffer.readLine(chbuffer);
+        Assert.assertEquals(-1, inbuffer.readLine(chbuffer));
         final long bytesRead = inbuffer.getMetrics().getBytesTransferred();
         Assert.assertEquals(bytesWritten, bytesRead);
     }
@@ -210,8 +233,7 @@ public class TestSessionInOutBuffers {
             outbuffer.writeLine(chbuffer);
         }
         //these write operations should have no effect
-        outbuffer.writeLine((String)null);
-        outbuffer.writeLine((CharArrayBuffer)null);
+        outbuffer.writeLine(null);
         outbuffer.flush();
 
         final long bytesWritten = outbuffer.getMetrics().getBytesTransferred();
@@ -225,10 +247,14 @@ public class TestSessionInOutBuffers {
                 outbuffer.getData(), 1024);
 
         for (final String teststr : teststrs) {
-            Assert.assertEquals(teststr, inbuffer.readLine());
+            chbuffer.clear();
+            inbuffer.readLine(chbuffer);
+            Assert.assertEquals(teststr, chbuffer.toString());
         }
-        Assert.assertNull(inbuffer.readLine());
-        Assert.assertNull(inbuffer.readLine());
+        chbuffer.clear();
+        Assert.assertEquals(-1, inbuffer.readLine(chbuffer));
+        chbuffer.clear();
+        Assert.assertEquals(-1, inbuffer.readLine(chbuffer));
         final long bytesRead = inbuffer.getMetrics().getBytesTransferred();
         Assert.assertEquals(expected, bytesRead);
     }
@@ -363,7 +389,8 @@ public class TestSessionInOutBuffers {
         // no limit
         final SessionInputBufferMock inbuffer1 = new SessionInputBufferMock(tmp, 5,
                 MessageConstraints.DEFAULT);
-        Assert.assertNotNull(inbuffer1.readLine());
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
+        inbuffer1.readLine(chbuffer);
         final long bytesRead = inbuffer1.getMetrics().getBytesTransferred();
         Assert.assertEquals(60, bytesRead);
 
@@ -371,7 +398,8 @@ public class TestSessionInOutBuffers {
         final SessionInputBufferMock inbuffer2 = new SessionInputBufferMock(tmp, 5,
                 MessageConstraints.lineLen(15));
         try {
-            inbuffer2.readLine();
+            chbuffer.clear();
+            inbuffer2.readLine(chbuffer);
             Assert.fail("MessageConstraintException expected");
         } catch (MessageConstraintException ex) {
         }
@@ -384,7 +412,8 @@ public class TestSessionInOutBuffers {
         // no limit
         final SessionInputBufferMock inbuffer1 = new SessionInputBufferMock(tmp, 25,
                 MessageConstraints.DEFAULT);
-        Assert.assertNotNull(inbuffer1.readLine());
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
+        inbuffer1.readLine(chbuffer);
         final long bytesRead = inbuffer1.getMetrics().getBytesTransferred();
         Assert.assertEquals(13, bytesRead);
 
@@ -392,7 +421,8 @@ public class TestSessionInOutBuffers {
         final SessionInputBufferMock inbuffer2 = new SessionInputBufferMock(tmp, 25,
                 MessageConstraints.lineLen(10));
         try {
-            inbuffer2.readLine();
+            chbuffer.clear();
+            inbuffer2.readLine(chbuffer);
             Assert.fail("MessageConstraintException expected");
         } catch (MessageConstraintException ex) {
         }
@@ -407,7 +437,8 @@ public class TestSessionInOutBuffers {
         Assert.assertEquals('b', inbuffer1.read());
         Assert.assertEquals('c', inbuffer1.read());
         Assert.assertEquals('\r', inbuffer1.read());
-        Assert.assertEquals("", inbuffer1.readLine());
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
+        Assert.assertEquals(0, inbuffer1.readLine(chbuffer));
     }
 
     static final int SWISS_GERMAN_HELLO [] = {
@@ -460,12 +491,20 @@ public class TestSessionInOutBuffers {
                 outbuffer.getData(), Consts.UTF_8);
 
         for (int i = 0; i < 10; i++) {
-            Assert.assertEquals(s1, inbuffer.readLine());
-            Assert.assertEquals(s2, inbuffer.readLine());
-            Assert.assertEquals(s3, inbuffer.readLine());
+            chbuffer.clear();
+            inbuffer.readLine(chbuffer);
+            Assert.assertEquals(s1, chbuffer.toString());
+            chbuffer.clear();
+            inbuffer.readLine(chbuffer);
+            Assert.assertEquals(s2, chbuffer.toString());
+            chbuffer.clear();
+            inbuffer.readLine(chbuffer);
+            Assert.assertEquals(s3, chbuffer.toString());
         }
-        Assert.assertNull(inbuffer.readLine());
-        Assert.assertNull(inbuffer.readLine());
+        chbuffer.clear();
+        Assert.assertEquals(-1, inbuffer.readLine(chbuffer));
+        chbuffer.clear();
+        Assert.assertEquals(-1, inbuffer.readLine(chbuffer));
         final long bytesRead = inbuffer.getMetrics().getBytesTransferred();
         Assert.assertEquals(expected, bytesRead);
     }
@@ -491,7 +530,9 @@ public class TestSessionInOutBuffers {
         final SessionInputBufferMock inbuffer = new SessionInputBufferMock(
                 outbuffer.getData(), Consts.UTF_8);
 
-        Assert.assertEquals(s, inbuffer.readLine());
+        chbuffer.clear();
+        inbuffer.readLine(chbuffer);
+        Assert.assertEquals(s, chbuffer.toString());
     }
 
     @Test
@@ -501,35 +542,33 @@ public class TestSessionInOutBuffers {
         final SessionOutputBufferMock outbuffer = new SessionOutputBufferMock(Consts.ISO_8859_1);
 
         final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
-        for (int i = 0; i < 5; i++) {
+        for (int i = 0; i < 10; i++) {
             chbuffer.clear();
             chbuffer.append(s1);
             outbuffer.writeLine(chbuffer);
         }
-        for (int i = 0; i < 5; i++) {
-            outbuffer.writeLine(s1);
-        }
         chbuffer.clear();
         outbuffer.writeLine(chbuffer);
         outbuffer.flush();
         final long bytesWritten = outbuffer.getMetrics().getBytesTransferred();
-        final long expected = ((s1.toString().getBytes(Consts.ISO_8859_1).length + 2)) * 10 + 2;
+        final long expected = ((s1.getBytes(Consts.ISO_8859_1).length + 2)) * 10 + 2;
         Assert.assertEquals(expected, bytesWritten);
 
         final SessionInputBufferMock inbuffer = new SessionInputBufferMock(
                 outbuffer.getData(), Consts.ISO_8859_1);
 
-        final CharArrayBuffer buf = new CharArrayBuffer(64);
         for (int i = 0; i < 10; i++) {
-            buf.clear();
-            final int len = inbuffer.readLine(buf);
+            chbuffer.clear();
+            final int len = inbuffer.readLine(chbuffer);
             Assert.assertEquals(len, SWISS_GERMAN_HELLO.length);
-            Assert.assertEquals(s1, buf.toString());
+            Assert.assertEquals(s1, chbuffer.toString());
         }
-        buf.clear();
-        Assert.assertEquals("", inbuffer.readLine());
-        Assert.assertNull(inbuffer.readLine());
-        Assert.assertNull(inbuffer.readLine());
+        chbuffer.clear();
+        Assert.assertEquals(0, inbuffer.readLine(chbuffer));
+        chbuffer.clear();
+        Assert.assertEquals(-1, inbuffer.readLine(chbuffer));
+        chbuffer.clear();
+        Assert.assertEquals(-1, inbuffer.readLine(chbuffer));
         final long bytesRead = inbuffer.getMetrics().getBytesTransferred();
         Assert.assertEquals(expected, bytesRead);
     }
@@ -541,7 +580,9 @@ public class TestSessionInOutBuffers {
         encoder.onMalformedInput(CodingErrorAction.IGNORE);
         encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
         final SessionOutputBufferMock outbuf = new SessionOutputBufferMock(encoder);
-        outbuf.writeLine(s);
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(32);
+        chbuffer.append(s);
+        outbuf.writeLine(chbuffer);
     }
 
     @Test
@@ -551,7 +592,9 @@ public class TestSessionInOutBuffers {
         encoder.onMalformedInput(CodingErrorAction.IGNORE);
         encoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
         final SessionOutputBufferMock outbuf = new SessionOutputBufferMock(encoder);
-        outbuf.writeLine(s);
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(32);
+        chbuffer.append(s);
+        outbuf.writeLine(chbuffer);
         outbuf.flush();
         final String result = new String(outbuf.getData(), "ISO-8859-1");
         Assert.assertEquals("This text contains a circumflex ? !!!\r\n", result);
@@ -564,7 +607,9 @@ public class TestSessionInOutBuffers {
         encoder.onMalformedInput(CodingErrorAction.IGNORE);
         encoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
         final SessionOutputBufferMock outbuf = new SessionOutputBufferMock(encoder);
-        outbuf.writeLine(s);
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(32);
+        chbuffer.append(s);
+        outbuf.writeLine(chbuffer);
         outbuf.flush();
         final String result = new String(outbuf.getData(), "ISO-8859-1");
         Assert.assertEquals("This text contains a circumflex  !!!\r\n", result);
@@ -577,7 +622,8 @@ public class TestSessionInOutBuffers {
         decoder.onMalformedInput(CodingErrorAction.REPORT);
         decoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
         final SessionInputBufferMock inbuffer = new SessionInputBufferMock(tmp, decoder);
-        inbuffer.readLine();
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(32);
+        inbuffer.readLine(chbuffer);
     }
 
     @Test
@@ -587,8 +633,9 @@ public class TestSessionInOutBuffers {
         decoder.onMalformedInput(CodingErrorAction.REPLACE);
         decoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
         final SessionInputBufferMock inbuffer = new SessionInputBufferMock(tmp, decoder);
-        final String s = inbuffer.readLine();
-        Assert.assertEquals("Gr\ufffdezi_z\ufffdm\ufffd", s);
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(32);
+        inbuffer.readLine(chbuffer);
+        Assert.assertEquals("Gr\ufffdezi_z\ufffdm\ufffd", chbuffer.toString());
     }
 
     @Test
@@ -598,8 +645,9 @@ public class TestSessionInOutBuffers {
         decoder.onMalformedInput(CodingErrorAction.IGNORE);
         decoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
         final SessionInputBufferMock inbuffer = new SessionInputBufferMock(tmp, decoder);
-        final String s = inbuffer.readLine();
-        Assert.assertEquals("Grezi_zm", s);
+        final CharArrayBuffer chbuffer = new CharArrayBuffer(32);
+        inbuffer.readLine(chbuffer);
+        Assert.assertEquals("Grezi_zm", chbuffer.toString());
     }
 
     @Test



Mime
View raw message