summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCasey Marshall <csm@gnu.org>2006-09-25 21:54:44 +0000
committerCasey Marshall <csm@gnu.org>2006-09-25 21:54:44 +0000
commit531e39762343dc00a415b75c19443bf724daac94 (patch)
tree789a82b6d151635a636a51b64b505d97e1f44084
parent5427bd2e19fc5d53c18777df0178d8c91cf913d2 (diff)
downloadclasspath-531e39762343dc00a415b75c19443bf724daac94.tar.gz
2006-09-25 Casey Marshall <csm@gnu.org>
* gnu/java/nio/FileChannelImpl.java (read): revert back to using `readScattering.' (write): revert back to using `writeGathering.' * vm/reference/gnu/java/nio/VMChannel.java (writeGathering): find the first buffer that has data remaining, and start at that one.
-rw-r--r--ChangeLog8
-rw-r--r--gnu/java/nio/FileChannelImpl.java21
-rw-r--r--vm/reference/gnu/java/nio/VMChannel.java21
3 files changed, 28 insertions, 22 deletions
diff --git a/ChangeLog b/ChangeLog
index a8b3210d5..d30e243dc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2006-09-25 Casey Marshall <csm@gnu.org>
+
+ * gnu/java/nio/FileChannelImpl.java (read): revert back to using
+ `readScattering.'
+ (write): revert back to using `writeGathering.'
+ * vm/reference/gnu/java/nio/VMChannel.java (writeGathering): find
+ the first buffer that has data remaining, and start at that one.
+
2006-09-25 Tom Tromey <tromey@redhat.com>
* native/jni/gconf-peer/Makefile.am (libgconfpeer_la_LDFLAGS): New
diff --git a/gnu/java/nio/FileChannelImpl.java b/gnu/java/nio/FileChannelImpl.java
index 42efcd0be..419124050 100644
--- a/gnu/java/nio/FileChannelImpl.java
+++ b/gnu/java/nio/FileChannelImpl.java
@@ -253,18 +253,7 @@ public final class FileChannelImpl extends FileChannel
public long read (ByteBuffer[] dsts, int offset, int length)
throws IOException
{
- 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;
+ return ch.readScattering(dsts, offset, length);
}
public int write (ByteBuffer src) throws IOException
@@ -303,13 +292,7 @@ public final class FileChannelImpl extends FileChannel
public long write(ByteBuffer[] srcs, int offset, int length)
throws IOException
{
- 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;
+ return ch.writeGathering(srcs, offset, length);
}
public MappedByteBuffer map (FileChannel.MapMode mode,
diff --git a/vm/reference/gnu/java/nio/VMChannel.java b/vm/reference/gnu/java/nio/VMChannel.java
index ab09ef801..520a6f4d5 100644
--- a/vm/reference/gnu/java/nio/VMChannel.java
+++ b/vm/reference/gnu/java/nio/VMChannel.java
@@ -196,7 +196,7 @@ public final class VMChannel
{
if (offset + length > dsts.length)
throw new IndexOutOfBoundsException("offset + length > dsts.length");
-
+
return readScattering(nfd.getNativeFD(), dsts, offset, length);
}
@@ -275,6 +275,21 @@ public final class VMChannel
if (offset + length > srcs.length)
throw new IndexOutOfBoundsException("offset + length > srcs.length");
+ // A gathering write is limited to 16 buffers; when writing, ensure
+ // that we have at least one buffer with something in it in the 16
+ // buffer window starting at offset.
+ while (!srcs[offset].hasRemaining() && offset < srcs.length)
+ offset++;
+
+ // There are no buffers with anything to write.
+ if (offset == srcs.length)
+ return 0;
+
+ // If we advanced `offset' so far that we don't have `length'
+ // buffers left, reset length to only the remaining buffers.
+ if (length > srcs.length - offset)
+ length = srcs.length - offset;
+
return writeGathering(nfd.getNativeFD(), srcs, offset, length);
}
@@ -673,10 +688,10 @@ public final class VMChannel
public String toString()
{
- if (!valid)
- return "<<invalid>>";
if (closed)
return "<<closed>>";
+ if (!valid)
+ return "<<invalid>>";
return String.valueOf(native_fd);
}