harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r523235 - in /harmony/enhanced/classlib/trunk/modules/nio/src: main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java
Date Wed, 28 Mar 2007 08:55:06 GMT
Author: pyang
Date: Wed Mar 28 01:55:05 2007
New Revision: 523235

URL: http://svn.apache.org/viewvc?view=rev&rev=523235
Log:
Apply patch for HARMONY-3475( java.nio.SocketChannel's OutputStream cannot write a single
byte)

Modified:
    harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java
    harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java?view=diff&rev=523235&r1=523234&r2=523235
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java
Wed Mar 28 01:55:05 2007
@@ -986,7 +986,7 @@
                 throw new IllegalBlockingModeException();
             }
             ByteBuffer buffer = ByteBuffer.allocate(1);
-            buffer.put((byte) (oneByte & 0xFF));
+            buffer.put(0, (byte) (oneByte & 0xFF));
             channel.write(buffer);
         }
     }

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java?view=diff&rev=523235&r1=523234&r2=523235
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java
Wed Mar 28 01:55:05 2007
@@ -3013,6 +3013,41 @@
         }
     }
 
+    /**
+     * @tests SocketChannelImpl#socket().getOutputStream().write(int)
+     */
+    public void test_socket_getOutputStream_write_oneByte()
+            throws IOException {
+
+        // Regression test for Harmony-3475
+
+        int MAGIC = 123;
+
+        channel1.connect(this.localAddr1);
+
+        OutputStream os = channel1.socket().getOutputStream();
+
+        Socket acceptedSocket = server1.accept();
+
+        InputStream in = acceptedSocket.getInputStream();
+
+        os.write(MAGIC);
+        channel1.close();
+
+        int lastByte =  in.read();
+        if (lastByte == -1) {
+            fail("Server received nothing. Expected 1 byte.");
+        } else if (lastByte != MAGIC) {
+            fail("Server received wrong single byte: " + lastByte +
+                 ", expected: " + MAGIC);
+        }
+
+        lastByte = in.read();
+        if (lastByte != -1) {
+            fail("Server received too long sequence. Expected 1 byte.");
+        }
+    }
+
     class MockSocketChannel extends SocketChannel{
         
         private boolean isWriteCalled = false;



Mime
View raw message