Buffer.java: Implemented.
2002-11-13 Michael Koch <konqueror@gmx.de> * java/nio/Buffer.java: Implemented. * java/nio/CharBuffer.java: New file. * java/nio/InvalidMarkException.java: New file. * java/nio/channels/DatagramChannel.java: Implemented. * java/nio/channels/ServerSocketChannel.java: Implemented. * java/nio/channels/SocketChannel.java: Implemented. * java/nio/channels/spi/AbstractChannel.java: Removed. * java/nio/channels/spi/AbstractSelectableChannel.java: Implemented. * java/nio/charset/Charset.java: Merge from Classpath. * java/nio/charset/CharsetDecoder.java: New file. * java/nio/charset/CharsetEncoder.java: New file. * java/nio/charset/CoderResult.java: New file. * Makefile.am (ordinary_java_source_files): Added new files. * Makefile.in: Regenerated. From-SVN: r59075
This commit is contained in:
parent
7b53becc10
commit
93f93f9f28
14 changed files with 2006 additions and 82 deletions
|
@ -39,12 +39,127 @@ 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.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
|
||||
public abstract class SocketChannel
|
||||
extends AbstractSelectableChannel
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
abstract public class SocketChannel extends AbstractSelectableChannel
|
||||
{
|
||||
public SocketChannel (SelectorProvider provider)
|
||||
/**
|
||||
* Initializes this socket.
|
||||
*/
|
||||
protected SocketChannel (SelectorProvider provider)
|
||||
{
|
||||
super (provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a socket channel.
|
||||
*/
|
||||
public static SocketChannel open () throws IOException
|
||||
{
|
||||
return SelectorProvider.provider ().openSocketChannel ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a channel and connects it to a remote address.
|
||||
*/
|
||||
public static SocketChannel open (SocketAddress remote) throws IOException
|
||||
{
|
||||
SocketChannel ch = open ();
|
||||
|
||||
if (ch.connect (remote))
|
||||
{
|
||||
}
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads data from the channel.
|
||||
*/
|
||||
public final long read (ByteBuffer[] dsts)
|
||||
{
|
||||
long b = 0;
|
||||
|
||||
for (int i = 0; i < dsts.length; i++)
|
||||
{
|
||||
b += read (dsts [i]);
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes data to the channel.
|
||||
*/
|
||||
public final long write (ByteBuffer[] dsts)
|
||||
{
|
||||
long b = 0;
|
||||
|
||||
for (int i= 0; i < dsts.length; i++)
|
||||
{
|
||||
b += write (dsts [i]);
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the valid operations for this channel.
|
||||
*/
|
||||
public final int validOps ()
|
||||
{
|
||||
return SelectionKey.OP_CONNECT | SelectionKey.OP_READ | SelectionKey.OP_WRITE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads data from the channel.
|
||||
*/
|
||||
public abstract int read (ByteBuffer dst);
|
||||
|
||||
/**
|
||||
* Connects the channel's socket to the remote address.
|
||||
*/
|
||||
public abstract boolean connect (SocketAddress remote) throws IOException;
|
||||
|
||||
/**
|
||||
* Finishes the process of connecting a socket channel.
|
||||
*/
|
||||
public abstract boolean finishConnect ();
|
||||
|
||||
/**
|
||||
* Tells whether or not the channel's socket is connected.
|
||||
*/
|
||||
public abstract boolean isConnected ();
|
||||
|
||||
/**
|
||||
* Tells whether or not a connection operation is in progress on this channel.
|
||||
*/
|
||||
public abstract boolean isConnectionPending ();
|
||||
|
||||
/**
|
||||
* Reads data from the channel.
|
||||
*/
|
||||
public abstract long read (ByteBuffer[] dsts, int offset, int length);
|
||||
|
||||
/**
|
||||
* Retrieves the channel's socket.
|
||||
*/
|
||||
public abstract Socket socket ();
|
||||
|
||||
/**
|
||||
* Writes data to the channel.
|
||||
*/
|
||||
public abstract int write (ByteBuffer src);
|
||||
|
||||
/**
|
||||
* Writes data to the channel.
|
||||
*/
|
||||
public abstract long write (ByteBuffer[] srcs, int offset, int length);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue