summaryrefslogtreecommitdiff
path: root/libjava/classpath/java/nio/channels
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /libjava/classpath/java/nio/channels
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'libjava/classpath/java/nio/channels')
-rw-r--r--libjava/classpath/java/nio/channels/AlreadyConnectedException.java50
-rw-r--r--libjava/classpath/java/nio/channels/AsynchronousCloseException.java55
-rw-r--r--libjava/classpath/java/nio/channels/ByteChannel.java43
-rw-r--r--libjava/classpath/java/nio/channels/CancelledKeyException.java55
-rw-r--r--libjava/classpath/java/nio/channels/Channel.java60
-rw-r--r--libjava/classpath/java/nio/channels/Channels.java144
-rw-r--r--libjava/classpath/java/nio/channels/ClosedByInterruptException.java55
-rw-r--r--libjava/classpath/java/nio/channels/ClosedChannelException.java57
-rw-r--r--libjava/classpath/java/nio/channels/ClosedSelectorException.java55
-rw-r--r--libjava/classpath/java/nio/channels/ConnectionPendingException.java55
-rw-r--r--libjava/classpath/java/nio/channels/DatagramChannel.java208
-rw-r--r--libjava/classpath/java/nio/channels/FileChannel.java357
-rw-r--r--libjava/classpath/java/nio/channels/FileLock.java151
-rw-r--r--libjava/classpath/java/nio/channels/FileLockInterruptionException.java57
-rw-r--r--libjava/classpath/java/nio/channels/GatheringByteChannel.java79
-rw-r--r--libjava/classpath/java/nio/channels/IllegalBlockingModeException.java59
-rw-r--r--libjava/classpath/java/nio/channels/IllegalSelectorException.java55
-rw-r--r--libjava/classpath/java/nio/channels/InterruptibleChannel.java51
-rw-r--r--libjava/classpath/java/nio/channels/NoConnectionPendingException.java55
-rw-r--r--libjava/classpath/java/nio/channels/NonReadableChannelException.java55
-rw-r--r--libjava/classpath/java/nio/channels/NonWritableChannelException.java55
-rw-r--r--libjava/classpath/java/nio/channels/NotYetBoundException.java55
-rw-r--r--libjava/classpath/java/nio/channels/NotYetConnectedException.java55
-rw-r--r--libjava/classpath/java/nio/channels/OverlappingFileLockException.java55
-rw-r--r--libjava/classpath/java/nio/channels/Pipe.java121
-rw-r--r--libjava/classpath/java/nio/channels/ReadableByteChannel.java64
-rw-r--r--libjava/classpath/java/nio/channels/ScatteringByteChannel.java79
-rw-r--r--libjava/classpath/java/nio/channels/SelectableChannel.java140
-rw-r--r--libjava/classpath/java/nio/channels/SelectionKey.java164
-rw-r--r--libjava/classpath/java/nio/channels/Selector.java134
-rw-r--r--libjava/classpath/java/nio/channels/ServerSocketChannel.java98
-rw-r--r--libjava/classpath/java/nio/channels/SocketChannel.java248
-rw-r--r--libjava/classpath/java/nio/channels/UnresolvedAddressException.java55
-rw-r--r--libjava/classpath/java/nio/channels/UnsupportedAddressTypeException.java55
-rw-r--r--libjava/classpath/java/nio/channels/WritableByteChannel.java60
-rw-r--r--libjava/classpath/java/nio/channels/package.html47
-rw-r--r--libjava/classpath/java/nio/channels/spi/AbstractInterruptibleChannel.java119
-rw-r--r--libjava/classpath/java/nio/channels/spi/AbstractSelectableChannel.java271
-rw-r--r--libjava/classpath/java/nio/channels/spi/AbstractSelectionKey.java78
-rw-r--r--libjava/classpath/java/nio/channels/spi/AbstractSelector.java167
-rw-r--r--libjava/classpath/java/nio/channels/spi/SelectorProvider.java178
-rw-r--r--libjava/classpath/java/nio/channels/spi/package.html46
42 files changed, 4100 insertions, 0 deletions
diff --git a/libjava/classpath/java/nio/channels/AlreadyConnectedException.java b/libjava/classpath/java/nio/channels/AlreadyConnectedException.java
new file mode 100644
index 000000000..979486f06
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/AlreadyConnectedException.java
@@ -0,0 +1,50 @@
+/* AlreadyConnectedException.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+public class AlreadyConnectedException extends IllegalStateException
+{
+ private static final long serialVersionUID = - 7331895245053773357L;
+
+ /**
+ * Creates the exception
+ */
+ public AlreadyConnectedException()
+ {
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/AsynchronousCloseException.java b/libjava/classpath/java/nio/channels/AsynchronousCloseException.java
new file mode 100644
index 000000000..31e41528b
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/AsynchronousCloseException.java
@@ -0,0 +1,55 @@
+/* AsynchronousCloseException.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public class AsynchronousCloseException extends ClosedChannelException
+{
+ private static final long serialVersionUID = 6891178312432313966L;
+
+ /**
+ * Creates the exception
+ */
+ public AsynchronousCloseException()
+ {
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/ByteChannel.java b/libjava/classpath/java/nio/channels/ByteChannel.java
new file mode 100644
index 000000000..d7d7a451b
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/ByteChannel.java
@@ -0,0 +1,43 @@
+/* ByteChannel.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+public interface ByteChannel extends ReadableByteChannel,
+ WritableByteChannel
+{
+}
diff --git a/libjava/classpath/java/nio/channels/CancelledKeyException.java b/libjava/classpath/java/nio/channels/CancelledKeyException.java
new file mode 100644
index 000000000..d94e65053
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/CancelledKeyException.java
@@ -0,0 +1,55 @@
+/* CancelledKeyException.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public class CancelledKeyException extends IllegalStateException
+{
+ private static final long serialVersionUID = - 8438032138028814268L;
+
+ /**
+ * Creates the exception
+ */
+ public CancelledKeyException()
+ {
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/Channel.java b/libjava/classpath/java/nio/channels/Channel.java
new file mode 100644
index 000000000..33fcf3174
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/Channel.java
@@ -0,0 +1,60 @@
+/* Channel.java --
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.nio.channels;
+
+import java.io.IOException;
+import java.io.Closeable;
+
+public interface Channel extends Closeable
+{
+ /**
+ * Tells whether this channel is open or not
+ *
+ * @return <code>true</code>if channel is open,
+ * <code>false</code> otherwise
+ */
+ boolean isOpen();
+
+ /**
+ * Closes this channel
+ *
+ * @exception IOException If an error occurs
+ */
+ void close() throws IOException;
+}
diff --git a/libjava/classpath/java/nio/channels/Channels.java b/libjava/classpath/java/nio/channels/Channels.java
new file mode 100644
index 000000000..382a3d705
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/Channels.java
@@ -0,0 +1,144 @@
+/* Channels.java --
+ Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.nio.channels;
+
+import gnu.java.nio.ChannelReader;
+import gnu.java.nio.ChannelWriter;
+import gnu.java.nio.InputStreamChannel;
+import gnu.java.nio.OutputStreamChannel;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.UnsupportedCharsetException;
+
+
+/**
+ * @since 1.4
+ */
+public final class Channels
+{
+ /**
+ * This class isn't intended to be instantiated.
+ */
+ private Channels()
+ {
+ // Do nothing here.
+ }
+
+ /**
+ * Constructs a stream that reads bytes from the given channel.
+ */
+ public static InputStream newInputStream(ReadableByteChannel ch)
+ {
+ return VMChannels.newInputStream(ch);
+ }
+
+ /**
+ * Constructs a stream that writes bytes to the given channel.
+ */
+ public static OutputStream newOutputStream(WritableByteChannel ch)
+ {
+ return VMChannels.newOutputStream(ch);
+ }
+
+ /**
+ * Constructs a channel that reads bytes from the given stream.
+ */
+ public static ReadableByteChannel newChannel(InputStream in)
+ {
+ return new InputStreamChannel(in);
+ }
+
+ /**
+ * Constructs a channel that writes bytes to the given stream.
+ */
+ public static WritableByteChannel newChannel(OutputStream out)
+ {
+ return new OutputStreamChannel(out);
+ }
+
+ /**
+ * Constructs a reader that decodes bytes from the given channel using the
+ * given decoder.
+ */
+ public static Reader newReader(ReadableByteChannel ch, CharsetDecoder dec,
+ int minBufferCap)
+ {
+ return new ChannelReader(ch, dec, minBufferCap);
+ }
+
+ /**
+ * Constructs a reader that decodes bytes from the given channel according to
+ * the named charset.
+ *
+ * @exception UnsupportedCharsetException If no support for the named charset
+ * is available in this instance of the Java virtual machine.
+ */
+ public static Reader newReader(ReadableByteChannel ch, String csName)
+ {
+ return newReader(ch, Charset.forName(csName).newDecoder(), -1);
+ }
+
+ /**
+ * Constructs a writer that encodes characters using the given encoder and
+ * writes the resulting bytes to the given channel.
+ */
+ public static Writer newWriter(WritableByteChannel ch, CharsetEncoder enc,
+ int minBufferCap)
+ {
+ return new ChannelWriter(ch, enc, minBufferCap);
+ }
+
+ /**
+ * Constructs a writer that encodes characters according to the named charset
+ * and writes the resulting bytes to the given channel.
+ *
+ * @exception UnsupportedCharsetException If no support for the named charset
+ * is available in this instance of the Java virtual machine.
+ */
+ public static Writer newWriter(WritableByteChannel ch, String csName)
+ {
+ return newWriter(ch, Charset.forName(csName).newEncoder(), -1);
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/ClosedByInterruptException.java b/libjava/classpath/java/nio/channels/ClosedByInterruptException.java
new file mode 100644
index 000000000..ade7e2a27
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/ClosedByInterruptException.java
@@ -0,0 +1,55 @@
+/* ClosedByInterruptException.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public class ClosedByInterruptException extends AsynchronousCloseException
+{
+ private static final long serialVersionUID = - 4488191543534286750L;
+
+ /**
+ * Creates the exception
+ */
+ public ClosedByInterruptException()
+ {
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/ClosedChannelException.java b/libjava/classpath/java/nio/channels/ClosedChannelException.java
new file mode 100644
index 000000000..ea896a0fd
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/ClosedChannelException.java
@@ -0,0 +1,57 @@
+/* ClosedChannelException.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+import java.io.IOException;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public class ClosedChannelException extends IOException
+{
+ private static final long serialVersionUID = 882777185433553857L;
+
+ /**
+ * Creates the exception
+ */
+ public ClosedChannelException()
+ {
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/ClosedSelectorException.java b/libjava/classpath/java/nio/channels/ClosedSelectorException.java
new file mode 100644
index 000000000..9dfbd7bf8
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/ClosedSelectorException.java
@@ -0,0 +1,55 @@
+/* ClosedSelectorException.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public class ClosedSelectorException extends IllegalStateException
+{
+ private static final long serialVersionUID = 6466297122317847835L;
+
+ /**
+ * Creates the exception
+ */
+ public ClosedSelectorException()
+ {
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/ConnectionPendingException.java b/libjava/classpath/java/nio/channels/ConnectionPendingException.java
new file mode 100644
index 000000000..2e54ed61a
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/ConnectionPendingException.java
@@ -0,0 +1,55 @@
+/* ConnectionPendingException.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public class ConnectionPendingException extends IllegalStateException
+{
+ private static final long serialVersionUID = 2008393366501760879L;
+
+ /**
+ * Creates the exception
+ */
+ public ConnectionPendingException()
+ {
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/DatagramChannel.java b/libjava/classpath/java/nio/channels/DatagramChannel.java
new file mode 100644
index 000000000..b8815f47c
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/DatagramChannel.java
@@ -0,0 +1,208 @@
+/* DatagramChannel.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+import java.io.IOException;
+import java.net.DatagramSocket;
+import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.channels.spi.AbstractSelectableChannel;
+import java.nio.channels.spi.SelectorProvider;
+
+
+/**
+ * @since 1.4
+ */
+public abstract class DatagramChannel extends AbstractSelectableChannel
+ implements ByteChannel, ScatteringByteChannel, GatheringByteChannel
+{
+ /**
+ * Initializes the channel.
+ */
+ protected DatagramChannel(SelectorProvider provider)
+ {
+ super(provider);
+ }
+
+ /**
+ * Opens a datagram channel.
+ *
+ * @exception IOException If an error occurs
+ */
+ public static DatagramChannel open() throws IOException
+ {
+ return SelectorProvider.provider().openDatagramChannel();
+ }
+
+ /**
+ * Reads data from this channel.
+ */
+ public final long read(ByteBuffer[] dsts) throws IOException
+ {
+ long b = 0;
+
+ for (int i = 0; i < dsts.length; i++)
+ b += read(dsts[i]);
+
+ return b;
+ }
+
+ /**
+ * Writes data to this channel.
+ *
+ * @exception IOException If an error occurs
+ * @exception NotYetConnectedException The channel's socket is not connected.
+ */
+ public final long write(ByteBuffer[] srcs) throws IOException
+ {
+ long b = 0;
+
+ for (int i = 0; i < srcs.length; i++)
+ b += write(srcs[i]);
+
+ return b;
+ }
+
+ /**
+ * Connects this channel's socket.
+ *
+ * @exception AsynchronousCloseException If another thread closes this channel
+ * while the connect operation is in progress.
+ * @exception ClosedByInterruptException If another thread interrupts the
+ * current thread while the read operation is in progress, thereby closing the
+ * channel and setting the current thread's interrupt status.
+ * @exception ClosedChannelException If this channel is closed.
+ * @exception IOException If an error occurs.
+ * @exception SecurityException If a security manager has been installed and
+ * it does not permit datagrams to be sent to the given address.
+ */
+ public abstract DatagramChannel connect(SocketAddress remote)
+ throws IOException;
+
+ /**
+ * Disonnects this channel's socket.
+ *
+ * @exception IOException If an error occurs
+ */
+ public abstract DatagramChannel disconnect() throws IOException;
+
+ /**
+ * Tells whether or not this channel's socket is connected.
+ *
+ * @exception NotYetConnectedException The channel's socket is not connected.
+ */
+ public abstract boolean isConnected();
+
+ /**
+ * Reads data from this channel.
+ */
+ public abstract int read(ByteBuffer dst) throws IOException;
+
+ /**
+ * Reads data from this channel.
+ *
+ * @exception IOException If an error occurs.
+ * @exception NotYetConnectedException The channel's socket is not connected.
+ */
+ public abstract long read(ByteBuffer[] dsts, int offset, int length)
+ throws IOException;
+
+ /**
+ * Receives a datagram via this channel.
+ *
+ * @exception AsynchronousCloseException If another thread closes this channel
+ * while the connect operation is in progress.
+ * @exception ClosedByInterruptException If another thread interrupts the
+ * current thread while the read operation is in progress, thereby closing the
+ * channel and setting the current thread's interrupt status.
+ * @exception ClosedChannelException If this channel is closed.
+ * @exception IOException If an error occurs
+ * @exception SecurityException If a security manager has been installed and
+ * it does not permit datagrams to be sent to the given address.
+ */
+ public abstract SocketAddress receive(ByteBuffer dst)
+ throws IOException;
+
+ /**
+ * Sends a datagram via this channel.
+ *
+ * @exception AsynchronousCloseException If another thread closes this channel
+ * while the connect operation is in progress.
+ * @exception ClosedByInterruptException If another thread interrupts the
+ * current thread while the read operation is in progress, thereby closing the
+ * channel and setting the current thread's interrupt status.
+ * @exception ClosedChannelException If this channel is closed.
+ * @exception IOException If an error occurs
+ * @exception SecurityException If a security manager has been installed and
+ * it does not permit datagrams to be sent to the given address.
+ */
+ public abstract int send(ByteBuffer src, SocketAddress target)
+ throws IOException;
+
+ /**
+ * Retrieves the channel's socket.
+ */
+ public abstract DatagramSocket socket();
+
+ /**
+ * Writes data to this channel.
+ *
+ * @exception IOException If an error occurs.
+ * @exception NotYetConnectedException The channel's socket is not connected.
+ */
+ public abstract int write(ByteBuffer src) throws IOException;
+
+ /**
+ * Writes data to this channel.
+ *
+ * @exception IOException If an error occurs.
+ * @exception NotYetConnectedException The channel's socket is not connected.
+ */
+ public abstract long write(ByteBuffer[] srcs, int offset, int length)
+ throws IOException;
+
+ /**
+ * Retrieves the valid operations for this channel.
+ *
+ * @exception NotYetConnectedException The channel's socket is not connected.
+ */
+ public final int validOps()
+ {
+ return SelectionKey.OP_READ | SelectionKey.OP_WRITE;
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/FileChannel.java b/libjava/classpath/java/nio/channels/FileChannel.java
new file mode 100644
index 000000000..8c8029fe7
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/FileChannel.java
@@ -0,0 +1,357 @@
+/* FileChannel.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.MappedByteBuffer;
+import java.nio.channels.spi.AbstractInterruptibleChannel;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public abstract class FileChannel extends AbstractInterruptibleChannel
+ implements ByteChannel, GatheringByteChannel, ScatteringByteChannel
+{
+ public static class MapMode
+ {
+ int m;
+ public static final MapMode READ_ONLY = new MapMode(0);
+ public static final MapMode READ_WRITE = new MapMode(1);
+ public static final MapMode PRIVATE = new MapMode(2);
+
+ /**
+ * Initializes the MapMode.
+ */
+ MapMode(int a)
+ {
+ m = a;
+ }
+
+ /**
+ * Returns a string representation of the <code>MapMode</code> object.
+ */
+ public String toString()
+ {
+ if (this == READ_ONLY)
+ return "READ_ONLY";
+ else if (this == READ_WRITE)
+ return "READ_WRITE";
+
+ return "PRIVATE";
+ }
+ }
+
+ /**
+ * Initializes the channel.
+ */
+ protected FileChannel()
+ {
+ }
+
+ /**
+ * Maps the file into the memory.
+ *
+ * @exception IllegalArgumentException If the preconditions on the parameters
+ * do not hold.
+ * @exception IOException If an I/O error occurs.
+ * @exception NonReadableChannelException If mode is READ_ONLY but this channel was
+ * not opened for reading.
+ * @exception NonWritableChannelException If mode is READ_WRITE or PRIVATE but this
+ * channel was not opened for writing.
+ */
+ public abstract MappedByteBuffer map(MapMode mode, long position, long size)
+ throws IOException;
+
+ /**
+ * Return the size of the file thus far
+ *
+ * @exception ClosedChannelException If this channel is closed.
+ */
+ public abstract long size() throws IOException;
+
+ /**
+ * Writes data to the channel.
+ *
+ * @exception IOException If an I/O error occurs.
+ */
+ public final long write(ByteBuffer[] srcs) throws IOException
+ {
+ return write(srcs, 0, srcs.length);
+ }
+
+ /**
+ * Writes data to the channel.
+ *
+ * @exception IOException If an I/O error occurs.
+ */
+ public abstract int write(ByteBuffer src) throws IOException;
+
+ /**
+ * Writes data to the channel.
+ *
+ * @exception AsynchronousCloseException If another thread closes this channel
+ * while the transfer is in progress.
+ * @exception ClosedByInterruptException If another thread interrupts the
+ * current thread while the transfer is in progress, thereby closing both
+ * channels and setting the current thread's interrupt status.
+ * @exception ClosedChannelException If this channel is closed.
+ * @exception IllegalArgumentException If position is negative.
+ * @exception IOException If an I/O error occurs.
+ * @exception NonWritableChannelException If this channel was not opened for
+ * writing.
+ */
+ public abstract int write(ByteBuffer srcs, long position)
+ throws IOException;
+
+ /**
+ * Writes data to the channel.
+ *
+ * @exception IOException If an I/O error occurs.
+ */
+ public abstract long write(ByteBuffer[] srcs, int offset, int length)
+ throws IOException;
+
+ /**
+ * Reads data from the channel.
+ *
+ * @exception IOException If an I/O error occurs.
+ */
+ public abstract long read(ByteBuffer[] dsts, int offset, int length)
+ throws IOException;
+
+ /**
+ * Reads data from the channel.
+ *
+ * @exception IOException If an I/O error occurs.
+ */
+ public final long read(ByteBuffer[] dsts) throws IOException
+ {
+ return read(dsts, 0, dsts.length);
+ }
+
+ /**
+ * Reads data from the channel.
+ *
+ * @exception IOException If an I/O error occurs.
+ */
+ public abstract int read(ByteBuffer dst) throws IOException;
+
+ /**
+ * Reads data from the channel.
+ *
+ * @exception AsynchronousCloseException If another thread closes this channel
+ * while the transfer is in progress.
+ * @exception ClosedByInterruptException If another thread interrupts the
+ * current thread while the transfer is in progress, thereby closing both
+ * channels and setting the current thread's interrupt status.
+ * @exception ClosedChannelException If this channel is closed.
+ * @exception IllegalArgumentException If position is negative.
+ * @exception IOException If an I/O error occurs.
+ * @exception NonReadableChannelException If this channel was not opened for
+ * reading.
+ */
+ public abstract int read(ByteBuffer dst, long position)
+ throws IOException;
+
+ /**
+ * Closes the channel.
+ *
+ * This is called from @see close.
+ *
+ * @exception IOException If an I/O error occurs.
+ */
+ protected abstract void implCloseChannel() throws IOException;
+
+ /**
+ * msync with the disk
+ *
+ * @exception ClosedChannelException If this channel is closed.
+ * @exception IOException If an I/O error occurs.
+ */
+ public abstract void force(boolean metaData) throws IOException;
+
+ /**
+ * Creates a file lock for the whole associated file.
+ *
+ * @exception AsynchronousCloseException If another thread closes this channel
+ * while the transfer is in progress.
+ * @exception ClosedChannelException If this channel is closed.
+ * @exception FileLockInterruptionException If the invoking thread is
+ * interrupted while blocked in this method.
+ * @exception IOException If an I/O error occurs.
+ * @exception NonReadableChannelException If shared is true and this channel
+ * was not opened for reading.
+ * @exception NonWritableChannelException If shared is false and this channel
+ * was not opened for writing.
+ * @exception OverlappingFileLockException If a lock that overlaps the
+ * requested region is already held by this Java virtual machine, or if
+ * another thread is already blocked in this method and is attempting to lock
+ * an overlapping region.
+ */
+ public final FileLock lock() throws IOException
+ {
+ return lock(0, Long.MAX_VALUE, false);
+ }
+
+ /**
+ * Creates a file lock for a region of the associated file.
+ *
+ * @exception AsynchronousCloseException If another thread closes this channel
+ * while the transfer is in progress.
+ * @exception ClosedChannelException If this channel is closed.
+ * @exception FileLockInterruptionException If the invoking thread is
+ * interrupted while blocked in this method.
+ * @exception IllegalArgumentException If the preconditions on the parameters
+ * do not hold.
+ * @exception IOException If an I/O error occurs.
+ * @exception OverlappingFileLockException If a lock that overlaps the
+ * requested region is already held by this Java virtual machine, or if
+ * another thread is already blocked in this method and is attempting to lock
+ * an overlapping region.
+ * @exception NonReadableChannelException If shared is true and this channel
+ * was not opened for reading.
+ * @exception NonWritableChannelException If shared is false and this channel
+ * was not opened for writing.
+ */
+ public abstract FileLock lock(long position, long size, boolean shared)
+ throws IOException;
+
+ /**
+ * Tries to aqquire alock on the whole associated file.
+ *
+ * @exception ClosedChannelException If this channel is closed.
+ * @exception IOException If an I/O error occurs.
+ * @exception OverlappingFileLockException If a lock that overlaps the
+ * requested region is already held by this Java virtual machine, or if
+ * another thread is already blocked in this method and is attempting to lock
+ * an overlapping region.
+ */
+ public final FileLock tryLock() throws IOException
+ {
+ return tryLock(0, Long.MAX_VALUE, false);
+ }
+
+ /**
+ * Tries to aqquire a lock on a region of the associated file.
+ *
+ * @exception ClosedChannelException If this channel is closed.
+ * @exception IllegalArgumentException If the preconditions on the parameters
+ * do not hold.
+ * @exception IOException If an I/O error occurs.
+ * @exception OverlappingFileLockException If a lock that overlaps the
+ * requested region is already held by this Java virtual machine, or if
+ * another thread is already blocked in this method and is attempting to lock
+ * an overlapping region.
+ */
+ public abstract FileLock tryLock(long position, long size, boolean shared)
+ throws IOException;
+
+ /**
+ * Returns the current position on the file.
+ *
+ * @exception ClosedChannelException If this channel is closed.
+ * @exception IOException If an I/O error occurs.
+ */
+ public abstract long position() throws IOException;
+
+ /**
+ * Sets the position of the channel on the assoziated file.
+ *
+ * @exception ClosedChannelException If this channel is closed.
+ * @exception IllegalArgumentException If newPosition is negative.
+ * @exception IOException If an I/O error occurs.
+ */
+ public abstract FileChannel position(long newPosition)
+ throws IOException;
+
+ /**
+ * Transfers bytes from this channel's file to the given writable byte
+ * channel.
+ *
+ * @exception AsynchronousCloseException If another thread closes this channel
+ * while the transfer is in progress.
+ * @exception ClosedByInterruptException If another thread interrupts the
+ * current thread while the transfer is in progress, thereby closing both
+ * channels and setting the current thread's interrupt status.
+ * @exception ClosedChannelException If this channel is closed.
+ * @exception IllegalArgumentException If the preconditions on the parameters
+ * do not hold.
+ * @exception IOException If an I/O error occurs.
+ * @exception NonReadableChannelException If this channel was not opened for
+ * reading.
+ * @exception NonWritableChannelException If the target channel was not
+ * opened for writing.
+ */
+ public abstract long transferTo(long position, long count,
+ WritableByteChannel target)
+ throws IOException;
+
+ /**
+ * Transfers bytes from the given readable channel into this channel.
+ *
+ * @exception AsynchronousCloseException If another thread closes this channel
+ * while the transfer is in progress.
+ * @exception ClosedByInterruptException If another thread interrupts the
+ * current thread while the transfer is in progress, thereby closing both
+ * channels and setting the current thread's interrupt status.
+ * @exception ClosedChannelException If this channel is closed.
+ * @exception IllegalArgumentException If the preconditions on the parameters
+ * do not hold.
+ * @exception IOException If an I/O error occurs.
+ * @exception NonReadableChannelException If the source channel was not
+ * opened for reading.
+ * @exception NonWritableChannelException If this channel was not opened for
+ * writing.
+ */
+ public abstract long transferFrom(ReadableByteChannel src, long position,
+ long count) throws IOException;
+
+ /**
+ * Truncates the channel's file at <code>size</code>.
+ *
+ * @exception ClosedChannelException If this channel is closed.
+ * @exception IllegalArgumentException If size is negative.
+ * @exception IOException If an I/O error occurs.
+ * @exception NonWritableChannelException If this channel was not opened for
+ * writing.
+ */
+ public abstract FileChannel truncate(long size) throws IOException;
+}
diff --git a/libjava/classpath/java/nio/channels/FileLock.java b/libjava/classpath/java/nio/channels/FileLock.java
new file mode 100644
index 000000000..78210b34d
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/FileLock.java
@@ -0,0 +1,151 @@
+/* FileLock.java --
+ Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+import gnu.java.lang.CPStringBuilder;
+
+import java.io.IOException;
+
+/**
+ * @since 1.4
+ */
+public abstract class FileLock
+{
+ private final FileChannel channel;
+ private final long position;
+ private final long size;
+ private final boolean shared;
+
+ /**
+ * Initializes the file lock.
+ *
+ * @exception IllegalArgumentException If the preconditions on the parameters do not hold
+ */
+ protected FileLock(FileChannel channel, long position, long size,
+ boolean shared)
+ {
+ if (position < 0 || size < 0)
+ throw new IllegalArgumentException();
+
+ this.channel = channel;
+ this.position = position;
+ this.size = size;
+ this.shared = shared;
+ }
+
+ /**
+ * Tells whether or not this lock is valid.
+ */
+ public abstract boolean isValid();
+
+ /**
+ * Releases this lock.
+ *
+ * @exception IOException If an error occurs
+ * @exception ClosedChannelException If the locked channel is no longer open.
+ */
+ public abstract void release() throws IOException;
+
+ /**
+ * Returns the file channel upon whose file this lock is held.
+ */
+ public final FileChannel channel()
+ {
+ return channel;
+ }
+
+ /**
+ * Tells whether this lock is shared.
+ */
+ public final boolean isShared()
+ {
+ return shared;
+ }
+
+ /**
+ * Tells whether or not this lock overlaps the given lock range.
+ */
+ public final boolean overlaps(long position, long size)
+ {
+ if (position > this.position + this.size)
+ return false;
+
+ if (position + size < this.position)
+ return false;
+
+ return true;
+ }
+
+ /**
+ * Returns the position within the file of the first byte of the
+ * locked region.
+ */
+ public final long position()
+ {
+ return position;
+ }
+
+ /**
+ * Returns the size of the locked region in bytes.
+ */
+ public final long size()
+ {
+ return size;
+ }
+
+ /**
+ * Returns a string describing the range, type, and validity of this lock.
+ */
+ public final String toString()
+ {
+ CPStringBuilder buf = new CPStringBuilder(getClass().getName());
+ buf.append("[");
+ buf.append(position);
+ buf.append(":");
+ buf.append(size);
+ if (shared)
+ buf.append(" shared");
+ else
+ buf.append(" exclusive");
+ if (isValid())
+ buf.append(" valid]");
+ else
+ buf.append(" invalid]");
+ return buf.toString();
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/FileLockInterruptionException.java b/libjava/classpath/java/nio/channels/FileLockInterruptionException.java
new file mode 100644
index 000000000..f1024331e
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/FileLockInterruptionException.java
@@ -0,0 +1,57 @@
+/* FileLockInterruptionException.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+import java.io.IOException;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public class FileLockInterruptionException extends IOException
+{
+ private static final long serialVersionUID = 7104080643653532383L;
+
+ /**
+ * Creates the exception
+ */
+ public FileLockInterruptionException()
+ {
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/GatheringByteChannel.java b/libjava/classpath/java/nio/channels/GatheringByteChannel.java
new file mode 100644
index 000000000..822ea232a
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/GatheringByteChannel.java
@@ -0,0 +1,79 @@
+/* GatheringByteChannel.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+
+public interface GatheringByteChannel extends WritableByteChannel
+{
+ /**
+ * Writes a sequence of bytes to this channel from a subsequence of
+ * the given buffers
+ *
+ * @exception AsynchronousCloseException If another thread closes this
+ * channel while the write operation is in progress
+ * @exception ClosedByInterruptException If another thread interrupts the
+ * current thread while the write operation is in progress, thereby closing
+ * the channel and setting the current thread's interrupt status
+ * @exception ClosedChannelException If this channel is closed
+ * @exception IndexOutOfBoundsException If the preconditions on the offset
+ * and length parameters do not hold
+ * @exception IOException If an error occurs
+ * @exception NonWritableChannelException If this channel was not opened for
+ * writing
+ */
+ long write(ByteBuffer[] srcs, int offset, int length)
+ throws IOException;
+
+ /**
+ * Writes a sequence of bytes to this channel from the given buffers
+ *
+ * @exception AsynchronousCloseException If another thread closes this
+ * channel while the write operation is in progress
+ * @exception ClosedByInterruptException If another thread interrupts the
+ * current thread while the write operation is in progress, thereby closing
+ * the channel and setting the current thread's interrupt status
+ * @exception ClosedChannelException If this channel is closed
+ * @exception IOException If an error occurs
+ * @exception NonWritableChannelException If this channel was not opened for
+ * writing
+ */
+ long write(ByteBuffer[] srcs) throws IOException;
+}
diff --git a/libjava/classpath/java/nio/channels/IllegalBlockingModeException.java b/libjava/classpath/java/nio/channels/IllegalBlockingModeException.java
new file mode 100644
index 000000000..f34d76382
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/IllegalBlockingModeException.java
@@ -0,0 +1,59 @@
+/* IllegalBlockingModeException.java --
+ Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+
+/**
+ * @author Michael Koch (konqueror@gmx.de)
+ * @since 1.4
+ *
+ * Written using JDK 1.4.1 Online API from Sun
+ * Status: JDK 1.4 complete
+ */
+public class IllegalBlockingModeException extends IllegalStateException
+{
+ private static final long serialVersionUID = - 3335774961855590474L;
+
+ /**
+ * Creates the exception
+ */
+ public IllegalBlockingModeException()
+ {
+ super();
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/IllegalSelectorException.java b/libjava/classpath/java/nio/channels/IllegalSelectorException.java
new file mode 100644
index 000000000..01b22529c
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/IllegalSelectorException.java
@@ -0,0 +1,55 @@
+/* IllegalSelectorException.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public class IllegalSelectorException extends IllegalArgumentException
+{
+ private static final long serialVersionUID = - 8406323347253320987L;
+
+ /**
+ * Creates the exception
+ */
+ public IllegalSelectorException()
+ {
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/InterruptibleChannel.java b/libjava/classpath/java/nio/channels/InterruptibleChannel.java
new file mode 100644
index 000000000..54122cead
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/InterruptibleChannel.java
@@ -0,0 +1,51 @@
+/* InterruptibleChannel.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+import java.io.IOException;
+
+
+public interface InterruptibleChannel extends Channel
+{
+ /**
+ * Closes this channel
+ *
+ * @exception IOException If an error occurs
+ */
+ void close() throws IOException;
+}
diff --git a/libjava/classpath/java/nio/channels/NoConnectionPendingException.java b/libjava/classpath/java/nio/channels/NoConnectionPendingException.java
new file mode 100644
index 000000000..8dcbdf695
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/NoConnectionPendingException.java
@@ -0,0 +1,55 @@
+/* NoConnectionPendingException.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public class NoConnectionPendingException extends IllegalStateException
+{
+ private static final long serialVersionUID = - 8296561183633134743L;
+
+ /**
+ * Creates the exception
+ */
+ public NoConnectionPendingException()
+ {
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/NonReadableChannelException.java b/libjava/classpath/java/nio/channels/NonReadableChannelException.java
new file mode 100644
index 000000000..bf4f4a433
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/NonReadableChannelException.java
@@ -0,0 +1,55 @@
+/* NonReadableChannelException.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public class NonReadableChannelException extends IllegalStateException
+{
+ private static final long serialVersionUID = - 3200915679294993514L;
+
+ /**
+ * Creates the exception
+ */
+ public NonReadableChannelException()
+ {
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/NonWritableChannelException.java b/libjava/classpath/java/nio/channels/NonWritableChannelException.java
new file mode 100644
index 000000000..98c86eae2
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/NonWritableChannelException.java
@@ -0,0 +1,55 @@
+/* NonWritableChannelException.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public class NonWritableChannelException extends IllegalStateException
+{
+ private static final long serialVersionUID = - 7071230488279011621L;
+
+ /**
+ * Creates the exception
+ */
+ public NonWritableChannelException()
+ {
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/NotYetBoundException.java b/libjava/classpath/java/nio/channels/NotYetBoundException.java
new file mode 100644
index 000000000..74bf1ed7f
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/NotYetBoundException.java
@@ -0,0 +1,55 @@
+/* NotYetBoundException.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public class NotYetBoundException extends IllegalStateException
+{
+ private static final long serialVersionUID = 4640999303950202242L;
+
+ /**
+ * Creates the exception
+ */
+ public NotYetBoundException()
+ {
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/NotYetConnectedException.java b/libjava/classpath/java/nio/channels/NotYetConnectedException.java
new file mode 100644
index 000000000..083ff6c6d
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/NotYetConnectedException.java
@@ -0,0 +1,55 @@
+/* NotYetConnectedException.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public class NotYetConnectedException extends IllegalStateException
+{
+ private static final long serialVersionUID = 4697316551909513464L;
+
+ /**
+ * Creates the exception
+ */
+ public NotYetConnectedException()
+ {
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/OverlappingFileLockException.java b/libjava/classpath/java/nio/channels/OverlappingFileLockException.java
new file mode 100644
index 000000000..aa2cedd9a
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/OverlappingFileLockException.java
@@ -0,0 +1,55 @@
+/* OverlappingFileLockException.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public class OverlappingFileLockException extends IllegalStateException
+{
+ private static final long serialVersionUID = 2047812138163068433L;
+
+ /**
+ * Creates the exception
+ */
+ public OverlappingFileLockException()
+ {
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/Pipe.java b/libjava/classpath/java/nio/channels/Pipe.java
new file mode 100644
index 000000000..c7b04c88c
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/Pipe.java
@@ -0,0 +1,121 @@
+/* Pipe.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+import java.io.IOException;
+import java.nio.channels.spi.AbstractSelectableChannel;
+import java.nio.channels.spi.SelectorProvider;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public abstract class Pipe
+{
+ public abstract static class SinkChannel extends AbstractSelectableChannel
+ implements WritableByteChannel, GatheringByteChannel
+ {
+ /**
+ * Initializes the channel.
+ */
+ protected SinkChannel(SelectorProvider provider)
+ {
+ super(provider);
+ }
+
+ /**
+ * Returns an operation set that is valid on this channel.
+ *
+ * The only valid operation on this channel is @see SelectionKey.OP_WRITE.
+ */
+ public final int validOps()
+ {
+ return SelectionKey.OP_WRITE;
+ }
+ }
+
+ public abstract static class SourceChannel extends AbstractSelectableChannel
+ implements ReadableByteChannel, ScatteringByteChannel
+ {
+ /**
+ * Initializes the channel.
+ */
+ protected SourceChannel(SelectorProvider provider)
+ {
+ super(provider);
+ }
+
+ /**
+ * Returns an operation set that is valid on this channel.
+ *
+ * The only valid operation on this channel is @see SelectionKey.OP_READ.
+ */
+ public final int validOps()
+ {
+ return SelectionKey.OP_READ;
+ }
+ }
+
+ /**
+ * Initializes the pipe.
+ */
+ protected Pipe()
+ {
+ }
+
+ /**
+ * Opens a pipe.
+ *
+ * @exception IOException If an error occurs
+ */
+ public static Pipe open() throws IOException
+ {
+ return SelectorProvider.provider().openPipe();
+ }
+
+ /**
+ * Returns a pipe's sink channel.
+ */
+ public abstract Pipe.SinkChannel sink();
+
+ /**
+ * Returns a pipe's source channel
+ */
+ public abstract Pipe.SourceChannel source();
+}
diff --git a/libjava/classpath/java/nio/channels/ReadableByteChannel.java b/libjava/classpath/java/nio/channels/ReadableByteChannel.java
new file mode 100644
index 000000000..889662de0
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/ReadableByteChannel.java
@@ -0,0 +1,64 @@
+/* ReadableByteChannel.java --
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+
+public interface ReadableByteChannel extends Channel
+{
+ /**
+ * Reads a sequence of bytes from this channel into the given buffer
+ *
+ * @param dst the buffer to put the read data into
+ *
+ * @return the numer of bytes read
+ *
+ * @exception AsynchronousCloseException If another thread closes this
+ * channel while the read operation is in progress
+ * @exception ClosedByInterruptException If another thread interrupts the
+ * current thread while the read operation is in progress, thereby closing
+ * the channel and setting the current thread's interrupt status
+ * @exception ClosedChannelException If this channel is closed
+ * @exception IOException If an error occurs
+ * @exception NonReadableChannelException If this channel was not opened for
+ * reading
+ */
+ int read(ByteBuffer dst) throws IOException;
+}
diff --git a/libjava/classpath/java/nio/channels/ScatteringByteChannel.java b/libjava/classpath/java/nio/channels/ScatteringByteChannel.java
new file mode 100644
index 000000000..5437ea158
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/ScatteringByteChannel.java
@@ -0,0 +1,79 @@
+/* ScatteringByteChannel.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+
+public interface ScatteringByteChannel extends ReadableByteChannel
+{
+ /**
+ * Reads a sequence of bytes from this channel into a subsequence of the
+ * given buffers
+ *
+ * @exception AsynchronousCloseException If another thread closes this
+ * channel while the write operation is in progress
+ * @exception ClosedByInterruptException If another thread interrupts the
+ * current thread while the write operation is in progress, thereby closing
+ * the channel and setting the current thread's interrupt status
+ * @exception ClosedChannelException If this channel is closed
+ * @exception IndexOutOfBoundsException If the preconditions on the offset
+ * and length parameters do not hold
+ * @exception IOException If an error occurs
+ * @exception NonReadableChannelException If this channel was not opened for
+ * reading
+ */
+ long read(ByteBuffer[] srcs, int offset, int length)
+ throws IOException;
+
+ /**
+ * Reads a sequence of bytes from this channel into the given buffers
+ *
+ * @exception AsynchronousCloseException If another thread closes this
+ * channel while the write operation is in progress
+ * @exception ClosedByInterruptException If another thread interrupts the
+ * current thread while the write operation is in progress, thereby closing
+ * the channel and setting the current thread's interrupt status
+ * @exception ClosedChannelException If this channel is closed
+ * @exception IOException If an error occurs
+ * @exception NonReadableChannelException If this channel was not opened for
+ * reading
+ */
+ long read(ByteBuffer[] srcs) throws IOException;
+}
diff --git a/libjava/classpath/java/nio/channels/SelectableChannel.java b/libjava/classpath/java/nio/channels/SelectableChannel.java
new file mode 100644
index 000000000..70fa785ce
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/SelectableChannel.java
@@ -0,0 +1,140 @@
+/* SelectableChannel.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+import java.io.IOException;
+import java.nio.channels.spi.AbstractInterruptibleChannel;
+import java.nio.channels.spi.SelectorProvider;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public abstract class SelectableChannel extends AbstractInterruptibleChannel
+{
+ /**
+ * Initializes the channel.
+ */
+ protected SelectableChannel()
+ {
+ }
+
+ /**
+ * Returns the lock of this channel.
+ */
+ public abstract Object blockingLock();
+
+ /**
+ * Adjusts this channel's blocking mode.
+ *
+ * @exception ClosedChannelException If this channel is closed.
+ * @exception IllegalBlockingModeException If block is true and this channel
+ * is registered with one or more selectors.
+ * @exception IOException If an error occurs.
+ */
+ public abstract SelectableChannel configureBlocking(boolean block)
+ throws IOException;
+
+ /**
+ * Tells whether this channel is blocking or not.
+ */
+ public abstract boolean isBlocking();
+
+ /**
+ * Tells whether or not this channel is currently registered with
+ * any selectors.
+ */
+ public abstract boolean isRegistered();
+
+ /**
+ * Retrieves the key representing the channel's registration with
+ * the given selector.
+ */
+ public abstract SelectionKey keyFor(Selector sel);
+
+ /**
+ * Returns the provider that created this channel.
+ */
+ public abstract SelectorProvider provider();
+
+ /**
+ * Registers this channel with the given selector,
+ * returning a selection key.
+ *
+ * @exception CancelledKeyException If this channel is currently registered
+ * with the given selector but the corresponding key has already been cancelled
+ * @exception ClosedChannelException If this channel is closed.
+ * @exception IllegalArgumentException If a bit in ops does not correspond
+ * to an operation that is supported by this channel, that is, if
+ * set &amp; ~validOps() != 0.
+ * @exception IllegalBlockingModeException If block is true and this channel
+ * is registered with one or more selectors.
+ * @exception IllegalSelectorException If this channel was not created by
+ * the same provider as the given selector.
+ */
+ public final SelectionKey register(Selector sel, int ops)
+ throws ClosedChannelException
+ {
+ return register(sel, ops, null);
+ }
+
+ /**
+ * Registers this channel with the given selector,
+ * returning a selection key.
+ *
+ * @exception CancelledKeyException If this channel is currently registered
+ * with the given selector but the corresponding key has already been
+ * cancelled.
+ * @exception ClosedChannelException If this channel is closed.
+ * @exception IllegalArgumentException If a bit in ops does not correspond
+ * to an operation that is supported by this channel, that is, if
+ * set &amp; ~validOps() != 0.
+ * @exception IllegalBlockingModeException If block is true and this channel
+ * is registered with one or more selectors.
+ * @exception IllegalSelectorException If this channel was not created by
+ * the same provider as the given selector.
+ */
+ public abstract SelectionKey register(Selector sel, int ops, Object att)
+ throws ClosedChannelException;
+
+ /**
+ * Returns a set of valid operations on this channel.
+ */
+ public abstract int validOps();
+}
diff --git a/libjava/classpath/java/nio/channels/SelectionKey.java b/libjava/classpath/java/nio/channels/SelectionKey.java
new file mode 100644
index 000000000..9723faf52
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/SelectionKey.java
@@ -0,0 +1,164 @@
+/* SelectionKey.java --
+ Copyright (C) 2002, 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public abstract class SelectionKey
+{
+ public static final int OP_ACCEPT = 16;
+ public static final int OP_CONNECT = 8;
+ public static final int OP_READ = 1;
+ public static final int OP_WRITE = 4;
+ Object attached;
+
+ /**
+ * Initializes the selection key.
+ */
+ protected SelectionKey()
+ {
+ }
+
+ /**
+ * Attaches obj to the key and returns the old attached object.
+ */
+ public final synchronized Object attach(Object obj)
+ {
+ Object old = attached;
+ attached = obj;
+ return old;
+ }
+
+ /**
+ * Returns the object attached to the key.
+ */
+ public final synchronized Object attachment()
+ {
+ return attached;
+ }
+
+ /**
+ * Tests if the channel attached to this key is ready to accept
+ * a new socket connection.
+ *
+ * @exception CancelledKeyException If this key has been cancelled
+ */
+ public final boolean isAcceptable()
+ {
+ return (readyOps() & OP_ACCEPT) != 0;
+ }
+
+ /**
+ * Tests whether this key's channel has either finished,
+ * or failed to finish, its socket-connection operation.
+ *
+ * @exception CancelledKeyException If this key has been cancelled
+ */
+ public final boolean isConnectable()
+ {
+ return (readyOps() & OP_CONNECT) != 0;
+ }
+
+ /**
+ * Tests if the channel attached to the key is readable.
+ *
+ * @exception CancelledKeyException If this key has been cancelled
+ */
+ public final boolean isReadable()
+ {
+ return (readyOps() & OP_READ) != 0;
+ }
+
+ /**
+ * Tests if the channel attached to the key is writable.
+ *
+ * @exception CancelledKeyException If this key has been cancelled
+ */
+ public final boolean isWritable()
+ {
+ return (readyOps() & OP_WRITE) != 0;
+ }
+
+ /**
+ * Requests that the registration of this key's channel with
+ * its selector be cancelled.
+ */
+ public abstract void cancel();
+
+ /**
+ * return the channel attached to the key.
+ */
+ public abstract SelectableChannel channel();
+
+ /**
+ * Returns the key's interest set.
+ *
+ * @exception CancelledKeyException If this key has been cancelled
+ */
+ public abstract int interestOps();
+
+ /**
+ * Sets this key's interest set to the given value.
+ *
+ * @exception CancelledKeyException If this key has been cancelled
+ * @exception IllegalArgumentException If a bit in the set does not
+ * correspond to an operation that is supported by this key's channel,
+ * that is, if set &amp; ~(channel().validOps()) != 0
+ */
+ public abstract SelectionKey interestOps(int ops);
+
+ /**
+ * Tells whether or not this key is valid.
+ */
+ public abstract boolean isValid();
+
+ /**
+ * Retrieves this key's ready-operation set.
+ *
+ * @exception CancelledKeyException If this key has been cancelled
+ */
+ public abstract int readyOps();
+
+ /**
+ * Returns the selector for which this key was created.
+ */
+ public abstract Selector selector();
+}
diff --git a/libjava/classpath/java/nio/channels/Selector.java b/libjava/classpath/java/nio/channels/Selector.java
new file mode 100644
index 000000000..1c09db702
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/Selector.java
@@ -0,0 +1,134 @@
+/* Selector.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+import java.io.IOException;
+import java.nio.channels.spi.SelectorProvider;
+import java.util.Set;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public abstract class Selector
+{
+ /**
+ * Initializes the selector.
+ */
+ protected Selector()
+ {
+ }
+
+ /**
+ * Opens a selector.
+ *
+ * @exception IOException If an error occurs
+ */
+ public static Selector open() throws IOException
+ {
+ return SelectorProvider.provider().openSelector();
+ }
+
+ /**
+ * Closes the selector.
+ *
+ * @exception IOException If an error occurs
+ */
+ public abstract void close() throws IOException;
+
+ /**
+ * Tells whether the selector is open or not.
+ */
+ public abstract boolean isOpen();
+
+ /**
+ * Returns this selector's key set.
+ *
+ * @exception ClosedSelectorException If this selector is closed.
+ */
+ public abstract Set<SelectionKey> keys();
+
+ /**
+ * Returns the SelectorProvider that created the selector.
+ */
+ public abstract SelectorProvider provider();
+
+ /**
+ * Selects a set of keys whose corresponding channels are ready
+ * for I/O operations.
+ *
+ * @exception ClosedSelectorException If this selector is closed.
+ * @exception IOException If an error occurs
+ */
+ public abstract int select() throws IOException;
+
+ /**
+ * Selects a set of keys whose corresponding channels are ready
+ * for I/O operations.
+ *
+ * @param timeout The timeout to use.
+ *
+ * @exception ClosedSelectorException If this selector is closed.
+ * @exception IllegalArgumentException If the timeout value is negative.
+ * @exception IOException If an error occurs
+ */
+ public abstract int select(long timeout) throws IOException;
+
+ /**
+ * Returns this selector's selected-key set.
+ *
+ * @exception ClosedSelectorException If this selector is closed.
+ */
+ public abstract Set<SelectionKey> selectedKeys();
+
+ /**
+ * Selects a set of keys whose corresponding channels are ready
+ * for I/O operations.
+ *
+ * @exception ClosedSelectorException If this selector is closed.
+ * @exception IOException If an error occurs
+ */
+ public abstract int selectNow() throws IOException;
+
+ /**
+ * Causes the first selection operation that has not yet returned to
+ * return immediately.
+ */
+ public abstract Selector wakeup();
+}
diff --git a/libjava/classpath/java/nio/channels/ServerSocketChannel.java b/libjava/classpath/java/nio/channels/ServerSocketChannel.java
new file mode 100644
index 000000000..105d17f94
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/ServerSocketChannel.java
@@ -0,0 +1,98 @@
+/* ServerSocketChannel.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.nio.channels.spi.AbstractSelectableChannel;
+import java.nio.channels.spi.SelectorProvider;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public abstract class ServerSocketChannel extends AbstractSelectableChannel
+{
+ /**
+ * Initializes this channel.
+ */
+ protected ServerSocketChannel(SelectorProvider provider)
+ {
+ super(provider);
+ }
+
+ /**
+ * Accepts a connection made to this channel's socket.
+ *
+ * @exception IOException If an error occurs
+ * @exception AsynchronousCloseException If another thread closes this
+ * channel while the accept operation is in progress.
+ * @exception ClosedByInterruptException If another thread interrupts the
+ * current thread while the accept operation is in progress, thereby closing
+ * the channel and setting the current thread's interrupt status.
+ * @exception ClosedChannelException If the channel is closed.
+ * @exception NotYetBoundException If the channel's socket is not yet bound.
+ * @exception SecurityException If a security manager has been installed and
+ * it does not permit access to the remote endpoint of the new connection.
+ */
+ public abstract SocketChannel accept() throws IOException;
+
+ /**
+ * Retrieves the channels socket.
+ */
+ public abstract ServerSocket socket();
+
+ /**
+ * Opens a server socket channel.
+ *
+ * @exception IOException If an error occurs
+ */
+ public static ServerSocketChannel open() throws IOException
+ {
+ return SelectorProvider.provider().openServerSocketChannel();
+ }
+
+ /**
+ * Retrieves the valid operations for this channel.
+ */
+ public final int validOps()
+ {
+ return SelectionKey.OP_ACCEPT;
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/SocketChannel.java b/libjava/classpath/java/nio/channels/SocketChannel.java
new file mode 100644
index 000000000..324c9816b
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/SocketChannel.java
@@ -0,0 +1,248 @@
+/* SocketChannel.java --
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.nio.channels;
+
+import java.io.IOException;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.channels.spi.AbstractSelectableChannel;
+import java.nio.channels.spi.SelectorProvider;
+
+/**
+ * @author Michael Koch (konqueror@gmx.de)
+ * @since 1.4
+ */
+public abstract class SocketChannel extends AbstractSelectableChannel
+ implements ByteChannel, ScatteringByteChannel, GatheringByteChannel
+{
+ /**
+ * Initializes this socket channel.
+ */
+ protected SocketChannel(SelectorProvider provider)
+ {
+ super(provider);
+ }
+
+ /**
+ * Opens a socket channel.
+ *
+ * @return the new <code>SocketChannel</code> object
+ *
+ * @exception IOException If an error occurs
+ */
+ public static SocketChannel open() throws IOException
+ {
+ return SelectorProvider.provider().openSocketChannel();
+ }
+
+ /**
+ * Opens a channel and connects it to a remote address.
+ *
+ * @return the new <code>SocketChannel</code> object
+ *
+ * @exception AsynchronousCloseException If this channel is already connected.
+ * @exception ClosedByInterruptException If another thread interrupts the
+ * current thread while the connect operation is in progress, thereby closing
+ * the channel and setting the current thread's interrupt status.
+ * @exception IOException If an error occurs
+ * @exception SecurityException If a security manager has been installed and
+ * it does not permit access to the given remote endpoint.
+ * @exception UnresolvedAddressException If the given remote address is not
+ * fully resolved.
+ * @exception UnsupportedAddressTypeException If the type of the given remote
+ * address is not supported.
+ */
+ public static SocketChannel open(SocketAddress remote)
+ throws IOException
+ {
+ SocketChannel ch = open();
+ ch.connect(remote);
+ return ch;
+ }
+
+ /**
+ * Reads data from the channel.
+ *
+ * @return the number of bytes read, zero is valid too, -1 if end of stream
+ * is reached
+ *
+ * @exception IOException If an error occurs
+ * @exception NotYetConnectedException If this channel is not yet connected.
+ */
+ public final long read(ByteBuffer[] dsts) throws IOException
+ {
+ long b = 0;
+
+ for (int i = 0; i < dsts.length; i++)
+ b += read(dsts[i]);
+
+ return b;
+ }
+
+ /**
+ * Writes data to the channel.
+ *
+ * @return the number of bytes written, zero is valid too
+ *
+ * @exception IOException If an error occurs
+ * @exception NotYetConnectedException If this channel is not yet connected.
+ */
+ public final long write(ByteBuffer[] dsts) throws IOException
+ {
+ long b = 0;
+
+ for (int i = 0; i < dsts.length; i++)
+ b += write(dsts[i]);
+
+ return b;
+ }
+
+ /**
+ * Retrieves the valid operations for this channel.
+ *
+ * @return the valid operations
+ */
+ public final int validOps()
+ {
+ return SelectionKey.OP_CONNECT | SelectionKey.OP_READ
+ | SelectionKey.OP_WRITE;
+ }
+
+ /**
+ * Reads data from the channel.
+ *
+ * @return the number of bytes read, zero is valid too, -1 if end of stream
+ * is reached
+ *
+ * @exception IOException If an error occurs
+ * @exception NotYetConnectedException If this channel is not yet connected.
+ */
+ public abstract int read(ByteBuffer dst) throws IOException;
+
+ /**
+ * Connects the channel's socket to the remote address.
+ *
+ * @return <code>true</code> if the channel got successfully connected,
+ * <code>false</code> if the channel is in non-blocking mode and connection
+ * operation is still in progress.
+ *
+ * @exception AlreadyConnectedException If this channel is already connected.
+ * @exception AsynchronousCloseException If this channel is already connected.
+ * @exception ClosedByInterruptException If another thread interrupts the
+ * current thread while the connect operation is in progress, thereby closing
+ * the channel and setting the current thread's interrupt status.
+ * @exception ClosedChannelException If this channel is closed.
+ * @exception ConnectionPendingException If a non-blocking connection
+ * operation is already in progress on this channel.
+ * @exception IOException If an error occurs
+ * @exception SecurityException If a security manager has been installed and
+ * it does not permit access to the given remote endpoint.
+ * @exception UnresolvedAddressException If the given remote address is not
+ * fully resolved.
+ * @exception UnsupportedAddressTypeException If the type of the given remote
+ * address is not supported.
+ */
+ public abstract boolean connect(SocketAddress remote)
+ throws IOException;
+
+ /**
+ * Finishes the process of connecting a socket channel.
+ *
+ * @exception AsynchronousCloseException If this channel is already connected.
+ * @exception ClosedByInterruptException If another thread interrupts the
+ * current thread while the connect operation is in progress, thereby closing
+ * the channel and setting the current thread's interrupt status.
+ * @exception ClosedChannelException If this channel is closed.
+ * @exception IOException If an error occurs
+ * @exception NoConnectionPendingException If this channel is not connected
+ * and a connection operation has not been initiated.
+ */
+ public abstract boolean finishConnect() throws IOException;
+
+ /**
+ * Tells whether or not the channel's socket is connected.
+ */
+ public abstract boolean isConnected();
+
+ /**
+ * Tells whether or not a connection operation is in progress on this channel.
+ */
+ public abstract boolean isConnectionPending();
+
+ /**
+ * Reads data from the channel.
+ *
+ * @return the number of bytes read, zero is valid too, -1 if end of stream
+ * is reached
+ *
+ * @exception IOException If an error occurs
+ * @exception NotYetConnectedException If this channel is not yet connected.
+ */
+ public abstract long read(ByteBuffer[] dsts, int offset, int length)
+ throws IOException;
+
+ /**
+ * Retrieves the channel's socket.
+ *
+ * @return the socket
+ */
+ public abstract Socket socket();
+
+ /**
+ * Writes data to the channel.
+ *
+ * @return the number of bytes written, zero is valid too
+ *
+ * @exception IOException If an error occurs
+ * @exception NotYetConnectedException If this channel is not yet connected.
+ */
+ public abstract int write(ByteBuffer src) throws IOException;
+
+ /**
+ * Writes data to the channel.
+ *
+ * @return the number of bytes written, zero is valid too
+ *
+ * @exception IOException If an error occurs
+ * @exception NotYetConnectedException If this channel is not yet connected.
+ */
+ public abstract long write(ByteBuffer[] srcs, int offset, int length)
+ throws IOException;
+}
diff --git a/libjava/classpath/java/nio/channels/UnresolvedAddressException.java b/libjava/classpath/java/nio/channels/UnresolvedAddressException.java
new file mode 100644
index 000000000..7a591709b
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/UnresolvedAddressException.java
@@ -0,0 +1,55 @@
+/* UnresolvedAddressException.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public class UnresolvedAddressException extends IllegalArgumentException
+{
+ private static final long serialVersionUID = 6136959093620794148L;
+
+ /**
+ * Creates the exception
+ */
+ public UnresolvedAddressException()
+ {
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/UnsupportedAddressTypeException.java b/libjava/classpath/java/nio/channels/UnsupportedAddressTypeException.java
new file mode 100644
index 000000000..759d0964c
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/UnsupportedAddressTypeException.java
@@ -0,0 +1,55 @@
+/* UnsupportedAddressTypeException.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public class UnsupportedAddressTypeException extends IllegalArgumentException
+{
+ private static final long serialVersionUID = - 2964323842829700493L;
+
+ /**
+ * Creates the exception
+ */
+ public UnsupportedAddressTypeException()
+ {
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/WritableByteChannel.java b/libjava/classpath/java/nio/channels/WritableByteChannel.java
new file mode 100644
index 000000000..3845723bc
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/WritableByteChannel.java
@@ -0,0 +1,60 @@
+/* WritableByteChannel.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+
+public interface WritableByteChannel extends Channel
+{
+ /**
+ * Writes a sequence of bytes to this channel from the given buffer
+ *
+ * @exception AsynchronousCloseException If another thread closes this
+ * channel while the write operation is in progress
+ * @exception ClosedByInterruptException If another thread interrupts the
+ * current thread while the write operation is in progress, thereby closing
+ * the channel and setting the current thread's interrupt status
+ * @exception ClosedChannelException If this channel is closed
+ * @exception IOException If an error occurs
+ * @exception NonWritableChannelException If this channel was not opened for
+ * writing
+ */
+ int write(ByteBuffer src) throws IOException;
+}
diff --git a/libjava/classpath/java/nio/channels/package.html b/libjava/classpath/java/nio/channels/package.html
new file mode 100644
index 000000000..4e2bbc9f6
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/package.html
@@ -0,0 +1,47 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in java.nio.channels package.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. -->
+
+<html>
+<head><title>GNU Classpath - java.nio.channels</title></head>
+
+<body>
+<p>Classes for creating, selecting and non-blocking reading and writing of
+buffers from files and sockets.</p>
+
+</body>
+</html>
diff --git a/libjava/classpath/java/nio/channels/spi/AbstractInterruptibleChannel.java b/libjava/classpath/java/nio/channels/spi/AbstractInterruptibleChannel.java
new file mode 100644
index 000000000..b1ed7c7f2
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/spi/AbstractInterruptibleChannel.java
@@ -0,0 +1,119 @@
+/* AbstractInterruptibleChannel.java --
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels.spi;
+
+import java.io.IOException;
+import java.nio.channels.AsynchronousCloseException;
+import java.nio.channels.Channel;
+import java.nio.channels.ClosedByInterruptException;
+import java.nio.channels.InterruptibleChannel;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public abstract class AbstractInterruptibleChannel
+ implements Channel, InterruptibleChannel
+{
+ private boolean closed;
+
+ /**
+ * Initializes the channel.
+ */
+ protected AbstractInterruptibleChannel()
+ {
+ }
+
+ /**
+ * Marks the beginning of an I/O operation that might block indefinitely.
+ */
+ protected final void begin()
+ {
+ }
+
+ /**
+ * Closes the channel.
+ *
+ * @exception IOException If an error occurs
+ */
+ public final void close() throws IOException
+ {
+ if (! closed)
+ {
+ closed = true;
+ implCloseChannel();
+ }
+ }
+
+ /**
+ * Marks the end of an I/O operation that might block indefinitely.
+ *
+ * @param completed true if the task completed successfully,
+ * false otherwise
+ *
+ * @exception AsynchronousCloseException If the channel was asynchronously
+ * closed.
+ * @exception ClosedByInterruptException If the thread blocked in the
+ * I/O operation was interrupted.
+ */
+ protected final void end(boolean completed)
+ throws AsynchronousCloseException
+ {
+ // FIXME: check more here.
+
+ if (closed) throw new AsynchronousCloseException();
+ }
+
+ /**
+ * Closes the channel.
+ *
+ * @exception IOException If an error occurs
+ */
+ protected abstract void implCloseChannel() throws IOException;
+
+ /**
+ * Tells whether or not this channel is open.
+ *
+ * @return true if the channel is open, false otherwise
+ */
+ public final boolean isOpen()
+ {
+ return ! closed;
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/spi/AbstractSelectableChannel.java b/libjava/classpath/java/nio/channels/spi/AbstractSelectableChannel.java
new file mode 100644
index 000000000..97ed685b8
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/spi/AbstractSelectableChannel.java
@@ -0,0 +1,271 @@
+/* AbstractSelectableChannel.java
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.nio.channels.spi;
+
+import java.io.IOException;
+import java.nio.channels.ClosedChannelException;
+import java.nio.channels.SelectableChannel;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+import java.nio.channels.IllegalBlockingModeException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.ListIterator;
+
+public abstract class AbstractSelectableChannel extends SelectableChannel
+{
+ private boolean blocking = true;
+ private Object LOCK = new Object();
+ private SelectorProvider provider;
+ private LinkedList keys = new LinkedList();
+
+ /**
+ * Initializes the channel
+ *
+ * @param provider the provider that created this channel
+ */
+ protected AbstractSelectableChannel(SelectorProvider provider)
+ {
+ this.provider = provider;
+ }
+
+ /**
+ * Retrieves the object upon which the configureBlocking and register
+ * methods synchronize.
+ *
+ * @return the blocking lock
+ */
+ public final Object blockingLock()
+ {
+ return LOCK;
+ }
+
+ /**
+ * Adjusts this channel's blocking mode.
+ *
+ * @param blocking true if blocking should be enabled, false otherwise
+ *
+ * @return this channel
+ *
+ * @exception IOException If an error occurs
+ */
+ public final SelectableChannel configureBlocking(boolean blocking)
+ throws IOException
+ {
+ synchronized (blockingLock())
+ {
+ if (this.blocking != blocking)
+ {
+ implConfigureBlocking(blocking);
+ this.blocking = blocking;
+ }
+ }
+
+ return this;
+ }
+
+ /**
+ * Closes this channel.
+ *
+ * @exception IOException If an error occurs
+ */
+ protected final void implCloseChannel() throws IOException
+ {
+ try
+ {
+ implCloseSelectableChannel();
+ }
+ finally
+ {
+ for (Iterator it = keys.iterator(); it.hasNext(); )
+ ((SelectionKey) it.next()).cancel();
+ }
+ }
+
+ /**
+ * Closes this selectable channel.
+ *
+ * @exception IOException If an error occurs
+ */
+ protected abstract void implCloseSelectableChannel()
+ throws IOException;
+
+ /**
+ * Adjusts this channel's blocking mode.
+ *
+ * @param blocking true if blocking should be enabled, false otherwise
+ *
+ * @exception IOException If an error occurs
+ */
+ protected abstract void implConfigureBlocking(boolean blocking)
+ throws IOException;
+
+ /**
+ * Tells whether or not every I/O operation on this channel will block
+ * until it completes.
+ *
+ * @return true of this channel is blocking, false otherwise
+ */
+ public final boolean isBlocking()
+ {
+ return blocking;
+ }
+
+ /**
+ * Tells whether or not this channel is currently registered with
+ * any selectors.
+ *
+ * @return true if this channel is registered, false otherwise
+ */
+ public final boolean isRegistered()
+ {
+ return ! keys.isEmpty();
+ }
+
+ /**
+ * Retrieves the key representing the channel's registration with the
+ * given selector.
+ *
+ * @param selector the selector to get a selection key for
+ *
+ * @return the selection key this channel is registered with
+ */
+ public final SelectionKey keyFor(Selector selector)
+ {
+ if (! isOpen())
+ return null;
+
+ try
+ {
+ synchronized (blockingLock())
+ {
+ return locate(selector);
+ }
+ }
+ catch (Exception e)
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Returns the provider that created this channel.
+ *
+ * @return the selector provider that created this channel
+ */
+ public final SelectorProvider provider()
+ {
+ return provider;
+ }
+
+ private SelectionKey locate(Selector selector)
+ {
+ ListIterator it = keys.listIterator();
+
+ while (it.hasNext())
+ {
+ SelectionKey key = (SelectionKey) it.next();
+
+ if (key.selector() == selector)
+ return key;
+ }
+
+ return null;
+ }
+
+ /**
+ * Registers this channel with the given selector, returning a selection key.
+ *
+ * @param selin the seletor to use
+ * @param ops the interested operations
+ * @param att an attachment for the returned selection key
+ *
+ * @return the registered selection key
+ *
+ * @exception ClosedChannelException If the channel is already closed.
+ * @exception IllegalBlockingModeException If the channel is configured in
+ * blocking mode.
+ */
+ public final SelectionKey register(Selector selin, int ops, Object att)
+ throws ClosedChannelException
+ {
+ if (! isOpen())
+ throw new ClosedChannelException();
+
+ if ((ops & ~validOps()) != 0)
+ throw new IllegalArgumentException();
+
+ SelectionKey key = null;
+ AbstractSelector selector = (AbstractSelector) selin;
+
+ synchronized (blockingLock())
+ {
+ if (blocking)
+ throw new IllegalBlockingModeException();
+
+ key = locate(selector);
+
+ if (key != null && key.isValid())
+ {
+ key.interestOps(ops);
+ key.attach(att);
+ }
+ else
+ {
+ key = selector.register(this, ops, att);
+
+ if (key != null)
+ addSelectionKey(key);
+ }
+ }
+
+ return key;
+ }
+
+ void addSelectionKey(SelectionKey key)
+ {
+ keys.add(key);
+ }
+
+ // This method gets called by AbstractSelector.deregister().
+ void removeSelectionKey(SelectionKey key)
+ {
+ keys.remove(key);
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/spi/AbstractSelectionKey.java b/libjava/classpath/java/nio/channels/spi/AbstractSelectionKey.java
new file mode 100644
index 000000000..e0dc03f53
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/spi/AbstractSelectionKey.java
@@ -0,0 +1,78 @@
+/* AbstractSelectionKey.java --
+ Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels.spi;
+
+import java.nio.channels.SelectionKey;
+
+
+/**
+ * @since 1.4
+ */
+public abstract class AbstractSelectionKey extends SelectionKey
+{
+ private boolean cancelled;
+
+ /**
+ * Initializes the key.
+ */
+ protected AbstractSelectionKey()
+ {
+ }
+
+ /**
+ * Cancels this key.
+ */
+ public final synchronized void cancel()
+ {
+ if (isValid())
+ {
+ ((AbstractSelector) selector()).cancelKey(this);
+ cancelled = true;
+ }
+ }
+
+ /**
+ * Tells whether this key is valid or not.
+ *
+ * @return true if this key is valid, false otherwise
+ */
+ public final synchronized boolean isValid()
+ {
+ return ! cancelled;
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/spi/AbstractSelector.java b/libjava/classpath/java/nio/channels/spi/AbstractSelector.java
new file mode 100644
index 000000000..b67d4aecc
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/spi/AbstractSelector.java
@@ -0,0 +1,167 @@
+/* AbstractSelector.java --
+ Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels.spi;
+
+import java.io.IOException;
+import java.nio.channels.ClosedSelectorException;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+import java.util.HashSet;
+import java.util.Set;
+
+
+public abstract class AbstractSelector extends Selector
+{
+ private boolean closed;
+ private SelectorProvider provider;
+ private HashSet<SelectionKey> cancelledKeys;
+
+ /**
+ * Initializes the slector.
+ *
+ * @param provider the provider that created this selector
+ */
+ protected AbstractSelector(SelectorProvider provider)
+ {
+ this.provider = provider;
+ this.cancelledKeys = new HashSet<SelectionKey>();
+ }
+
+ /**
+ * Closes the channel.
+ *
+ * @exception IOException If an error occurs
+ */
+ public final synchronized void close() throws IOException
+ {
+ if (closed)
+ return;
+
+ implCloseSelector();
+ closed = true;
+ }
+
+ /**
+ * Tells whether this channel is open or not.
+ *
+ * @return true if channel is open, false otherwise.
+ */
+ public final boolean isOpen()
+ {
+ return ! closed;
+ }
+
+ /**
+ * Marks the beginning of an I/O operation that might block indefinitely.
+ */
+ protected final void begin()
+ {
+ }
+
+ /**
+ * Marks the end of an I/O operation that might block indefinitely.
+ */
+ protected final void end()
+ {
+ }
+
+ /**
+ * Returns the provider for this selector object.
+ *
+ * @return the SelectorProvider object that created this seletor
+ */
+ public final SelectorProvider provider()
+ {
+ return provider;
+ }
+
+ /**
+ * Returns the cancelled keys set.
+ *
+ * @return the cancelled keys set
+ */
+ protected final Set<SelectionKey> cancelledKeys()
+ {
+ if (! isOpen())
+ throw new ClosedSelectorException();
+
+ return cancelledKeys;
+ }
+
+ /**
+ * Cancels a selection key.
+ */
+
+ // This method is only called by AbstractSelectionKey.cancel().
+ final void cancelKey(AbstractSelectionKey key)
+ {
+ synchronized (cancelledKeys)
+ {
+ cancelledKeys.add(key);
+ }
+ }
+
+ /**
+ * Closes the channel.
+ *
+ * @exception IOException if an error occurs
+ */
+ protected abstract void implCloseSelector() throws IOException;
+
+ /**
+ * Registers a channel for the selection process.
+ *
+ * @param ch the channel register
+ * @param ops the interested operations
+ * @param att an attachement to the selection key
+ *
+ * @return the registered selection key
+ */
+ protected abstract SelectionKey register(AbstractSelectableChannel ch,
+ int ops, Object att);
+
+ /**
+ * Deregisters the given selection key.
+ *
+ * @param key the key to deregister
+ */
+ protected final void deregister(AbstractSelectionKey key)
+ {
+ ((AbstractSelectableChannel) key.channel()).removeSelectionKey(key);
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/spi/SelectorProvider.java b/libjava/classpath/java/nio/channels/spi/SelectorProvider.java
new file mode 100644
index 000000000..821bc4361
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/spi/SelectorProvider.java
@@ -0,0 +1,178 @@
+/* SelectorProvider.java
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.nio.channels.spi;
+
+import gnu.java.nio.SelectorProviderImpl;
+
+import java.io.IOException;
+import java.nio.channels.Channel;
+import java.nio.channels.DatagramChannel;
+import java.nio.channels.Pipe;
+import java.nio.channels.ServerSocketChannel;
+import java.nio.channels.SocketChannel;
+
+
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
+public abstract class SelectorProvider
+{
+ private static SelectorProvider systemDefaultProvider;
+
+ /**
+ * Initializes the selector provider.
+ *
+ * @exception SecurityException If a security manager has been installed and
+ * it denies @see RuntimePermission ("selectorProvider").
+ */
+ protected SelectorProvider()
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(new RuntimePermission("selectorProvider"));
+ }
+
+ /**
+ * Opens a datagram channel.
+ *
+ * @return a new datagram channel object
+ *
+ * @exception IOException if an error occurs
+ */
+ public abstract DatagramChannel openDatagramChannel()
+ throws IOException;
+
+ /**
+ * Opens a pipe.
+ *
+ * @return a new pipe object
+ *
+ * @exception IOException if an error occurs
+ */
+ public abstract Pipe openPipe() throws IOException;
+
+ /**
+ * Opens a selector.
+ *
+ * @return a new selector object
+ *
+ * @exception IOException if an error occurs
+ */
+ public abstract AbstractSelector openSelector() throws IOException;
+
+ /**
+ * Opens a server socket channel.
+ *
+ * @return a new server socket channel object
+ *
+ * @exception IOException if an error occurs
+ */
+ public abstract ServerSocketChannel openServerSocketChannel()
+ throws IOException;
+
+ /**
+ * Opens a socket channel.
+ *
+ * @return a new socket channel object
+ *
+ * @exception IOException if an error occurs
+ */
+ public abstract SocketChannel openSocketChannel() throws IOException;
+
+ /**
+ * Returns the inherited channel of the VM.
+ *
+ * @return the inherited channel of the VM
+ *
+ * @throws IOException If an I/O error occurs
+ * @throws SecurityException If an installed security manager denies access
+ * to RuntimePermission("inheritedChannel")
+ *
+ * @since 1.5
+ */
+ public Channel inheritedChannel()
+ throws IOException
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ {
+ sm.checkPermission(new RuntimePermission("inheritedChannel"));
+ }
+ // Implementation note: The default implementation can't do much more
+ // than return null. If a VM can provide something more useful it should
+ // install its own SelectorProvider (maybe a subclass of this one) to
+ // return something more useful.
+ return null;
+ }
+
+ /**
+ * Returns the system-wide default selector provider for this invocation
+ * of the Java virtual machine.
+ *
+ * @return the default seletor provider
+ */
+ public static synchronized SelectorProvider provider()
+ {
+ if (systemDefaultProvider == null)
+ {
+ String propertyValue =
+ System.getProperty("java.nio.channels.spi.SelectorProvider");
+
+ if (propertyValue == null || propertyValue.equals(""))
+ systemDefaultProvider = new SelectorProviderImpl();
+ else
+ {
+ try
+ {
+ systemDefaultProvider =
+ (SelectorProvider) Class.forName(propertyValue)
+ .newInstance();
+ }
+ catch (Exception e)
+ {
+ System.err.println("Could not instantiate class: "
+ + propertyValue);
+ systemDefaultProvider = new SelectorProviderImpl();
+ }
+ }
+ }
+
+ return systemDefaultProvider;
+ }
+}
diff --git a/libjava/classpath/java/nio/channels/spi/package.html b/libjava/classpath/java/nio/channels/spi/package.html
new file mode 100644
index 000000000..133fb04f2
--- /dev/null
+++ b/libjava/classpath/java/nio/channels/spi/package.html
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in java.nio.channels.spi package.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. -->
+
+<html>
+<head><title>GNU Classpath - java.nio.channels.spi</title></head>
+
+<body>
+<p>Utility classes and interfaces for implementing channels.</p>
+
+</body>
+</html>