readScattering and writeGathering seem really unhappy on Darwin for
files, and calling the latter seems to return 0 too often (ie, all the
time). I don't know if this is a bug in those methods or not, but I
don't think it makes sense to use readv/writev for file I/O, when a loop
will suffice.
And, this makes Azureus extremely unhappy.
2006-09-24 Casey Marshall <[EMAIL PROTECTED]>
* gnu/java/nio/FileChannelImpl.java
(read): call `read' in a loop, don't use `readScattering.'
(write): call `write' in a loop, don't use `writeGathering.'
Committed.
### Eclipse Workspace Patch 1.0
#P classpath
Index: gnu/java/nio/FileChannelImpl.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/nio/FileChannelImpl.java,v
retrieving revision 1.17
diff -u -r1.17 FileChannelImpl.java
--- gnu/java/nio/FileChannelImpl.java 17 Sep 2006 07:31:41 -0000 1.17
+++ gnu/java/nio/FileChannelImpl.java 25 Sep 2006 06:44:06 -0000
@@ -253,7 +253,18 @@
public long read (ByteBuffer[] dsts, int offset, int length)
throws IOException
{
- return ch.readScattering(dsts, offset, length);
+ int n = offset + length;
+ long read = 0;
+ if (offset < 0 || length < 0 || n > dsts.length)
+ throw new ArrayIndexOutOfBoundsException();
+ for (int i = offset; i < n; i++)
+ {
+ int ret = read(dsts[i]);
+ if (ret == -1)
+ break;
+ read += ret;
+ }
+ return read;
}
public int write (ByteBuffer src) throws IOException
@@ -292,7 +303,13 @@
public long write(ByteBuffer[] srcs, int offset, int length)
throws IOException
{
- return ch.writeGathering(srcs, offset, length);
+ int n = offset + length;
+ long written = 0;
+ if (offset < 0 || length < 0 || n > srcs.length)
+ throw new ArrayIndexOutOfBoundsException();
+ for (int i = offset; i < n; i++)
+ written += write(srcs[i]);
+ return written;
}
public MappedByteBuffer map (FileChannel.MapMode mode,