Initial revision

From-SVN: r102074
This commit is contained in:
Tom Tromey
2005-07-16 00:30:23 +00:00
parent 6f4434b39b
commit f911ba985a
4557 changed files with 1000262 additions and 0 deletions
@@ -0,0 +1,48 @@
/* 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
{
/**
* Creates the exception
*/
public AlreadyConnectedException()
{
}
}
@@ -0,0 +1,53 @@
/* 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
{
/**
* Creates the exception
*/
public AsynchronousCloseException()
{
}
}
@@ -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
{
}
@@ -0,0 +1,53 @@
/* 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
{
/**
* Creates the exception
*/
public CancelledKeyException()
{
}
}
@@ -0,0 +1,59 @@
/* 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;
public interface Channel
{
/**
* 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;
}
@@ -0,0 +1,143 @@
/* 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.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;
/**
* @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)
{
// FIXME: implement java.nio.channels.Channel.newWriter(WritableByteChannel, CharsetEncoder, int)
throw new Error("not implemented");
}
/**
* 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);
}
}
@@ -0,0 +1,53 @@
/* 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
{
/**
* Creates the exception
*/
public ClosedByInterruptException()
{
}
}
@@ -0,0 +1,55 @@
/* 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
{
/**
* Creates the exception
*/
public ClosedChannelException()
{
}
}
@@ -0,0 +1,53 @@
/* 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
{
/**
* Creates the exception
*/
public ClosedSelectorException()
{
}
}
@@ -0,0 +1,53 @@
/* 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
{
/**
* Creates the exception
*/
public ConnectionPendingException()
{
}
}
@@ -0,0 +1,210 @@
/* 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 IOException If an error occurs.
* @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 IOException If an error occurs.
* @exception NotYetConnectedException The channel's socket is not connected.
*/
public final int validOps()
{
return SelectionKey.OP_READ | SelectionKey.OP_WRITE;
}
}
@@ -0,0 +1,367 @@
/* 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
{
long result = 0;
for (int i = 0; i < srcs.length; i++)
result += write(srcs[i]);
return result;
}
/**
* 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
{
long result = 0;
for (int i = 0; i < dsts.length; i++)
read(dsts[i]);
return result;
}
/**
* 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 assoziated 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 assoziated 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 assoziated 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 assoziated 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;
}
@@ -0,0 +1,150 @@
/* 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 java.io.IOException;
/**
* @since 1.4
*/
public abstract class FileLock
{
FileChannel channel;
long position;
long size;
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()
{
StringBuffer buf = new StringBuffer(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();
}
}
@@ -0,0 +1,55 @@
/* 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
{
/**
* Creates the exception
*/
public FileLockInterruptionException()
{
}
}
@@ -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;
}
@@ -0,0 +1,57 @@
/* 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
{
/**
* Creates the exception
*/
public IllegalBlockingModeException()
{
super();
}
}
@@ -0,0 +1,53 @@
/* 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
{
/**
* Creates the exception
*/
public IllegalSelectorException()
{
}
}
@@ -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;
}
@@ -0,0 +1,53 @@
/* 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
{
/**
* Creates the exception
*/
public NoConnectionPendingException()
{
}
}
@@ -0,0 +1,53 @@
/* 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
{
/**
* Creates the exception
*/
public NonReadableChannelException()
{
}
}
@@ -0,0 +1,53 @@
/* 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
{
/**
* Creates the exception
*/
public NonWritableChannelException()
{
}
}
@@ -0,0 +1,53 @@
/* 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
{
/**
* Creates the exception
*/
public NotYetBoundException()
{
}
}
@@ -0,0 +1,53 @@
/* 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
{
/**
* Creates the exception
*/
public NotYetConnectedException()
{
}
}
@@ -0,0 +1,53 @@
/* 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
{
/**
* Creates the exception
*/
public OverlappingFileLockException()
{
}
}
@@ -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();
}
@@ -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;
}
@@ -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;
}
@@ -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();
}
@@ -0,0 +1,164 @@
/* SelectionKey.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 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 Object attach(Object obj)
{
Object old = attached;
attached = obj;
return old;
}
/**
* Returns the object attached to the key.
*/
public final 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();
}
@@ -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 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 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();
}
@@ -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;
}
}
@@ -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;
}
@@ -0,0 +1,53 @@
/* 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
{
/**
* Creates the exception
*/
public UnresolvedAddressException()
{
}
}
@@ -0,0 +1,53 @@
/* 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
{
/**
* Creates the exception
*/
public UnsupportedAddressTypeException()
{
}
}
@@ -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;
}
@@ -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>
@@ -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.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 IOException if an error occurs
* @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;
}
}
@@ -0,0 +1,256 @@
/* 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.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
{
implCloseSelectableChannel();
}
/**
* 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.
*/
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())
{
key = locate(selector);
if (key != null && key.isValid())
{
if (att != null)
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);
}
}
@@ -0,0 +1,78 @@
/* AbstractSelectionKey.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.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 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 boolean isValid()
{
return ! cancelled;
}
}
@@ -0,0 +1,167 @@
/* AbstractSelector.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.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 cancelledKeys;
/**
* Initializes the slector.
*
* @param provider the provider that created this selector
*/
protected AbstractSelector(SelectorProvider provider)
{
this.provider = provider;
this.cancelledKeys = new HashSet();
}
/**
* 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 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);
}
}
@@ -0,0 +1,151 @@
/* 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.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 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;
}
}
@@ -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>