diff options
author | Michael Koch <konqueror@gmx.de> | 2003-10-20 15:41:46 +0000 |
---|---|---|
committer | Michael Koch <konqueror@gmx.de> | 2003-10-20 15:41:46 +0000 |
commit | 31cdeae79d4b140ed2ebebafe9284b816d55ba8e (patch) | |
tree | eaf767468890069af94b039538fa8ea9456bebc0 /gnu/java/nio | |
parent | 3c860b6275c6c189b14d7f36e444168210dc9201 (diff) | |
download | classpath-31cdeae79d4b140ed2ebebafe9284b816d55ba8e.tar.gz |
2003-10-20 Michael Koch <konqueror@gmx.de>
* gnu/java/nio/PipeImpl.java
(PipeImpl): New constructor implementation which takes
SelectorProvider argument.
* gnu/java/nio/SelectorProviderImpl.java
(openPipe): Give SelectorProvider argument to PipeImpl.
* gnu/java/nio/SocketChannelImpl.java
(read): Fixed reading into ByteBuffer objects which are backed by an
array.
(write): Likewise.
Diffstat (limited to 'gnu/java/nio')
-rw-r--r-- | gnu/java/nio/PipeImpl.java | 8 | ||||
-rw-r--r-- | gnu/java/nio/SelectorProviderImpl.java | 4 | ||||
-rw-r--r-- | gnu/java/nio/SocketChannelImpl.java | 37 |
3 files changed, 31 insertions, 18 deletions
diff --git a/gnu/java/nio/PipeImpl.java b/gnu/java/nio/PipeImpl.java index 77341e7f4..76da5ee91 100644 --- a/gnu/java/nio/PipeImpl.java +++ b/gnu/java/nio/PipeImpl.java @@ -1,5 +1,5 @@ /* PipeImpl.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -37,12 +37,16 @@ exception statement from your version. */ package gnu.java.nio; +import java.io.IOException; import java.nio.channels.Pipe; +import java.nio.channels.spi.SelectorProvider; class PipeImpl extends Pipe { - public PipeImpl() + public PipeImpl (SelectorProvider provider) + throws IOException { + super(); } public Pipe.SinkChannel sink() diff --git a/gnu/java/nio/SelectorProviderImpl.java b/gnu/java/nio/SelectorProviderImpl.java index d58e10a01..41966ef14 100644 --- a/gnu/java/nio/SelectorProviderImpl.java +++ b/gnu/java/nio/SelectorProviderImpl.java @@ -1,5 +1,5 @@ /* SelectorProviderImpl.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -60,7 +60,7 @@ public class SelectorProviderImpl extends SelectorProvider public Pipe openPipe () throws IOException { - return new PipeImpl (); + return new PipeImpl (this); } public AbstractSelector openSelector () diff --git a/gnu/java/nio/SocketChannelImpl.java b/gnu/java/nio/SocketChannelImpl.java index 6a9315f77..0478e32ea 100644 --- a/gnu/java/nio/SocketChannelImpl.java +++ b/gnu/java/nio/SocketChannelImpl.java @@ -213,8 +213,16 @@ public final class SocketChannelImpl extends SocketChannel byte[] data; int offset = 0; + InputStream input = socket.getInputStream(); + int available = input.available(); int len = dst.remaining(); + if (available == 0) + return 0; + + if (len > available) + len = available; + if (dst.hasArray()) { offset = dst.arrayOffset() + dst.position(); @@ -225,15 +233,6 @@ public final class SocketChannelImpl extends SocketChannel data = new byte [len]; } - InputStream input = socket.getInputStream(); - int available = input.available(); - - if (available == 0) - return 0; - - if (len > available) - len = available; - int readBytes = 0; boolean completed = false; @@ -248,11 +247,15 @@ public final class SocketChannelImpl extends SocketChannel end (completed); } - if (readBytes > 0 - && !dst.hasArray()) - { - dst.put (data); - } + if (readBytes > 0) + if (dst.hasArray()) + { + dst.position (dst.position() + readBytes); + } + else + { + dst.put (data, offset, len); + } return readBytes; } @@ -302,6 +305,12 @@ public final class SocketChannelImpl extends SocketChannel OutputStream output = socket.getOutputStream(); output.write (data, offset, len); + + if (src.hasArray()) + { + src.position (src.position() + len); + } + return len; } |