You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2006/05/26 16:26:34 UTC

svn commit: r409677 - in /incubator/harmony/enhanced/classlib/trunk/modules: luni/src/test/java/tests/api/java/io/ nio/src/main/java/org/apache/harmony/nio/internal/ nio/src/test/java/org/apache/harmony/tests/java/nio/channels/

Author: tellison
Date: Fri May 26 07:26:33 2006
New Revision: 409677

URL: http://svn.apache.org/viewvc?rev=409677&view=rev
Log:
Apply patch HARMONY-508 ([classlib][luni] java.io.FileOutputStream.getChannel().position() returns incorrect value on Linux platform)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileOutputStreamTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/WriteOnlyFileChannel.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/FileChannelTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileOutputStreamTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileOutputStreamTest.java?rev=409677&r1=409676&r2=409677&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileOutputStreamTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileOutputStreamTest.java Fri May 26 07:26:33 2006
@@ -208,6 +208,25 @@
     }
 
     /**
+     * @tests java.io.FileOutputStream#getChannel()
+     */
+    public void test_getChannel() throws Exception {
+		// Regression for HARMONY-
+		File tmpfile = File.createTempFile("FileOutputStream", "tmp");
+		tmpfile.deleteOnExit();
+		FileOutputStream fos = new FileOutputStream(tmpfile);
+		byte[] b = new byte[10];
+		for (int i = 10; i < b.length; i++) {
+			b[i] = (byte) i;
+		}
+		fos.write(b);
+		fos.flush();
+		fos.close();
+		FileOutputStream f = new FileOutputStream(tmpfile, true);
+		assertEquals(f.getChannel().position(), 10); 
+    }
+
+    /**
      * Tears down the fixture, for example, close a network connection. This
      * method is called after a test is executed.
      */

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/WriteOnlyFileChannel.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/WriteOnlyFileChannel.java?rev=409677&r1=409676&r2=409677&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/WriteOnlyFileChannel.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/WriteOnlyFileChannel.java Fri May 26 07:26:33 2006
@@ -34,6 +34,14 @@
 		super(stream, handle);
 		append = isAppend;
 	}
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.harmony.nio.internal.FileChannelImpl#position()
+     */
+    public long position() throws IOException {
+        return append ? size() : super.position();
+    }
 
 	public long transferTo(long position, long count, WritableByteChannel target)
 			throws IOException {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/FileChannelTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/FileChannelTest.java?rev=409677&r1=409676&r2=409677&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/FileChannelTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/FileChannelTest.java Fri May 26 07:26:33 2006
@@ -36,4 +36,23 @@
 		out.close();
 		assertFalse("Assert 0: Channel is still open", channel.isOpen());
 	}
+
+    /**
+     * @tests java.nio.channels.FileChannel#position()
+     */
+    public void test_Position() throws Exception {
+        // Regression test for Harmony-508
+        File tmpfile = File.createTempFile("FileOutputStream", "tmp");
+        tmpfile.deleteOnExit();
+        FileOutputStream fos = new FileOutputStream(tmpfile);
+        byte[] b = new byte[10];
+        for (int i = 0; i < b.length; i++) {
+            b[i] = (byte) i;
+        }
+        fos.write(b);
+        fos.flush();
+        fos.close();
+        FileOutputStream f = new FileOutputStream(tmpfile, true);
+        assertEquals(10, f.getChannel().position());
+    }
 }