Commit 92e1fe67 by Michael Koch Committed by Michael Koch

Buffer.java, [...]: Fixed javadocs and jalopied all over java.nio.

2004-04-20  Michael Koch  <konqueror@gmx.de>

	* java/nio/Buffer.java,
	java/nio/channels/AlreadyConnectedException.java,
	java/nio/channels/AsynchronousCloseException.java,
	java/nio/channels/ByteChannel.java,
	java/nio/channels/CancelledKeyException.java,
	java/nio/channels/Channel.java,
	java/nio/channels/Channels.java,
	java/nio/channels/ClosedByInterruptException.java,
	java/nio/channels/ClosedChannelException.java,
	java/nio/channels/ClosedSelectorException.java,
	java/nio/channels/ConnectionPendingException.java,
	java/nio/channels/DatagramChannel.java,
	java/nio/channels/FileChannel.java,
	java/nio/channels/FileLock.java,
	java/nio/channels/FileLockInterruptionException.java,
	java/nio/channels/GatheringByteChannel.java,
	java/nio/channels/IllegalBlockingModeException.java,
	java/nio/channels/IllegalSelectorException.java,
	java/nio/channels/InterruptibleChannel.java,
	java/nio/channels/NoConnectionPendingException.java,
	java/nio/channels/NonReadableChannelException.java,
	java/nio/channels/NonWritableChannelException.java,
	java/nio/channels/NotYetBoundException.java,
	java/nio/channels/NotYetConnectedException.java,
	java/nio/channels/OverlappingFileLockException.java,
	java/nio/channels/Pipe.java,
	java/nio/channels/ReadableByteChannel.java,
	java/nio/channels/ScatteringByteChannel.java,
	java/nio/channels/SelectableChannel.java,
	java/nio/channels/SelectionKey.java,
	java/nio/channels/Selector.java,
	java/nio/channels/ServerSocketChannel.java,
	java/nio/channels/SocketChannel.java,
	java/nio/channels/UnresolvedAddressException.java,
	java/nio/channels/UnsupportedAddressTypeException.java,
	java/nio/channels/WritableByteChannel.java,
	java/nio/channels/spi/AbstractInterruptibleChannel.java,
	java/nio/channels/spi/AbstractSelectableChannel.java,
	java/nio/channels/spi/AbstractSelectionKey.java,
	java/nio/channels/spi/AbstractSelector.java,
	java/nio/channels/spi/SelectorProvider.java,
	java/nio/charset/spi/CharsetProvider.java:
	Fixed javadocs and jalopied all over java.nio.

