1 |
/* SocketChannel.java -- |
/* SocketChannel.java -- |
2 |
Copyright (C) 2002 Free Software Foundation, Inc. |
Copyright (C) 2002, 2004 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
35 |
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 |
36 |
exception statement from your version. */ |
exception statement from your version. */ |
37 |
|
|
38 |
|
|
39 |
package java.nio.channels; |
package java.nio.channels; |
40 |
|
|
41 |
import java.io.IOException; |
import java.io.IOException; |
45 |
import java.nio.channels.spi.AbstractSelectableChannel; |
import java.nio.channels.spi.AbstractSelectableChannel; |
46 |
import java.nio.channels.spi.SelectorProvider; |
import java.nio.channels.spi.SelectorProvider; |
47 |
|
|
|
|
|
48 |
/** |
/** |
49 |
* @author Michael Koch |
* @author Michael Koch (konqueror@gmx.de) |
50 |
* @since 1.4 |
* @since 1.4 |
51 |
*/ |
*/ |
52 |
public abstract class SocketChannel extends AbstractSelectableChannel |
public abstract class SocketChannel extends AbstractSelectableChannel |
53 |
implements ByteChannel, ScatteringByteChannel, GatheringByteChannel |
implements ByteChannel, ScatteringByteChannel, GatheringByteChannel |
54 |
{ |
{ |
55 |
/** |
/** |
56 |
* Initializes this socket. |
* Initializes this socket channel. |
57 |
*/ |
*/ |
58 |
protected SocketChannel(SelectorProvider provider) |
protected SocketChannel(SelectorProvider provider) |
59 |
{ |
{ |
63 |
/** |
/** |
64 |
* Opens a socket channel. |
* Opens a socket channel. |
65 |
* |
* |
66 |
|
* @return the new <code>SocketChannel</code> object |
67 |
|
* |
68 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
69 |
*/ |
*/ |
70 |
public static SocketChannel open() throws IOException |
public static SocketChannel open() throws IOException |
75 |
/** |
/** |
76 |
* Opens a channel and connects it to a remote address. |
* Opens a channel and connects it to a remote address. |
77 |
* |
* |
78 |
|
* @return the new <code>SocketChannel</code> object |
79 |
|
* |
80 |
* @exception AsynchronousCloseException If this channel is already connected. |
* @exception AsynchronousCloseException If this channel is already connected. |
81 |
* @exception ClosedByInterruptException If another thread interrupts the |
* @exception ClosedByInterruptException If another thread interrupts the |
82 |
* current thread while the connect operation is in progress, thereby closing |
* current thread while the connect operation is in progress, thereby closing |
100 |
/** |
/** |
101 |
* Reads data from the channel. |
* Reads data from the channel. |
102 |
* |
* |
103 |
|
* @return the number of bytes read, zero is valid too, -1 if end of stream |
104 |
|
* is reached |
105 |
|
* |
106 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
107 |
* @exception NotYetConnectedException If this channel is not yet connected. |
* @exception NotYetConnectedException If this channel is not yet connected. |
108 |
*/ |
*/ |
119 |
/** |
/** |
120 |
* Writes data to the channel. |
* Writes data to the channel. |
121 |
* |
* |
122 |
|
* @return the number of bytes written, zero is valid too |
123 |
|
* |
124 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
125 |
* @exception NotYetConnectedException If this channel is not yet connected. |
* @exception NotYetConnectedException If this channel is not yet connected. |
126 |
*/ |
*/ |
136 |
|
|
137 |
/** |
/** |
138 |
* Retrieves the valid operations for this channel. |
* Retrieves the valid operations for this channel. |
139 |
|
* |
140 |
|
* @return the valid operations |
141 |
*/ |
*/ |
142 |
public final int validOps() |
public final int validOps() |
143 |
{ |
{ |
148 |
/** |
/** |
149 |
* Reads data from the channel. |
* Reads data from the channel. |
150 |
* |
* |
151 |
|
* @return the number of bytes read, zero is valid too, -1 if end of stream |
152 |
|
* is reached |
153 |
|
* |
154 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
155 |
* @exception NotYetConnectedException If this channel is not yet connected. |
* @exception NotYetConnectedException If this channel is not yet connected. |
156 |
*/ |
*/ |
159 |
/** |
/** |
160 |
* Connects the channel's socket to the remote address. |
* Connects the channel's socket to the remote address. |
161 |
* |
* |
162 |
|
* @return <code>true</code> if the channel got successfully connected, |
163 |
|
* <code>false</code> if the channel is in non-blocking mode and connection |
164 |
|
* operation is still in progress. |
165 |
|
* |
166 |
* @exception AlreadyConnectedException If this channel is already connected. |
* @exception AlreadyConnectedException If this channel is already connected. |
167 |
* @exception AsynchronousCloseException If this channel is already connected. |
* @exception AsynchronousCloseException If this channel is already connected. |
168 |
* @exception ClosedByInterruptException If another thread interrupts the |
* @exception ClosedByInterruptException If another thread interrupts the |
209 |
/** |
/** |
210 |
* Reads data from the channel. |
* Reads data from the channel. |
211 |
* |
* |
212 |
|
* @return the number of bytes read, zero is valid too, -1 if end of stream |
213 |
|
* is reached |
214 |
|
* |
215 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
216 |
* @exception NotYetConnectedException If this channel is not yet connected. |
* @exception NotYetConnectedException If this channel is not yet connected. |
217 |
*/ |
*/ |
220 |
|
|
221 |
/** |
/** |
222 |
* Retrieves the channel's socket. |
* Retrieves the channel's socket. |
223 |
|
* |
224 |
|
* @return the socket |
225 |
*/ |
*/ |
226 |
public abstract Socket socket(); |
public abstract Socket socket(); |
227 |
|
|
228 |
/** |
/** |
229 |
* Writes data to the channel. |
* Writes data to the channel. |
230 |
* |
* |
231 |
|
* @return the number of bytes written, zero is valid too |
232 |
|
* |
233 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
234 |
* @exception NotYetConnectedException If this channel is not yet connected. |
* @exception NotYetConnectedException If this channel is not yet connected. |
235 |
*/ |
*/ |
238 |
/** |
/** |
239 |
* Writes data to the channel. |
* Writes data to the channel. |
240 |
* |
* |
241 |
|
* @return the number of bytes written, zero is valid too |
242 |
|
* |
243 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
244 |
* @exception NotYetConnectedException If this channel is not yet connected. |
* @exception NotYetConnectedException If this channel is not yet connected. |
245 |
*/ |
*/ |