From-SVN: r80909
parent 08c5d757
2004-04-20 Michael Koch <konqueror@gmx.de> 2004-04-20 Michael Koch <konqueror@gmx.de>
* java/nio/Buffer.java,
java/nio/channels/AlreadyConnectedException.java,
java/nio/channels/AsynchronousCloseException.java,
java/nio/channels/ByteChannel.java,
java/nio/channels/CancelledKeyException.java,
java/nio/channels/Channel.java,
java/nio/channels/Channels.java,
java/nio/channels/ClosedByInterruptException.java,
java/nio/channels/ClosedChannelException.java,
java/nio/channels/ClosedSelectorException.java,
java/nio/channels/ConnectionPendingException.java,
java/nio/channels/DatagramChannel.java,
java/nio/channels/FileChannel.java,
java/nio/channels/FileLock.java,
java/nio/channels/FileLockInterruptionException.java,
java/nio/channels/GatheringByteChannel.java,
java/nio/channels/IllegalBlockingModeException.java,
java/nio/channels/IllegalSelectorException.java,
java/nio/channels/InterruptibleChannel.java,
java/nio/channels/NoConnectionPendingException.java,
java/nio/channels/NonReadableChannelException.java,
java/nio/channels/NonWritableChannelException.java,
java/nio/channels/NotYetBoundException.java,
java/nio/channels/NotYetConnectedException.java,
java/nio/channels/OverlappingFileLockException.java,
java/nio/channels/Pipe.java,
java/nio/channels/ReadableByteChannel.java,
java/nio/channels/ScatteringByteChannel.java,
java/nio/channels/SelectableChannel.java,
java/nio/channels/SelectionKey.java,
java/nio/channels/Selector.java,
java/nio/channels/ServerSocketChannel.java,
java/nio/channels/SocketChannel.java,
java/nio/channels/UnresolvedAddressException.java,
java/nio/channels/UnsupportedAddressTypeException.java,
java/nio/channels/WritableByteChannel.java,
java/nio/channels/spi/AbstractInterruptibleChannel.java,
java/nio/channels/spi/AbstractSelectableChannel.java,
java/nio/channels/spi/AbstractSelectionKey.java,
java/nio/channels/spi/AbstractSelector.java,
java/nio/channels/spi/SelectorProvider.java,
java/nio/charset/spi/CharsetProvider.java:
Fixed javadocs and jalopied all over java.nio.
2004-04-20 Michael Koch <konqueror@gmx.de>
* java/nio/ByteBufferImpl.java, * java/nio/ByteBufferImpl.java,
java/nio/CharBufferImpl.java, java/nio/CharBufferImpl.java,
java/nio/DirectByteBufferImpl.java, java/nio/DirectByteBufferImpl.java,
......
...@@ -45,10 +45,11 @@ public abstract class Buffer ...@@ -45,10 +45,11 @@ public abstract class Buffer
int pos = 0; int pos = 0;
int mark = -1; int mark = -1;
// Creates a new Buffer. /**
// * Creates a new Buffer.
// Should be package private. *
// * Should be package private.
*/
Buffer (int capacity, int limit, int position, int mark) Buffer (int capacity, int limit, int position, int mark)
{ {
if (capacity < 0) if (capacity < 0)
...@@ -69,6 +70,8 @@ public abstract class Buffer ...@@ -69,6 +70,8 @@ public abstract class Buffer
/** /**
* Retrieves the capacity of the buffer. * Retrieves the capacity of the buffer.
*
* @return the capacity of the buffer
*/ */
public final int capacity () public final int capacity ()
{ {
...@@ -77,6 +80,8 @@ public abstract class Buffer ...@@ -77,6 +80,8 @@ public abstract class Buffer
/** /**
* Clears the buffer. * Clears the buffer.
*
* @return this buffer
*/ */
public final Buffer clear () public final Buffer clear ()
{ {
...@@ -88,6 +93,8 @@ public abstract class Buffer ...@@ -88,6 +93,8 @@ public abstract class Buffer
/** /**
* Flips the buffer. * Flips the buffer.
*
* @return this buffer
*/ */
public final Buffer flip () public final Buffer flip ()
{ {
...@@ -99,6 +106,9 @@ public abstract class Buffer ...@@ -99,6 +106,9 @@ public abstract class Buffer
/** /**
* Tells whether the buffer has remaining data to read or not. * Tells whether the buffer has remaining data to read or not.
*
* @return true if the buffer contains remaining data to read,
* false otherwise
*/ */
public final boolean hasRemaining () public final boolean hasRemaining ()
{ {
...@@ -107,11 +117,15 @@ public abstract class Buffer ...@@ -107,11 +117,15 @@ public abstract class Buffer
/** /**
* Tells whether this buffer is read only or not. * Tells whether this buffer is read only or not.
*
* @return true if the buffer is read only, false otherwise
*/ */
public abstract boolean isReadOnly (); public abstract boolean isReadOnly ();
/** /**
* Retrieves the current limit of the buffer. * Retrieves the current limit of the buffer.
*
* @return the limit of the buffer
*/ */
public final int limit () public final int limit ()
{ {
...@@ -124,6 +138,8 @@ public abstract class Buffer ...@@ -124,6 +138,8 @@ public abstract class Buffer
* @param newLimit The new limit value; must be non-negative and no larger * @param newLimit The new limit value; must be non-negative and no larger
* than this buffer's capacity. * than this buffer's capacity.
* *
* @return this buffer
*
* @exception IllegalArgumentException If the preconditions on newLimit * @exception IllegalArgumentException If the preconditions on newLimit
* do not hold. * do not hold.
*/ */
...@@ -144,6 +160,8 @@ public abstract class Buffer ...@@ -144,6 +160,8 @@ public abstract class Buffer
/** /**
* Sets this buffer's mark at its position. * Sets this buffer's mark at its position.
*
* @return this buffer
*/ */
public final Buffer mark () public final Buffer mark ()
{ {
...@@ -153,6 +171,8 @@ public abstract class Buffer ...@@ -153,6 +171,8 @@ public abstract class Buffer
/** /**
* Retrieves the current position of this buffer. * Retrieves the current position of this buffer.
*
* @return the current position of this buffer
*/ */
public final int position () public final int position ()
{ {
...@@ -166,6 +186,8 @@ public abstract class Buffer ...@@ -166,6 +186,8 @@ public abstract class Buffer
* @param newPosition The new position value; must be non-negative and no * @param newPosition The new position value; must be non-negative and no
* larger than the current limit. * larger than the current limit.
* *
* @return this buffer
*
* @exception IllegalArgumentException If the preconditions on newPosition * @exception IllegalArgumentException If the preconditions on newPosition
* do not hold * do not hold
*/ */
...@@ -183,6 +205,8 @@ public abstract class Buffer ...@@ -183,6 +205,8 @@ public abstract class Buffer
/** /**
* Returns the number of elements between the current position and the limit. * Returns the number of elements between the current position and the limit.
*
* @return the number of remaining elements
*/ */
public final int remaining() public final int remaining()
{ {
...@@ -192,6 +216,8 @@ public abstract class Buffer ...@@ -192,6 +216,8 @@ public abstract class Buffer
/** /**
* Resets this buffer's position to the previously-marked position. * Resets this buffer's position to the previously-marked position.
* *
* @return this buffer
*
* @exception InvalidMarkException If the mark has not been set. * @exception InvalidMarkException If the mark has not been set.
*/ */
public final Buffer reset() public final Buffer reset()
...@@ -206,6 +232,8 @@ public abstract class Buffer ...@@ -206,6 +232,8 @@ public abstract class Buffer
/** /**
* Rewinds this buffer. The position is set to zero and the mark * Rewinds this buffer. The position is set to zero and the mark
* is discarded. * is discarded.
*
* @this buffer
*/ */
public final Buffer rewind() public final Buffer rewind()
{ {
......
...@@ -37,6 +37,7 @@ exception statement from your version. */ ...@@ -37,6 +37,7 @@ exception statement from your version. */
package java.nio.channels; package java.nio.channels;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
......
...@@ -37,7 +37,7 @@ exception statement from your version. */ ...@@ -37,7 +37,7 @@ exception statement from your version. */
package java.nio.channels; package java.nio.channels;
public interface ByteChannel public interface ByteChannel extends ReadableByteChannel,
extends ReadableByteChannel, WritableByteChannel WritableByteChannel
{ {
} }
...@@ -37,6 +37,7 @@ exception statement from your version. */ ...@@ -37,6 +37,7 @@ exception statement from your version. */
package java.nio.channels; package java.nio.channels;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
......
...@@ -39,6 +39,7 @@ package java.nio.channels; ...@@ -39,6 +39,7 @@ package java.nio.channels;
import java.io.IOException; import java.io.IOException;
public interface Channel public interface Channel
{ {
/** /**
......
...@@ -42,16 +42,17 @@ import gnu.java.nio.ChannelOutputStream; ...@@ -42,16 +42,17 @@ import gnu.java.nio.ChannelOutputStream;
import gnu.java.nio.InputStreamChannel; import gnu.java.nio.InputStreamChannel;
import gnu.java.nio.OutputStreamChannel; import gnu.java.nio.OutputStreamChannel;
import gnu.java.nio.channels.FileChannelImpl; import gnu.java.nio.channels.FileChannelImpl;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader; import java.io.Reader;
import java.io.Writer; import java.io.Writer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder; import java.nio.charset.CharsetEncoder;
/** /**
* @since 1.4 * @since 1.4
*/ */
...@@ -78,6 +79,7 @@ public final class Channels ...@@ -78,6 +79,7 @@ public final class Channels
} }
static native FileInputStream newInputStream(FileChannelImpl ch); static native FileInputStream newInputStream(FileChannelImpl ch);
static native FileOutputStream newOutputStream(FileChannelImpl ch); static native FileOutputStream newOutputStream(FileChannelImpl ch);
/** /**
...@@ -93,14 +95,14 @@ public final class Channels ...@@ -93,14 +95,14 @@ public final class Channels
*/ */
public static WritableByteChannel newChannel(OutputStream out) public static WritableByteChannel newChannel(OutputStream out)
{ {
return new OutputStreamChannel (out); return new OutputStreamChannel(out);
} }
/** /**
* Constructs a reader that decodes bytes from the given channel using the * Constructs a reader that decodes bytes from the given channel using the
* given decoder. * given decoder.
*/ */
public static Reader newReader (ReadableByteChannel ch, CharsetDecoder dec, public static Reader newReader(ReadableByteChannel ch, CharsetDecoder dec,
int minBufferCap) int minBufferCap)
{ {
throw new Error ("not implemented"); throw new Error ("not implemented");
...@@ -113,16 +115,16 @@ public final class Channels ...@@ -113,16 +115,16 @@ public final class Channels
* @exception UnsupportedCharsetException If no support for the named charset * @exception UnsupportedCharsetException If no support for the named charset
* is available in this instance of the Java virtual machine. * is available in this instance of the Java virtual machine.
*/ */
public static Reader newReader (ReadableByteChannel ch, String csName) public static Reader newReader(ReadableByteChannel ch, String csName)
{ {
return newReader (ch, Charset.forName (csName).newDecoder (), -1); return newReader(ch, Charset.forName(csName).newDecoder(), -1);
} }
/** /**
* Constructs a writer that encodes characters using the given encoder and * Constructs a writer that encodes characters using the given encoder and
* writes the resulting bytes to the given channel. * writes the resulting bytes to the given channel.
*/ */
public static Writer newWriter (WritableByteChannel ch, CharsetEncoder enc, public static Writer newWriter(WritableByteChannel ch, CharsetEncoder enc,
int minBufferCap) int minBufferCap)
{ {
throw new Error ("not implemented"); throw new Error ("not implemented");
...@@ -135,9 +137,8 @@ public final class Channels ...@@ -135,9 +137,8 @@ public final class Channels
* @exception UnsupportedCharsetException If no support for the named charset * @exception UnsupportedCharsetException If no support for the named charset
* is available in this instance of the Java virtual machine. * is available in this instance of the Java virtual machine.
*/ */
public static Writer newWriter (WritableByteChannel ch, public static Writer newWriter(WritableByteChannel ch, String csName)
String csName)
{ {
return newWriter (ch, Charset.forName (csName).newEncoder (), -1); return newWriter(ch, Charset.forName(csName).newEncoder(), -1);
} }
} }
...@@ -37,6 +37,7 @@ exception statement from your version. */ ...@@ -37,6 +37,7 @@ exception statement from your version. */
package java.nio.channels; package java.nio.channels;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
......
...@@ -39,6 +39,7 @@ package java.nio.channels; ...@@ -39,6 +39,7 @@ package java.nio.channels;
import java.io.IOException; import java.io.IOException;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
......
...@@ -37,6 +37,7 @@ exception statement from your version. */ ...@@ -37,6 +37,7 @@ exception statement from your version. */
package java.nio.channels; package java.nio.channels;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
......
...@@ -37,6 +37,7 @@ exception statement from your version. */ ...@@ -37,6 +37,7 @@ exception statement from your version. */
package java.nio.channels; package java.nio.channels;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
......
...@@ -44,19 +44,19 @@ import java.nio.ByteBuffer; ...@@ -44,19 +44,19 @@ import java.nio.ByteBuffer;
import java.nio.channels.spi.AbstractSelectableChannel; import java.nio.channels.spi.AbstractSelectableChannel;
import java.nio.channels.spi.SelectorProvider; import java.nio.channels.spi.SelectorProvider;
/** /**
* @since 1.4 * @since 1.4
*/ */
public abstract class DatagramChannel public abstract class DatagramChannel extends AbstractSelectableChannel
extends AbstractSelectableChannel
implements ByteChannel, ScatteringByteChannel, GatheringByteChannel implements ByteChannel, ScatteringByteChannel, GatheringByteChannel
{ {
/** /**
* Initializes the channel. * Initializes the channel.
*/ */
protected DatagramChannel (SelectorProvider provider) protected DatagramChannel(SelectorProvider provider)
{ {
super (provider); super(provider);
} }
/** /**
...@@ -64,20 +64,20 @@ public abstract class DatagramChannel ...@@ -64,20 +64,20 @@ public abstract class DatagramChannel
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public static DatagramChannel open () throws IOException public static DatagramChannel open() throws IOException
{ {
return SelectorProvider.provider ().openDatagramChannel (); return SelectorProvider.provider().openDatagramChannel();
} }
/** /**
* Reads data from this channel. * Reads data from this channel.
*/ */
public final long read (ByteBuffer[] dsts) throws IOException public final long read(ByteBuffer[] dsts) throws IOException
{ {
long b = 0; long b = 0;
for (int i = 0; i < dsts.length; i++) for (int i = 0; i < dsts.length; i++)
b += read (dsts[i]); b += read(dsts[i]);
return b; return b;
} }
...@@ -88,12 +88,12 @@ public abstract class DatagramChannel ...@@ -88,12 +88,12 @@ public abstract class DatagramChannel
* @exception IOException If an error occurs * @exception IOException If an error occurs
* @exception NotYetConnectedException The channel's socket is not connected. * @exception NotYetConnectedException The channel's socket is not connected.
*/ */
public final long write (ByteBuffer[] srcs) throws IOException public final long write(ByteBuffer[] srcs) throws IOException
{ {
long b = 0; long b = 0;
for (int i = 0;i < srcs.length; i++) for (int i = 0; i < srcs.length; i++)
b += write (srcs[i]); b += write(srcs[i]);
return b; return b;
} }
...@@ -111,7 +111,7 @@ public abstract class DatagramChannel ...@@ -111,7 +111,7 @@ public abstract class DatagramChannel
* @exception SecurityException If a security manager has been installed and * @exception SecurityException If a security manager has been installed and
* it does not permit datagrams to be sent to the given address. * it does not permit datagrams to be sent to the given address.
*/ */
public abstract DatagramChannel connect (SocketAddress remote) public abstract DatagramChannel connect(SocketAddress remote)
throws IOException; throws IOException;
/** /**
...@@ -119,7 +119,7 @@ public abstract class DatagramChannel ...@@ -119,7 +119,7 @@ public abstract class DatagramChannel
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public abstract DatagramChannel disconnect () throws IOException; public abstract DatagramChannel disconnect() throws IOException;
/** /**
* Tells whether or not this channel's socket is connected. * Tells whether or not this channel's socket is connected.
...@@ -127,12 +127,12 @@ public abstract class DatagramChannel ...@@ -127,12 +127,12 @@ public abstract class DatagramChannel
* @exception IOException If an error occurs. * @exception IOException If an error occurs.
* @exception NotYetConnectedException The channel's socket is not connected. * @exception NotYetConnectedException The channel's socket is not connected.
*/ */
public abstract boolean isConnected (); public abstract boolean isConnected();
/** /**
* Reads data from this channel. * Reads data from this channel.
*/ */
public abstract int read (ByteBuffer dst) throws IOException; public abstract int read(ByteBuffer dst) throws IOException;
/** /**
* Reads data from this channel. * Reads data from this channel.
...@@ -140,7 +140,7 @@ public abstract class DatagramChannel ...@@ -140,7 +140,7 @@ public abstract class DatagramChannel
* @exception IOException If an error occurs. * @exception IOException If an error occurs.
* @exception NotYetConnectedException The channel's socket is not connected. * @exception NotYetConnectedException The channel's socket is not connected.
*/ */
public abstract long read (ByteBuffer[] dsts, int offset, int length) public abstract long read(ByteBuffer[] dsts, int offset, int length)
throws IOException; throws IOException;
/** /**
...@@ -156,7 +156,8 @@ public abstract class DatagramChannel ...@@ -156,7 +156,8 @@ public abstract class DatagramChannel
* @exception SecurityException If a security manager has been installed and * @exception SecurityException If a security manager has been installed and
* it does not permit datagrams to be sent to the given address. * it does not permit datagrams to be sent to the given address.
*/ */
public abstract SocketAddress receive (ByteBuffer dst) throws IOException; public abstract SocketAddress receive(ByteBuffer dst)
throws IOException;
/** /**
* Sends a datagram via this channel. * Sends a datagram via this channel.
...@@ -171,13 +172,13 @@ public abstract class DatagramChannel ...@@ -171,13 +172,13 @@ public abstract class DatagramChannel
* @exception SecurityException If a security manager has been installed and * @exception SecurityException If a security manager has been installed and
* it does not permit datagrams to be sent to the given address. * it does not permit datagrams to be sent to the given address.
*/ */
public abstract int send (ByteBuffer src, SocketAddress target) public abstract int send(ByteBuffer src, SocketAddress target)
throws IOException; throws IOException;
/** /**
* Retrieves the channel's socket. * Retrieves the channel's socket.
*/ */
public abstract DatagramSocket socket (); public abstract DatagramSocket socket();
/** /**
* Writes data to this channel. * Writes data to this channel.
...@@ -185,7 +186,7 @@ public abstract class DatagramChannel ...@@ -185,7 +186,7 @@ public abstract class DatagramChannel
* @exception IOException If an error occurs. * @exception IOException If an error occurs.
* @exception NotYetConnectedException The channel's socket is not connected. * @exception NotYetConnectedException The channel's socket is not connected.
*/ */
public abstract int write (ByteBuffer src) throws IOException; public abstract int write(ByteBuffer src) throws IOException;
/** /**
* Writes data to this channel. * Writes data to this channel.
...@@ -193,7 +194,7 @@ public abstract class DatagramChannel ...@@ -193,7 +194,7 @@ public abstract class DatagramChannel
* @exception IOException If an error occurs. * @exception IOException If an error occurs.
* @exception NotYetConnectedException The channel's socket is not connected. * @exception NotYetConnectedException The channel's socket is not connected.
*/ */
public abstract long write (ByteBuffer[] srcs, int offset, int length) public abstract long write(ByteBuffer[] srcs, int offset, int length)
throws IOException; throws IOException;
/** /**
...@@ -202,7 +203,7 @@ public abstract class DatagramChannel ...@@ -202,7 +203,7 @@ public abstract class DatagramChannel
* @exception IOException If an error occurs. * @exception IOException If an error occurs.
* @exception NotYetConnectedException The channel's socket is not connected. * @exception NotYetConnectedException The channel's socket is not connected.
*/ */
public final int validOps () public final int validOps()
{ {
return SelectionKey.OP_READ | SelectionKey.OP_WRITE; return SelectionKey.OP_READ | SelectionKey.OP_WRITE;
} }
......
...@@ -42,6 +42,7 @@ import java.nio.ByteBuffer; ...@@ -42,6 +42,7 @@ import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer; import java.nio.MappedByteBuffer;
import java.nio.channels.spi.AbstractInterruptibleChannel; import java.nio.channels.spi.AbstractInterruptibleChannel;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
...@@ -52,7 +53,6 @@ public abstract class FileChannel extends AbstractInterruptibleChannel ...@@ -52,7 +53,6 @@ public abstract class FileChannel extends AbstractInterruptibleChannel
public static class MapMode public static class MapMode
{ {
int m; int m;
public static final MapMode READ_ONLY = new MapMode(0); public static final MapMode READ_ONLY = new MapMode(0);
public static final MapMode READ_WRITE = new MapMode(1); public static final MapMode READ_WRITE = new MapMode(1);
public static final MapMode PRIVATE = new MapMode(2); public static final MapMode PRIVATE = new MapMode(2);
...@@ -82,7 +82,7 @@ public abstract class FileChannel extends AbstractInterruptibleChannel ...@@ -82,7 +82,7 @@ public abstract class FileChannel extends AbstractInterruptibleChannel
/** /**
* Initializes the channel. * Initializes the channel.
*/ */
protected FileChannel () protected FileChannel()
{ {
} }
...@@ -112,14 +112,12 @@ public abstract class FileChannel extends AbstractInterruptibleChannel ...@@ -112,14 +112,12 @@ public abstract class FileChannel extends AbstractInterruptibleChannel
* *
* @exception IOException If an I/O error occurs. * @exception IOException If an I/O error occurs.
*/ */
public final long write (ByteBuffer[] srcs) throws IOException public final long write(ByteBuffer[] srcs) throws IOException
{ {
long result = 0; long result = 0;
for (int i = 0; i < srcs.length; i++) for (int i = 0; i < srcs.length; i++)
{ result += write(srcs[i]);
result += write (srcs[i]);
}
return result; return result;
} }
...@@ -129,7 +127,7 @@ public abstract class FileChannel extends AbstractInterruptibleChannel ...@@ -129,7 +127,7 @@ public abstract class FileChannel extends AbstractInterruptibleChannel
* *
* @exception IOException If an I/O error occurs. * @exception IOException If an I/O error occurs.
*/ */
public abstract int write (ByteBuffer src) throws IOException; public abstract int write(ByteBuffer src) throws IOException;
/** /**
* Writes data to the channel. * Writes data to the channel.
...@@ -145,7 +143,8 @@ public abstract class FileChannel extends AbstractInterruptibleChannel ...@@ -145,7 +143,8 @@ public abstract class FileChannel extends AbstractInterruptibleChannel
* @exception NonWritableChannelException If this channel was not opened for * @exception NonWritableChannelException If this channel was not opened for
* writing. * writing.
*/ */
public abstract int write (ByteBuffer srcs, long position) throws IOException; public abstract int write(ByteBuffer srcs, long position)
throws IOException;
/** /**
* Writes data to the channel. * Writes data to the channel.
...@@ -160,7 +159,7 @@ public abstract class FileChannel extends AbstractInterruptibleChannel ...@@ -160,7 +159,7 @@ public abstract class FileChannel extends AbstractInterruptibleChannel
* *
* @exception IOException If an I/O error occurs. * @exception IOException If an I/O error occurs.
*/ */
public abstract long read (ByteBuffer[] dsts, int offset, int length) public abstract long read(ByteBuffer[] dsts, int offset, int length)
throws IOException; throws IOException;
/** /**
...@@ -168,14 +167,12 @@ public abstract class FileChannel extends AbstractInterruptibleChannel ...@@ -168,14 +167,12 @@ public abstract class FileChannel extends AbstractInterruptibleChannel
* *
* @exception IOException If an I/O error occurs. * @exception IOException If an I/O error occurs.
*/ */
public final long read (ByteBuffer[] dsts) throws IOException public final long read(ByteBuffer[] dsts) throws IOException
{ {
long result = 0; long result = 0;
for (int i = 0; i < dsts.length; i++) for (int i = 0; i < dsts.length; i++)
{ read(dsts[i]);
read (dsts [i]);
}
return result; return result;
} }
...@@ -201,7 +198,8 @@ public abstract class FileChannel extends AbstractInterruptibleChannel ...@@ -201,7 +198,8 @@ public abstract class FileChannel extends AbstractInterruptibleChannel
* @exception NonReadableChannelException If this channel was not opened for * @exception NonReadableChannelException If this channel was not opened for
* reading. * reading.
*/ */
public abstract int read(ByteBuffer dst, long position) throws IOException; public abstract int read(ByteBuffer dst, long position)
throws IOException;
/** /**
* Closes the channel. * Closes the channel.
...@@ -238,9 +236,9 @@ public abstract class FileChannel extends AbstractInterruptibleChannel ...@@ -238,9 +236,9 @@ public abstract class FileChannel extends AbstractInterruptibleChannel
* another thread is already blocked in this method and is attempting to lock * another thread is already blocked in this method and is attempting to lock
* an overlapping region. * an overlapping region.
*/ */
public final FileLock lock () throws IOException public final FileLock lock() throws IOException
{ {
return lock (0, Long.MAX_VALUE, false); return lock(0, Long.MAX_VALUE, false);
} }
/** /**
...@@ -263,7 +261,7 @@ public abstract class FileChannel extends AbstractInterruptibleChannel ...@@ -263,7 +261,7 @@ public abstract class FileChannel extends AbstractInterruptibleChannel
* @exception NonWritableChannelException If shared is false and this channel * @exception NonWritableChannelException If shared is false and this channel
* was not opened for writing. * was not opened for writing.
*/ */
public abstract FileLock lock (long position, long size, boolean shared) public abstract FileLock lock(long position, long size, boolean shared)
throws IOException; throws IOException;
/** /**
...@@ -276,9 +274,9 @@ public abstract class FileChannel extends AbstractInterruptibleChannel ...@@ -276,9 +274,9 @@ public abstract class FileChannel extends AbstractInterruptibleChannel
* another thread is already blocked in this method and is attempting to lock * another thread is already blocked in this method and is attempting to lock
* an overlapping region. * an overlapping region.
*/ */
public final FileLock tryLock () throws IOException public final FileLock tryLock() throws IOException
{ {
return tryLock (0, Long.MAX_VALUE, false); return tryLock(0, Long.MAX_VALUE, false);
} }
/** /**
...@@ -293,7 +291,7 @@ public abstract class FileChannel extends AbstractInterruptibleChannel ...@@ -293,7 +291,7 @@ public abstract class FileChannel extends AbstractInterruptibleChannel
* another thread is already blocked in this method and is attempting to lock * another thread is already blocked in this method and is attempting to lock
* an overlapping region. * an overlapping region.
*/ */
public abstract FileLock tryLock (long position, long size, boolean shared) public abstract FileLock tryLock(long position, long size, boolean shared)
throws IOException; throws IOException;
/** /**
...@@ -302,7 +300,7 @@ public abstract class FileChannel extends AbstractInterruptibleChannel ...@@ -302,7 +300,7 @@ public abstract class FileChannel extends AbstractInterruptibleChannel
* @exception ClosedChannelException If this channel is closed. * @exception ClosedChannelException If this channel is closed.
* @exception IOException If an I/O error occurs. * @exception IOException If an I/O error occurs.
*/ */
public abstract long position () throws IOException; public abstract long position() throws IOException;
/** /**
* Sets the position of the channel on the assoziated file. * Sets the position of the channel on the assoziated file.
...@@ -311,7 +309,8 @@ public abstract class FileChannel extends AbstractInterruptibleChannel ...@@ -311,7 +309,8 @@ public abstract class FileChannel extends AbstractInterruptibleChannel
* @exception IllegalArgumentException If newPosition is negative. * @exception IllegalArgumentException If newPosition is negative.
* @exception IOException If an I/O error occurs. * @exception IOException If an I/O error occurs.
*/ */
public abstract FileChannel position (long newPosition) throws IOException; public abstract FileChannel position(long newPosition)
throws IOException;
/** /**
* Transfers bytes from this channel's file to the given writable byte * Transfers bytes from this channel's file to the given writable byte
...@@ -331,7 +330,7 @@ public abstract class FileChannel extends AbstractInterruptibleChannel ...@@ -331,7 +330,7 @@ public abstract class FileChannel extends AbstractInterruptibleChannel
* @exception NonWritableChannelException If the target channel was not * @exception NonWritableChannelException If the target channel was not
* opened for writing. * opened for writing.
*/ */
public abstract long transferTo (long position, long count, public abstract long transferTo(long position, long count,
WritableByteChannel target) WritableByteChannel target)
throws IOException; throws IOException;
...@@ -352,7 +351,7 @@ public abstract class FileChannel extends AbstractInterruptibleChannel ...@@ -352,7 +351,7 @@ public abstract class FileChannel extends AbstractInterruptibleChannel
* @exception NonWritableChannelException If this channel was not opened for * @exception NonWritableChannelException If this channel was not opened for
* writing. * writing.
*/ */
public abstract long transferFrom (ReadableByteChannel src, long position, public abstract long transferFrom(ReadableByteChannel src, long position,
long count) throws IOException; long count) throws IOException;
/** /**
...@@ -364,5 +363,5 @@ public abstract class FileChannel extends AbstractInterruptibleChannel ...@@ -364,5 +363,5 @@ public abstract class FileChannel extends AbstractInterruptibleChannel
* @exception NonWritableChannelException If this channel was not opened for * @exception NonWritableChannelException If this channel was not opened for
* writing. * writing.
*/ */
public abstract FileChannel truncate (long size) throws IOException; public abstract FileChannel truncate(long size) throws IOException;
} }
...@@ -39,6 +39,7 @@ package java.nio.channels; ...@@ -39,6 +39,7 @@ package java.nio.channels;
import java.io.IOException; import java.io.IOException;
/** /**
* @since 1.4 * @since 1.4
*/ */
...@@ -54,12 +55,11 @@ public abstract class FileLock ...@@ -54,12 +55,11 @@ public abstract class FileLock
* *
* @exception IllegalArgumentException If the preconditions on the parameters do not hold * @exception IllegalArgumentException If the preconditions on the parameters do not hold
*/ */
protected FileLock (FileChannel channel, long position, long size, protected FileLock(FileChannel channel, long position, long size,
boolean shared) boolean shared)
{ {
if (position < 0 || if (position < 0 || size < 0)
size < 0) throw new IllegalArgumentException();
throw new IllegalArgumentException ();
this.channel = channel; this.channel = channel;
this.position = position; this.position = position;
...@@ -78,12 +78,12 @@ public abstract class FileLock ...@@ -78,12 +78,12 @@ public abstract class FileLock
* @exception IOException If an error occurs * @exception IOException If an error occurs
* @exception ClosedChannelException If the locked channel is no longer open. * @exception ClosedChannelException If the locked channel is no longer open.
*/ */
public abstract void release () throws IOException; public abstract void release() throws IOException;
/** /**
* Returns the file channel upon whose file this lock is held. * Returns the file channel upon whose file this lock is held.
*/ */
public final FileChannel channel () public final FileChannel channel()
{ {
return channel; return channel;
} }
...@@ -91,7 +91,7 @@ public abstract class FileLock ...@@ -91,7 +91,7 @@ public abstract class FileLock
/** /**
* Tells whether this lock is shared. * Tells whether this lock is shared.
*/ */
public final boolean isShared () public final boolean isShared()
{ {
return shared; return shared;
} }
...@@ -99,7 +99,7 @@ public abstract class FileLock ...@@ -99,7 +99,7 @@ public abstract class FileLock
/** /**
* Tells whether or not this lock overlaps the given lock range. * Tells whether or not this lock overlaps the given lock range.
*/ */
public final boolean overlaps (long position, long size) public final boolean overlaps(long position, long size)
{ {
if (position > this.position + this.size) if (position > this.position + this.size)
return false; return false;
...@@ -114,7 +114,7 @@ public abstract class FileLock ...@@ -114,7 +114,7 @@ public abstract class FileLock
* Returns the position within the file of the first byte of the * Returns the position within the file of the first byte of the
* locked region. * locked region.
*/ */
public final long position () public final long position()
{ {
return position; return position;
} }
...@@ -122,7 +122,7 @@ public abstract class FileLock ...@@ -122,7 +122,7 @@ public abstract class FileLock
/** /**
* Returns the size of the locked region in bytes. * Returns the size of the locked region in bytes.
*/ */
public final long size () public final long size()
{ {
return size; return size;
} }
...@@ -130,7 +130,7 @@ public abstract class FileLock ...@@ -130,7 +130,7 @@ public abstract class FileLock
/** /**
* Returns a string describing the range, type, and validity of this lock. * Returns a string describing the range, type, and validity of this lock.
*/ */
public final String toString () public final String toString()
{ {
return "file-lock:pos=" + position + "size=" + size; return "file-lock:pos=" + position + "size=" + size;
} }
......
...@@ -39,6 +39,7 @@ package java.nio.channels; ...@@ -39,6 +39,7 @@ package java.nio.channels;
import java.io.IOException; import java.io.IOException;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
......
...@@ -37,11 +37,11 @@ exception statement from your version. */ ...@@ -37,11 +37,11 @@ exception statement from your version. */
package java.nio.channels; package java.nio.channels;
import java.nio.ByteBuffer;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer;
public interface GatheringByteChannel public interface GatheringByteChannel extends WritableByteChannel
extends WritableByteChannel
{ {
/** /**
* Writes a sequence of bytes to this channel from a subsequence of * Writes a sequence of bytes to this channel from a subsequence of
...@@ -59,7 +59,7 @@ public interface GatheringByteChannel ...@@ -59,7 +59,7 @@ public interface GatheringByteChannel
* @exception NonWritableChannelException If this channel was not opened for * @exception NonWritableChannelException If this channel was not opened for
* writing * writing
*/ */
long write (ByteBuffer[] srcs, int offset, int length) long write(ByteBuffer[] srcs, int offset, int length)
throws IOException; throws IOException;
/** /**
...@@ -75,5 +75,5 @@ public interface GatheringByteChannel ...@@ -75,5 +75,5 @@ public interface GatheringByteChannel
* @exception NonWritableChannelException If this channel was not opened for * @exception NonWritableChannelException If this channel was not opened for
* writing * writing
*/ */
long write (ByteBuffer[] srcs) throws IOException; long write(ByteBuffer[] srcs) throws IOException;
} }
...@@ -37,6 +37,7 @@ exception statement from your version. */ ...@@ -37,6 +37,7 @@ exception statement from your version. */
package java.nio.channels; package java.nio.channels;
/** /**
* @author Michael Koch <konqueror@gmx.de> * @author Michael Koch <konqueror@gmx.de>
* @since 1.4 * @since 1.4
......
...@@ -37,6 +37,7 @@ exception statement from your version. */ ...@@ -37,6 +37,7 @@ exception statement from your version. */
package java.nio.channels; package java.nio.channels;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
......
...@@ -39,6 +39,7 @@ package java.nio.channels; ...@@ -39,6 +39,7 @@ package java.nio.channels;
import java.io.IOException; import java.io.IOException;
public interface InterruptibleChannel extends Channel public interface InterruptibleChannel extends Channel
{ {
/** /**
......
...@@ -37,6 +37,7 @@ exception statement from your version. */ ...@@ -37,6 +37,7 @@ exception statement from your version. */
package java.nio.channels; package java.nio.channels;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
......
...@@ -37,6 +37,7 @@ exception statement from your version. */ ...@@ -37,6 +37,7 @@ exception statement from your version. */
package java.nio.channels; package java.nio.channels;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
......
...@@ -37,6 +37,7 @@ exception statement from your version. */ ...@@ -37,6 +37,7 @@ exception statement from your version. */
package java.nio.channels; package java.nio.channels;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
......
...@@ -37,6 +37,7 @@ exception statement from your version. */ ...@@ -37,6 +37,7 @@ exception statement from your version. */
package java.nio.channels; package java.nio.channels;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
......
...@@ -37,6 +37,7 @@ exception statement from your version. */ ...@@ -37,6 +37,7 @@ exception statement from your version. */
package java.nio.channels; package java.nio.channels;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
......
...@@ -37,6 +37,7 @@ exception statement from your version. */ ...@@ -37,6 +37,7 @@ exception statement from your version. */
package java.nio.channels; package java.nio.channels;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
......
...@@ -41,22 +41,22 @@ import java.io.IOException; ...@@ -41,22 +41,22 @@ import java.io.IOException;
import java.nio.channels.spi.AbstractSelectableChannel; import java.nio.channels.spi.AbstractSelectableChannel;
import java.nio.channels.spi.SelectorProvider; import java.nio.channels.spi.SelectorProvider;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
*/ */
public abstract class Pipe public abstract class Pipe
{ {
public abstract static class SinkChannel public abstract static class SinkChannel extends AbstractSelectableChannel
extends AbstractSelectableChannel
implements WritableByteChannel, GatheringByteChannel implements WritableByteChannel, GatheringByteChannel
{ {
/** /**
* Initializes the channel. * Initializes the channel.
*/ */
protected SinkChannel (SelectorProvider provider) protected SinkChannel(SelectorProvider provider)
{ {
super (provider); super(provider);
} }
/** /**
...@@ -64,22 +64,21 @@ public abstract class Pipe ...@@ -64,22 +64,21 @@ public abstract class Pipe
* *
* The only valid operation on this channel is @see SelectionKey.OP_WRITE. * The only valid operation on this channel is @see SelectionKey.OP_WRITE.
*/ */
public final int validOps () public final int validOps()
{ {
return SelectionKey.OP_WRITE; return SelectionKey.OP_WRITE;
} }
} }
public abstract static class SourceChannel public abstract static class SourceChannel extends AbstractSelectableChannel
extends AbstractSelectableChannel
implements ReadableByteChannel, ScatteringByteChannel implements ReadableByteChannel, ScatteringByteChannel
{ {
/** /**
* Initializes the channel. * Initializes the channel.
*/ */
protected SourceChannel (SelectorProvider provider) protected SourceChannel(SelectorProvider provider)
{ {
super (provider); super(provider);
} }
/** /**
...@@ -87,7 +86,7 @@ public abstract class Pipe ...@@ -87,7 +86,7 @@ public abstract class Pipe
* *
* The only valid operation on this channel is @see SelectionKey.OP_READ. * The only valid operation on this channel is @see SelectionKey.OP_READ.
*/ */
public final int validOps () public final int validOps()
{ {
return SelectionKey.OP_READ; return SelectionKey.OP_READ;
} }
...@@ -107,7 +106,7 @@ public abstract class Pipe ...@@ -107,7 +106,7 @@ public abstract class Pipe
*/ */
public static Pipe open() throws IOException public static Pipe open() throws IOException
{ {
return SelectorProvider.provider ().openPipe(); return SelectorProvider.provider().openPipe();
} }
/** /**
......
/* ReadableByteChannel.java -- /* ReadableByteChannel.java --
Copyright (C) 2002 Free Software Foundation, Inc. Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -40,11 +40,16 @@ package java.nio.channels; ...@@ -40,11 +40,16 @@ package java.nio.channels;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
public interface ReadableByteChannel extends Channel public interface ReadableByteChannel extends Channel
{ {
/** /**
* Reads a sequence of bytes from this channel into the given buffer * 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 * @exception AsynchronousCloseException If another thread closes this
* channel while the read operation is in progress * channel while the read operation is in progress
* @exception ClosedByInterruptException If another thread interrupts the * @exception ClosedByInterruptException If another thread interrupts the
...@@ -55,5 +60,5 @@ public interface ReadableByteChannel extends Channel ...@@ -55,5 +60,5 @@ public interface ReadableByteChannel extends Channel
* @exception NonReadableChannelException If this channel was not opened for * @exception NonReadableChannelException If this channel was not opened for
* reading * reading
*/ */
int read (ByteBuffer dst) throws IOException; int read(ByteBuffer dst) throws IOException;
} }
...@@ -37,11 +37,11 @@ exception statement from your version. */ ...@@ -37,11 +37,11 @@ exception statement from your version. */
package java.nio.channels; package java.nio.channels;
import java.nio.ByteBuffer;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer;
public interface ScatteringByteChannel public interface ScatteringByteChannel extends ReadableByteChannel
extends ReadableByteChannel
{ {
/** /**
* Reads a sequence of bytes from this channel into a subsequence of the * Reads a sequence of bytes from this channel into a subsequence of the
...@@ -59,7 +59,7 @@ public interface ScatteringByteChannel ...@@ -59,7 +59,7 @@ public interface ScatteringByteChannel
* @exception NonReadableChannelException If this channel was not opened for * @exception NonReadableChannelException If this channel was not opened for
* reading * reading
*/ */
long read (ByteBuffer[] srcs, int offset, int length) long read(ByteBuffer[] srcs, int offset, int length)
throws IOException; throws IOException;
/** /**
...@@ -75,5 +75,5 @@ public interface ScatteringByteChannel ...@@ -75,5 +75,5 @@ public interface ScatteringByteChannel
* @exception NonReadableChannelException If this channel was not opened for * @exception NonReadableChannelException If this channel was not opened for
* reading * reading
*/ */
long read (ByteBuffer[] srcs) throws IOException; long read(ByteBuffer[] srcs) throws IOException;
} }
...@@ -41,24 +41,24 @@ import java.io.IOException; ...@@ -41,24 +41,24 @@ import java.io.IOException;
import java.nio.channels.spi.AbstractInterruptibleChannel; import java.nio.channels.spi.AbstractInterruptibleChannel;
import java.nio.channels.spi.SelectorProvider; import java.nio.channels.spi.SelectorProvider;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
*/ */
public abstract class SelectableChannel public abstract class SelectableChannel extends AbstractInterruptibleChannel
extends AbstractInterruptibleChannel
{ {
/** /**
* Initializes the channel. * Initializes the channel.
*/ */
protected SelectableChannel () protected SelectableChannel()
{ {
} }
/** /**
* Returns the lock of this channel. * Returns the lock of this channel.
*/ */
public abstract Object blockingLock (); public abstract Object blockingLock();
/** /**
* Adjusts this channel's blocking mode. * Adjusts this channel's blocking mode.
...@@ -68,30 +68,30 @@ public abstract class SelectableChannel ...@@ -68,30 +68,30 @@ public abstract class SelectableChannel
* is registered with one or more selectors. * is registered with one or more selectors.
* @exception IOException If an error occurs. * @exception IOException If an error occurs.
*/ */
public abstract SelectableChannel configureBlocking (boolean block) public abstract SelectableChannel configureBlocking(boolean block)
throws IOException; throws IOException;
/** /**
* Tells whether this channel is blocking or not. * Tells whether this channel is blocking or not.
*/ */
public abstract boolean isBlocking (); public abstract boolean isBlocking();
/** /**
* Tells whether or not this channel is currently registered with * Tells whether or not this channel is currently registered with
* any selectors. * any selectors.
*/ */
public abstract boolean isRegistered (); public abstract boolean isRegistered();
/** /**
* Retrieves the key representing the channel's registration with * Retrieves the key representing the channel's registration with
* the given selector. * the given selector.
*/ */
public abstract SelectionKey keyFor (Selector sel); public abstract SelectionKey keyFor(Selector sel);
/** /**
* Returns the provider that created this channel. * Returns the provider that created this channel.
*/ */
public abstract SelectorProvider provider (); public abstract SelectorProvider provider();
/** /**
* Registers this channel with the given selector, * Registers this channel with the given selector,
...@@ -108,10 +108,10 @@ public abstract class SelectableChannel ...@@ -108,10 +108,10 @@ public abstract class SelectableChannel
* @exception IllegalSelectorException If this channel was not created by * @exception IllegalSelectorException If this channel was not created by
* the same provider as the given selector. * the same provider as the given selector.
*/ */
public final SelectionKey register (Selector sel, int ops) public final SelectionKey register(Selector sel, int ops)
throws ClosedChannelException throws ClosedChannelException
{ {
return register (sel, ops, null); return register(sel, ops, null);
} }
/** /**
...@@ -130,7 +130,7 @@ public abstract class SelectableChannel ...@@ -130,7 +130,7 @@ public abstract class SelectableChannel
* @exception IllegalSelectorException If this channel was not created by * @exception IllegalSelectorException If this channel was not created by
* the same provider as the given selector. * the same provider as the given selector.
*/ */
public abstract SelectionKey register (Selector sel, int ops, Object att) public abstract SelectionKey register(Selector sel, int ops, Object att)
throws ClosedChannelException; throws ClosedChannelException;
/** /**
......
...@@ -37,6 +37,7 @@ exception statement from your version. */ ...@@ -37,6 +37,7 @@ exception statement from your version. */
package java.nio.channels; package java.nio.channels;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
...@@ -47,20 +48,19 @@ public abstract class SelectionKey ...@@ -47,20 +48,19 @@ public abstract class SelectionKey
public static final int OP_CONNECT = 8; public static final int OP_CONNECT = 8;
public static final int OP_READ = 1; public static final int OP_READ = 1;
public static final int OP_WRITE = 4; public static final int OP_WRITE = 4;
Object attached; Object attached;
/** /**
* Initializes the selection key. * Initializes the selection key.
*/ */
protected SelectionKey () protected SelectionKey()
{ {
} }
/** /**
* Attaches obj to the key and returns the old attached object. * Attaches obj to the key and returns the old attached object.
*/ */
public final Object attach (Object obj) public final Object attach(Object obj)
{ {
Object old = attached; Object old = attached;
attached = obj; attached = obj;
...@@ -70,7 +70,7 @@ public abstract class SelectionKey ...@@ -70,7 +70,7 @@ public abstract class SelectionKey
/** /**
* Returns the object attached to the key. * Returns the object attached to the key.
*/ */
public final Object attachment () public final Object attachment()
{ {
return attached; return attached;
} }
...@@ -81,9 +81,9 @@ public abstract class SelectionKey ...@@ -81,9 +81,9 @@ public abstract class SelectionKey
* *
* @exception CancelledKeyException If this key has been cancelled * @exception CancelledKeyException If this key has been cancelled
*/ */
public final boolean isAcceptable () public final boolean isAcceptable()
{ {
return (readyOps () & OP_ACCEPT) != 0; return (readyOps() & OP_ACCEPT) != 0;
} }
/** /**
...@@ -92,9 +92,9 @@ public abstract class SelectionKey ...@@ -92,9 +92,9 @@ public abstract class SelectionKey
* *
* @exception CancelledKeyException If this key has been cancelled * @exception CancelledKeyException If this key has been cancelled
*/ */
public final boolean isConnectable () public final boolean isConnectable()
{ {
return (readyOps () & OP_CONNECT) != 0; return (readyOps() & OP_CONNECT) != 0;
} }
/** /**
...@@ -102,9 +102,9 @@ public abstract class SelectionKey ...@@ -102,9 +102,9 @@ public abstract class SelectionKey
* *
* @exception CancelledKeyException If this key has been cancelled * @exception CancelledKeyException If this key has been cancelled
*/ */
public final boolean isReadable () public final boolean isReadable()
{ {
return (readyOps () & OP_READ) != 0; return (readyOps() & OP_READ) != 0;
} }
/** /**
...@@ -112,28 +112,28 @@ public abstract class SelectionKey ...@@ -112,28 +112,28 @@ public abstract class SelectionKey
* *
* @exception CancelledKeyException If this key has been cancelled * @exception CancelledKeyException If this key has been cancelled
*/ */
public final boolean isWritable () public final boolean isWritable()
{ {
return (readyOps () & OP_WRITE) != 0; return (readyOps() & OP_WRITE) != 0;
} }
/** /**
* Requests that the registration of this key's channel with * Requests that the registration of this key's channel with
* its selector be cancelled. * its selector be cancelled.
*/ */
public abstract void cancel (); public abstract void cancel();
/** /**
* return the channel attached to the key. * return the channel attached to the key.
*/ */
public abstract SelectableChannel channel (); public abstract SelectableChannel channel();
/** /**
* Returns the key's interest set. * Returns the key's interest set.
* *
* @exception CancelledKeyException If this key has been cancelled * @exception CancelledKeyException If this key has been cancelled
*/ */
public abstract int interestOps (); public abstract int interestOps();
/** /**
* Sets this key's interest set to the given value. * Sets this key's interest set to the given value.
...@@ -143,22 +143,22 @@ public abstract class SelectionKey ...@@ -143,22 +143,22 @@ public abstract class SelectionKey
* correspond to an operation that is supported by this key's channel, * correspond to an operation that is supported by this key's channel,
* that is, if set &amp; ~(channel().validOps()) != 0 * that is, if set &amp; ~(channel().validOps()) != 0
*/ */
public abstract SelectionKey interestOps (int ops); public abstract SelectionKey interestOps(int ops);
/** /**
* Tells whether or not this key is valid. * Tells whether or not this key is valid.
*/ */
public abstract boolean isValid (); public abstract boolean isValid();
/** /**
* Retrieves this key's ready-operation set. * Retrieves this key's ready-operation set.
* *
* @exception CancelledKeyException If this key has been cancelled * @exception CancelledKeyException If this key has been cancelled
*/ */
public abstract int readyOps (); public abstract int readyOps();
/** /**
* Returns the selector for which this key was created. * Returns the selector for which this key was created.
*/ */
public abstract Selector selector (); public abstract Selector selector();
} }
...@@ -41,6 +41,7 @@ import java.io.IOException; ...@@ -41,6 +41,7 @@ import java.io.IOException;
import java.nio.channels.spi.SelectorProvider; import java.nio.channels.spi.SelectorProvider;
import java.util.Set; import java.util.Set;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
...@@ -59,9 +60,9 @@ public abstract class Selector ...@@ -59,9 +60,9 @@ public abstract class Selector
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public static Selector open () throws IOException public static Selector open() throws IOException
{ {
return SelectorProvider.provider ().openSelector (); return SelectorProvider.provider().openSelector();
} }
/** /**
...@@ -69,24 +70,24 @@ public abstract class Selector ...@@ -69,24 +70,24 @@ public abstract class Selector
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public abstract void close () throws IOException; public abstract void close() throws IOException;
/** /**
* Tells whether the selector is open or not. * Tells whether the selector is open or not.
*/ */
public abstract boolean isOpen (); public abstract boolean isOpen();
/** /**
* Returns this selector's key set. * Returns this selector's key set.
* *
* @exception ClosedSelectorException If this selector is closed. * @exception ClosedSelectorException If this selector is closed.
*/ */
public abstract Set keys (); public abstract Set keys();
/** /**
* Returns the SelectorProvider that created the selector. * Returns the SelectorProvider that created the selector.
*/ */
public abstract SelectorProvider provider (); public abstract SelectorProvider provider();
/** /**
* Selects a set of keys whose corresponding channels are ready * Selects a set of keys whose corresponding channels are ready
...@@ -95,7 +96,7 @@ public abstract class Selector ...@@ -95,7 +96,7 @@ public abstract class Selector
* @exception ClosedSelectorException If this selector is closed. * @exception ClosedSelectorException If this selector is closed.
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public abstract int select () throws IOException; public abstract int select() throws IOException;
/** /**
* Selects a set of keys whose corresponding channels are ready * Selects a set of keys whose corresponding channels are ready
...@@ -107,14 +108,14 @@ public abstract class Selector ...@@ -107,14 +108,14 @@ public abstract class Selector
* @exception IllegalArgumentException If the timeout value is negative. * @exception IllegalArgumentException If the timeout value is negative.
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public abstract int select (long timeout) throws IOException; public abstract int select(long timeout) throws IOException;
/** /**
* Returns this selector's selected-key set. * Returns this selector's selected-key set.
* *
* @exception ClosedSelectorException If this selector is closed. * @exception ClosedSelectorException If this selector is closed.
*/ */
public abstract Set selectedKeys (); public abstract Set selectedKeys();
/** /**
* Selects a set of keys whose corresponding channels are ready * Selects a set of keys whose corresponding channels are ready
...@@ -123,11 +124,11 @@ public abstract class Selector ...@@ -123,11 +124,11 @@ public abstract class Selector
* @exception ClosedSelectorException If this selector is closed. * @exception ClosedSelectorException If this selector is closed.
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public abstract int selectNow () throws IOException; public abstract int selectNow() throws IOException;
/** /**
* Causes the first selection operation that has not yet returned to * Causes the first selection operation that has not yet returned to
* return immediately. * return immediately.
*/ */
public abstract Selector wakeup (); public abstract Selector wakeup();
} }
...@@ -35,27 +35,26 @@ this exception to your version of the library, but you are not ...@@ -35,27 +35,26 @@ 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 obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package java.nio.channels; package java.nio.channels;
import java.nio.channels.spi.AbstractSelectableChannel;
import java.nio.channels.spi.SelectorProvider;
import java.io.IOException; import java.io.IOException;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.nio.channels.spi.AbstractSelectableChannel;
import java.nio.channels.spi.SelectorProvider;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
*/ */
public abstract class ServerSocketChannel public abstract class ServerSocketChannel extends AbstractSelectableChannel
extends AbstractSelectableChannel
{ {
/** /**
* Initializes this channel. * Initializes this channel.
*/ */
protected ServerSocketChannel (SelectorProvider provider) protected ServerSocketChannel(SelectorProvider provider)
{ {
super (provider); super(provider);
} }
/** /**
...@@ -72,27 +71,27 @@ public abstract class ServerSocketChannel ...@@ -72,27 +71,27 @@ public abstract class ServerSocketChannel
* @exception SecurityException If a security manager has been installed and * @exception SecurityException If a security manager has been installed and
* it does not permit access to the remote endpoint of the new connection. * it does not permit access to the remote endpoint of the new connection.
*/ */
public abstract SocketChannel accept () throws IOException; public abstract SocketChannel accept() throws IOException;
/** /**
* Retrieves the channels socket. * Retrieves the channels socket.
*/ */
public abstract ServerSocket socket (); public abstract ServerSocket socket();
/** /**
* Opens a server socket channel. * Opens a server socket channel.
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public static ServerSocketChannel open () throws IOException public static ServerSocketChannel open() throws IOException
{ {
return SelectorProvider.provider ().openServerSocketChannel (); return SelectorProvider.provider().openServerSocketChannel();
} }
/** /**
* Retrieves the valid operations for this channel. * Retrieves the valid operations for this channel.
*/ */
public final int validOps () public final int validOps()
{ {
return SelectionKey.OP_ACCEPT; return SelectionKey.OP_ACCEPT;
} }
......
...@@ -37,26 +37,27 @@ exception statement from your version. */ ...@@ -37,26 +37,27 @@ exception statement from your version. */
package java.nio.channels; package java.nio.channels;
import java.nio.channels.spi.AbstractSelectableChannel;
import java.nio.channels.spi.SelectorProvider;
import java.nio.ByteBuffer;
import java.io.IOException; import java.io.IOException;
import java.net.Socket; import java.net.Socket;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.spi.AbstractSelectableChannel;
import java.nio.channels.spi.SelectorProvider;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
*/ */
abstract public class SocketChannel extends AbstractSelectableChannel public abstract class SocketChannel extends AbstractSelectableChannel
implements ByteChannel, ScatteringByteChannel, GatheringByteChannel implements ByteChannel, ScatteringByteChannel, GatheringByteChannel
{ {
/** /**
* Initializes this socket. * Initializes this socket.
*/ */
protected SocketChannel (SelectorProvider provider) protected SocketChannel(SelectorProvider provider)
{ {
super (provider); super(provider);
} }
/** /**
...@@ -64,9 +65,9 @@ abstract public class SocketChannel extends AbstractSelectableChannel ...@@ -64,9 +65,9 @@ abstract public class SocketChannel extends AbstractSelectableChannel
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public static SocketChannel open () throws IOException public static SocketChannel open() throws IOException
{ {
return SelectorProvider.provider ().openSocketChannel (); return SelectorProvider.provider().openSocketChannel();
} }
/** /**
...@@ -84,9 +85,10 @@ abstract public class SocketChannel extends AbstractSelectableChannel ...@@ -84,9 +85,10 @@ abstract public class SocketChannel extends AbstractSelectableChannel
* @exception UnsupportedAddressTypeException If the type of the given remote * @exception UnsupportedAddressTypeException If the type of the given remote
* address is not supported. * address is not supported.
*/ */
public static SocketChannel open (SocketAddress remote) throws IOException public static SocketChannel open(SocketAddress remote)
throws IOException
{ {
SocketChannel ch = open (); SocketChannel ch = open();
ch.connect(remote); ch.connect(remote);
return ch; return ch;
} }
...@@ -97,14 +99,12 @@ abstract public class SocketChannel extends AbstractSelectableChannel ...@@ -97,14 +99,12 @@ abstract public class SocketChannel extends AbstractSelectableChannel
* @exception IOException If an error occurs * @exception IOException If an error occurs
* @exception NotYetConnectedException If this channel is not yet connected. * @exception NotYetConnectedException If this channel is not yet connected.
*/ */
public final long read (ByteBuffer[] dsts) throws IOException public final long read(ByteBuffer[] dsts) throws IOException
{ {
long b = 0; long b = 0;
for (int i = 0; i < dsts.length; i++) for (int i = 0; i < dsts.length; i++)
{ b += read(dsts[i]);
b += read (dsts [i]);
}
return b; return b;
} }
...@@ -115,14 +115,12 @@ abstract public class SocketChannel extends AbstractSelectableChannel ...@@ -115,14 +115,12 @@ abstract public class SocketChannel extends AbstractSelectableChannel
* @exception IOException If an error occurs * @exception IOException If an error occurs
* @exception NotYetConnectedException If this channel is not yet connected. * @exception NotYetConnectedException If this channel is not yet connected.
*/ */
public final long write (ByteBuffer[] dsts) throws IOException public final long write(ByteBuffer[] dsts) throws IOException
{ {
long b = 0; long b = 0;
for (int i= 0; i < dsts.length; i++) for (int i = 0; i < dsts.length; i++)
{ b += write(dsts[i]);
b += write (dsts [i]);
}
return b; return b;
} }
...@@ -130,9 +128,10 @@ abstract public class SocketChannel extends AbstractSelectableChannel ...@@ -130,9 +128,10 @@ abstract public class SocketChannel extends AbstractSelectableChannel
/** /**
* Retrieves the valid operations for this channel. * Retrieves the valid operations for this channel.
*/ */
public final int validOps () public final int validOps()
{ {
return SelectionKey.OP_CONNECT | SelectionKey.OP_READ | SelectionKey.OP_WRITE; return SelectionKey.OP_CONNECT | SelectionKey.OP_READ
| SelectionKey.OP_WRITE;
} }
/** /**
...@@ -141,7 +140,7 @@ abstract public class SocketChannel extends AbstractSelectableChannel ...@@ -141,7 +140,7 @@ abstract public class SocketChannel extends AbstractSelectableChannel
* @exception IOException If an error occurs * @exception IOException If an error occurs
* @exception NotYetConnectedException If this channel is not yet connected. * @exception NotYetConnectedException If this channel is not yet connected.
*/ */
public abstract int read (ByteBuffer dst) throws IOException; public abstract int read(ByteBuffer dst) throws IOException;
/** /**
* Connects the channel's socket to the remote address. * Connects the channel's socket to the remote address.
...@@ -162,7 +161,8 @@ abstract public class SocketChannel extends AbstractSelectableChannel ...@@ -162,7 +161,8 @@ abstract public class SocketChannel extends AbstractSelectableChannel
* @exception UnsupportedAddressTypeException If the type of the given remote * @exception UnsupportedAddressTypeException If the type of the given remote
* address is not supported. * address is not supported.
*/ */
public abstract boolean connect (SocketAddress remote) throws IOException; public abstract boolean connect(SocketAddress remote)
throws IOException;
/** /**
* Finishes the process of connecting a socket channel. * Finishes the process of connecting a socket channel.
...@@ -176,17 +176,17 @@ abstract public class SocketChannel extends AbstractSelectableChannel ...@@ -176,17 +176,17 @@ abstract public class SocketChannel extends AbstractSelectableChannel
* @exception NoConnectionPendingException If this channel is not connected * @exception NoConnectionPendingException If this channel is not connected
* and a connection operation has not been initiated. * and a connection operation has not been initiated.
*/ */
public abstract boolean finishConnect () throws IOException; public abstract boolean finishConnect() throws IOException;
/** /**
* Tells whether or not the channel's socket is connected. * Tells whether or not the channel's socket is connected.
*/ */
public abstract boolean isConnected (); public abstract boolean isConnected();
/** /**
* Tells whether or not a connection operation is in progress on this channel. * Tells whether or not a connection operation is in progress on this channel.
*/ */
public abstract boolean isConnectionPending (); public abstract boolean isConnectionPending();
/** /**
* Reads data from the channel. * Reads data from the channel.
...@@ -194,13 +194,13 @@ abstract public class SocketChannel extends AbstractSelectableChannel ...@@ -194,13 +194,13 @@ abstract public class SocketChannel extends AbstractSelectableChannel
* @exception IOException If an error occurs * @exception IOException If an error occurs
* @exception NotYetConnectedException If this channel is not yet connected. * @exception NotYetConnectedException If this channel is not yet connected.
*/ */
public abstract long read (ByteBuffer[] dsts, int offset, int length) public abstract long read(ByteBuffer[] dsts, int offset, int length)
throws IOException; throws IOException;
/** /**
* Retrieves the channel's socket. * Retrieves the channel's socket.
*/ */
public abstract Socket socket (); public abstract Socket socket();
/** /**
* Writes data to the channel. * Writes data to the channel.
...@@ -208,7 +208,7 @@ abstract public class SocketChannel extends AbstractSelectableChannel ...@@ -208,7 +208,7 @@ abstract public class SocketChannel extends AbstractSelectableChannel
* @exception IOException If an error occurs * @exception IOException If an error occurs
* @exception NotYetConnectedException If this channel is not yet connected. * @exception NotYetConnectedException If this channel is not yet connected.
*/ */
public abstract int write (ByteBuffer src) throws IOException; public abstract int write(ByteBuffer src) throws IOException;
/** /**
* Writes data to the channel. * Writes data to the channel.
...@@ -216,6 +216,6 @@ abstract public class SocketChannel extends AbstractSelectableChannel ...@@ -216,6 +216,6 @@ abstract public class SocketChannel extends AbstractSelectableChannel
* @exception IOException If an error occurs * @exception IOException If an error occurs
* @exception NotYetConnectedException If this channel is not yet connected. * @exception NotYetConnectedException If this channel is not yet connected.
*/ */
public abstract long write (ByteBuffer[] srcs, int offset, int length) public abstract long write(ByteBuffer[] srcs, int offset, int length)
throws IOException; throws IOException;
} }
...@@ -37,6 +37,7 @@ exception statement from your version. */ ...@@ -37,6 +37,7 @@ exception statement from your version. */
package java.nio.channels; package java.nio.channels;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
......
...@@ -37,6 +37,7 @@ exception statement from your version. */ ...@@ -37,6 +37,7 @@ exception statement from your version. */
package java.nio.channels; package java.nio.channels;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
......
...@@ -40,8 +40,8 @@ package java.nio.channels; ...@@ -40,8 +40,8 @@ package java.nio.channels;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
public interface WritableByteChannel
extends Channel public interface WritableByteChannel extends Channel
{ {
/** /**
* Writes a sequence of bytes to this channel from the given buffer * Writes a sequence of bytes to this channel from the given buffer
...@@ -56,5 +56,5 @@ public interface WritableByteChannel ...@@ -56,5 +56,5 @@ public interface WritableByteChannel
* @exception NonWritableChannelException If this channel was not opened for * @exception NonWritableChannelException If this channel was not opened for
* writing * writing
*/ */
int write (ByteBuffer src) throws IOException; int write(ByteBuffer src) throws IOException;
} }
/* AbstractInterruptibleChannel.java -- /* AbstractInterruptibleChannel.java --
Copyright (C) 2002 Free Software Foundation, Inc. Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -42,6 +42,7 @@ import java.nio.channels.AsynchronousCloseException; ...@@ -42,6 +42,7 @@ import java.nio.channels.AsynchronousCloseException;
import java.nio.channels.Channel; import java.nio.channels.Channel;
import java.nio.channels.InterruptibleChannel; import java.nio.channels.InterruptibleChannel;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
...@@ -54,14 +55,14 @@ public abstract class AbstractInterruptibleChannel ...@@ -54,14 +55,14 @@ public abstract class AbstractInterruptibleChannel
/** /**
* Initializes the channel. * Initializes the channel.
*/ */
protected AbstractInterruptibleChannel () protected AbstractInterruptibleChannel()
{ {
} }
/** /**
* Marks the beginning of an I/O operation that might block indefinitely. * Marks the beginning of an I/O operation that might block indefinitely.
*/ */
protected final void begin () protected final void begin()
{ {
} }
...@@ -70,9 +71,9 @@ public abstract class AbstractInterruptibleChannel ...@@ -70,9 +71,9 @@ public abstract class AbstractInterruptibleChannel
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public final void close () throws IOException public final void close() throws IOException
{ {
if (!closed) if (! closed)
{ {
closed = true; closed = true;
implCloseChannel(); implCloseChannel();
...@@ -82,14 +83,21 @@ public abstract class AbstractInterruptibleChannel ...@@ -82,14 +83,21 @@ public abstract class AbstractInterruptibleChannel
/** /**
* Marks the end of an I/O operation that might block indefinitely. * 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 * @exception AsynchronousCloseException If the channel was asynchronously
* closed. * closed.
* @exception ClosedByInterruptException If the thread blocked in the * @exception ClosedByInterruptException If the thread blocked in the
* I/O operation was interrupted. * I/O operation was interrupted.
*/ */
protected final void end (boolean completed) protected final void end(boolean completed)
throws AsynchronousCloseException throws AsynchronousCloseException
{ {
// FIXME: check more here.
if (closed) throw new AsynchronousCloseException();
} }
/** /**
...@@ -97,13 +105,15 @@ public abstract class AbstractInterruptibleChannel ...@@ -97,13 +105,15 @@ public abstract class AbstractInterruptibleChannel
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
protected abstract void implCloseChannel () throws IOException; protected abstract void implCloseChannel() throws IOException;
/** /**
* Tells whether or not this channel is open. * Tells whether or not this channel is open.
*
* @return true if the channel is open, false otherwise
*/ */
public final boolean isOpen () public final boolean isOpen()
{ {
return !closed; return ! closed;
} }
} }
...@@ -43,9 +43,9 @@ import java.nio.channels.SelectableChannel; ...@@ -43,9 +43,9 @@ import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey; import java.nio.channels.SelectionKey;
import java.nio.channels.Selector; import java.nio.channels.Selector;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
public abstract class AbstractSelectableChannel extends SelectableChannel public abstract class AbstractSelectableChannel extends SelectableChannel
{ {
private boolean blocking = true; private boolean blocking = true;
...@@ -55,8 +55,10 @@ public abstract class AbstractSelectableChannel extends SelectableChannel ...@@ -55,8 +55,10 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
/** /**
* Initializes the channel * Initializes the channel
*
* @param provider the provider that created this channel
*/ */
protected AbstractSelectableChannel (SelectorProvider provider) protected AbstractSelectableChannel(SelectorProvider provider)
{ {
this.provider = provider; this.provider = provider;
} }
...@@ -64,16 +66,24 @@ public abstract class AbstractSelectableChannel extends SelectableChannel ...@@ -64,16 +66,24 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
/** /**
* Retrieves the object upon which the configureBlocking and register * Retrieves the object upon which the configureBlocking and register
* methods synchronize. * methods synchronize.
*
* @return the blocking lock
*/ */
public final Object blockingLock () public final Object blockingLock()
{ {
return LOCK; return LOCK;
} }
/** /**
* Adjusts this channel's blocking mode. * 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) public final SelectableChannel configureBlocking(boolean blocking)
throws IOException throws IOException
{ {
synchronized (blockingLock()) synchronized (blockingLock())
...@@ -93,25 +103,34 @@ public abstract class AbstractSelectableChannel extends SelectableChannel ...@@ -93,25 +103,34 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
protected final void implCloseChannel () throws IOException protected final void implCloseChannel() throws IOException
{ {
implCloseSelectableChannel (); implCloseSelectableChannel();
} }
/** /**
* Closes this selectable channel. * Closes this selectable channel.
*
* @exception IOException If an error occurs
*/ */
protected abstract void implCloseSelectableChannel () throws IOException; protected abstract void implCloseSelectableChannel()
throws IOException;
/** /**
* Adjusts this channel's blocking mode. * 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 block) protected abstract void implConfigureBlocking(boolean blocking)
throws IOException; throws IOException;
/** /**
* Tells whether or not every I/O operation on this channel will block * Tells whether or not every I/O operation on this channel will block
* until it completes. * until it completes.
*
* @return true of this channel is blocking, false otherwise
*/ */
public final boolean isBlocking() public final boolean isBlocking()
{ {
...@@ -121,15 +140,21 @@ public abstract class AbstractSelectableChannel extends SelectableChannel ...@@ -121,15 +140,21 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
/** /**
* Tells whether or not this channel is currently registered with * Tells whether or not this channel is currently registered with
* any selectors. * any selectors.
*
* @return true if this channel is registered, false otherwise
*/ */
public final boolean isRegistered() public final boolean isRegistered()
{ {
return !keys.isEmpty(); return ! keys.isEmpty();
} }
/** /**
* Retrieves the key representing the channel's registration with the * Retrieves the key representing the channel's registration with the
* given selector. * 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) public final SelectionKey keyFor(Selector selector)
{ {
...@@ -138,9 +163,9 @@ public abstract class AbstractSelectableChannel extends SelectableChannel ...@@ -138,9 +163,9 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
try try
{ {
synchronized(blockingLock()) synchronized (blockingLock())
{ {
return locate (selector); return locate(selector);
} }
} }
catch (Exception e) catch (Exception e)
...@@ -151,17 +176,19 @@ public abstract class AbstractSelectableChannel extends SelectableChannel ...@@ -151,17 +176,19 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
/** /**
* Returns the provider that created this channel. * Returns the provider that created this channel.
*
* @return the selector provider that created this channel
*/ */
public final SelectorProvider provider () public final SelectorProvider provider()
{ {
return provider; return provider;
} }
private SelectionKey locate (Selector selector) private SelectionKey locate(Selector selector)
{ {
ListIterator it = keys.listIterator (); ListIterator it = keys.listIterator();
while (it.hasNext ()) while (it.hasNext())
{ {
SelectionKey key = (SelectionKey) it.next(); SelectionKey key = (SelectionKey) it.next();
...@@ -175,32 +202,41 @@ public abstract class AbstractSelectableChannel extends SelectableChannel ...@@ -175,32 +202,41 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
/** /**
* Registers this channel with the given selector, returning a selection key. * Registers this channel with the given selector, returning a selection key.
* *
* @param selin the seletor to use
* @param ops the interested operations
* @param att an attachment for the returned selection key
*
* @return the registered selection key
*
* @exception ClosedChannelException If the channel is already closed. * @exception ClosedChannelException If the channel is already closed.
*/ */
public final SelectionKey register (Selector selin, int ops, Object att) public final SelectionKey register(Selector selin, int ops, Object att)
throws ClosedChannelException throws ClosedChannelException
{ {
if (!isOpen ()) if (! isOpen())
throw new ClosedChannelException(); throw new ClosedChannelException();
if ((ops & ~validOps()) != 0)
throw new IllegalArgumentException();
SelectionKey key = null; SelectionKey key = null;
AbstractSelector selector = (AbstractSelector) selin; AbstractSelector selector = (AbstractSelector) selin;
synchronized (blockingLock()) synchronized (blockingLock())
{ {
key = locate (selector); key = locate(selector);
if (key != null) if (key != null)
{ {
if (att != null) if (att != null)
key.attach (att); key.attach(att);
} }
else else
{ {
key = selector.register (this, ops, att); key = selector.register(this, ops, att);
if (key != null) if (key != null)
addSelectionKey (key); addSelectionKey(key);
} }
} }
......
...@@ -39,25 +39,25 @@ package java.nio.channels.spi; ...@@ -39,25 +39,25 @@ package java.nio.channels.spi;
import java.nio.channels.SelectionKey; import java.nio.channels.SelectionKey;
/** /**
* @since 1.4 * @since 1.4
*/ */
public abstract class AbstractSelectionKey public abstract class AbstractSelectionKey extends SelectionKey
extends SelectionKey
{ {
private boolean cancelled = false; private boolean cancelled;
/** /**
* Initializes the key. * Initializes the key.
*/ */
protected AbstractSelectionKey () protected AbstractSelectionKey()
{ {
} }
/** /**
* Cancels this key. * Cancels this key.
*/ */
public final void cancel () public final void cancel()
{ {
if (isValid()) if (isValid())
{ {
...@@ -68,9 +68,11 @@ public abstract class AbstractSelectionKey ...@@ -68,9 +68,11 @@ public abstract class AbstractSelectionKey
/** /**
* Tells whether this key is valid or not. * Tells whether this key is valid or not.
*
* @return true if this key is valid, false otherwise
*/ */
public final boolean isValid () public final boolean isValid()
{ {
return !cancelled; return ! cancelled;
} }
} }
...@@ -35,26 +35,28 @@ this exception to your version of the library, but you are not ...@@ -35,26 +35,28 @@ 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 obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package java.nio.channels.spi; package java.nio.channels.spi;
import java.io.IOException; import java.io.IOException;
import java.nio.channels.ClosedSelectorException; import java.nio.channels.ClosedSelectorException;
import java.nio.channels.SelectionKey; import java.nio.channels.SelectionKey;
import java.nio.channels.Selector; import java.nio.channels.Selector;
import java.util.Set;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set;
public abstract class AbstractSelector extends Selector public abstract class AbstractSelector extends Selector
{ {
private boolean closed = false; private boolean closed;
private SelectorProvider provider; private SelectorProvider provider;
private HashSet cancelledKeys; private HashSet cancelledKeys;
/** /**
* Initializes the slector. * Initializes the slector.
*
* @param provider the provider that created this selector
*/ */
protected AbstractSelector (SelectorProvider provider) protected AbstractSelector(SelectorProvider provider)
{ {
this.provider = provider; this.provider = provider;
this.cancelledKeys = new HashSet(); this.cancelledKeys = new HashSet();
...@@ -65,7 +67,7 @@ public abstract class AbstractSelector extends Selector ...@@ -65,7 +67,7 @@ public abstract class AbstractSelector extends Selector
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public final synchronized void close () throws IOException public final synchronized void close() throws IOException
{ {
if (closed) if (closed)
return; return;
...@@ -76,8 +78,10 @@ public abstract class AbstractSelector extends Selector ...@@ -76,8 +78,10 @@ public abstract class AbstractSelector extends Selector
/** /**
* Tells whether this channel is open or not. * Tells whether this channel is open or not.
*
* @return true if channel is open, false otherwise.
*/ */
public final boolean isOpen () public final boolean isOpen()
{ {
return ! closed; return ! closed;
} }
...@@ -98,18 +102,22 @@ public abstract class AbstractSelector extends Selector ...@@ -98,18 +102,22 @@ public abstract class AbstractSelector extends Selector
/** /**
* Returns the provider for this selector object. * Returns the provider for this selector object.
*
* @return the SelectorProvider object that created this seletor
*/ */
public final SelectorProvider provider () public final SelectorProvider provider()
{ {
return provider; return provider;
} }
/** /**
* Returns the cancelled keys set. * Returns the cancelled keys set.
*
* @return the cancelled keys set
*/ */
protected final Set cancelledKeys() protected final Set cancelledKeys()
{ {
if (!isOpen()) if (! isOpen())
throw new ClosedSelectorException(); throw new ClosedSelectorException();
return cancelledKeys; return cancelledKeys;
...@@ -118,8 +126,9 @@ public abstract class AbstractSelector extends Selector ...@@ -118,8 +126,9 @@ public abstract class AbstractSelector extends Selector
/** /**
* Cancels a selection key. * Cancels a selection key.
*/ */
// This method is only called by AbstractSelectionKey.cancel(). // This method is only called by AbstractSelectionKey.cancel().
final void cancelKey (AbstractSelectionKey key) final void cancelKey(AbstractSelectionKey key)
{ {
synchronized (cancelledKeys) synchronized (cancelledKeys)
{ {
...@@ -129,13 +138,29 @@ public abstract class AbstractSelector extends Selector ...@@ -129,13 +138,29 @@ public abstract class AbstractSelector extends Selector
/** /**
* Closes the channel. * Closes the channel.
*
* @exception IOException if an error occurs
*/ */
protected abstract void implCloseSelector () throws IOException; protected abstract void implCloseSelector() throws IOException;
protected abstract SelectionKey register (AbstractSelectableChannel ch, /**
* 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); int ops, Object att);
protected final void deregister (AbstractSelectionKey key) /**
* Deregisters the given selection key.
*
* @param key the key to deregister
*/
protected final void deregister(AbstractSelectionKey key)
{ {
((AbstractSelectableChannel) key.channel()).removeSelectionKey(key); ((AbstractSelectableChannel) key.channel()).removeSelectionKey(key);
} }
......
...@@ -44,6 +44,7 @@ import java.nio.channels.Pipe; ...@@ -44,6 +44,7 @@ import java.nio.channels.Pipe;
import java.nio.channels.ServerSocketChannel; import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel; import java.nio.channels.SocketChannel;
/** /**
* @author Michael Koch * @author Michael Koch
* @since 1.4 * @since 1.4
...@@ -58,63 +59,86 @@ public abstract class SelectorProvider ...@@ -58,63 +59,86 @@ public abstract class SelectorProvider
* @exception SecurityException If a security manager has been installed and * @exception SecurityException If a security manager has been installed and
* it denies @see RuntimePermission ("selectorProvider"). * it denies @see RuntimePermission ("selectorProvider").
*/ */
protected SelectorProvider () protected SelectorProvider()
{ {
SecurityManager sm = System.getSecurityManager (); SecurityManager sm = System.getSecurityManager();
if (sm != null) if (sm != null)
sm.checkPermission (new RuntimePermission ("selectorProvider")); sm.checkPermission(new RuntimePermission("selectorProvider"));
} }
/** /**
* Opens a datagram channel. * Opens a datagram channel.
*
* @return a new datagram channel object
*
* @exception IOException if an error occurs
*/ */
public abstract DatagramChannel openDatagramChannel () throws IOException; public abstract DatagramChannel openDatagramChannel()
throws IOException;
/** /**
* Opens a pipe. * Opens a pipe.
*
* @return a new pipe object
*
* @exception IOException if an error occurs
*/ */
public abstract Pipe openPipe () throws IOException; public abstract Pipe openPipe() throws IOException;
/** /**
* Opens a selector. * Opens a selector.
*
* @return a new selector object
*
* @exception IOException if an error occurs
*/ */
public abstract AbstractSelector openSelector () throws IOException; public abstract AbstractSelector openSelector() throws IOException;
/** /**
* Opens a server socket channel. * Opens a server socket channel.
*
* @return a new server socket channel object
*
* @exception IOException if an error occurs
*/ */
public abstract ServerSocketChannel openServerSocketChannel () public abstract ServerSocketChannel openServerSocketChannel()
throws IOException; throws IOException;
/** /**
* Opens a socket channel. * Opens a socket channel.
*
* @return a new socket channel object
*
* @exception IOException if an error occurs
*/ */
public abstract SocketChannel openSocketChannel () throws IOException; public abstract SocketChannel openSocketChannel() throws IOException;
/** /**
* Returns the system-wide default selector provider for this invocation * Returns the system-wide default selector provider for this invocation
* of the Java virtual machine. * of the Java virtual machine.
*
* @return the default seletor provider
*/ */
public static synchronized SelectorProvider provider () public static synchronized SelectorProvider provider()
{ {
if (systemDefaultProvider == null) if (systemDefaultProvider == null)
{ {
String propertyValue = String propertyValue =
System.getProperty ("java.nio.channels.spi.SelectorProvider"); System.getProperty("java.nio.channels.spi.SelectorProvider");
if (propertyValue == null if (propertyValue == null || propertyValue.equals(""))
|| propertyValue.equals (""))
systemDefaultProvider = new SelectorProviderImpl(); systemDefaultProvider = new SelectorProviderImpl();
else else
{ {
try try
{ {
systemDefaultProvider = (SelectorProvider) Class.forName systemDefaultProvider =
(propertyValue).newInstance(); (SelectorProvider) Class.forName(propertyValue)
.newInstance();
} }
catch (Exception e) catch (Exception e)
{ {
System.err.println ("Could not instantiate class: " System.err.println("Could not instantiate class: "
+ propertyValue); + propertyValue);
systemDefaultProvider = new SelectorProviderImpl(); systemDefaultProvider = new SelectorProviderImpl();
} }
......
...@@ -40,6 +40,7 @@ package java.nio.charset.spi; ...@@ -40,6 +40,7 @@ package java.nio.charset.spi;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.Iterator; import java.util.Iterator;
/** /**
* This class allows an implementor to provide additional character sets. The * This class allows an implementor to provide additional character sets. The
* subclass must have a nullary constructor, and be attached to charset * subclass must have a nullary constructor, and be attached to charset
...@@ -82,6 +83,8 @@ public abstract class CharsetProvider ...@@ -82,6 +83,8 @@ public abstract class CharsetProvider
/** /**
* Returns the named charset, by canonical name or alias. * Returns the named charset, by canonical name or alias.
* *
* @param name the name of the character
*
* @return the charset, or null if not supported * @return the charset, or null if not supported
*/ */
public abstract Charset charsetForName(String name); public abstract Charset charsetForName(String name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment