| java.lang.Object com.sun.cdc.io.ConnectionBaseAdapter
All known Subclasses: com.sun.cdc.io.BufferedConnectionAdapter, com.sun.j2me.io.ConnectionBaseAdapter,
ConnectionBaseAdapter | abstract public class ConnectionBaseAdapter implements ConnectionBaseInterface,StreamConnection(Code) | | Protocol classes extend this class to gain some of the common functionality
needed to implement a CDC Generic Connection.
The common functionality includes:
- Supplies the input and output stream classes for a StreamConnection
- Limits the number of streams opened according to mode, but the limit
can be overridden. Read-write allows 1 input and 1 output, write-only
allows 1 output, read-only allows 1 input
- Only "disconnects" when the connection and all streams are closed
- Throws I/O exceptions when used after being closed
- Provides a more efficient implementation of
InputStream.read(byte[]intint) , which is called by
InputStream.read
- Provides a more efficient implementation of
OutputStream.write(byte[]intint) , which is called by
OutputStream.write(int)
Class Relationship Diagram
version: 3.0 9/1/2000 |
Field Summary | |
protected boolean | connectionOpen Flag indicating if the connection is open. | protected static int | iStreams Number of input streams that were opened. | protected int | maxIStreams Maximum number of open input streams. | protected int | maxOStreams Maximum number of output streams. | protected static int | oStreams Number of output streams were opened. |
Method Summary | |
public int | available() Returns the number of bytes that can be read (or skipped over) from
this input stream without blocking by the next caller of a method for
this input stream. | protected void | checkForPermission() Overridden by Protocols to check for permissions.
This implementation always throws a security exception.
The subclass is responsible for checking permissions and
maintaining the state (in private local fields) as to whether
it was granted. | public void | close() Close the connection. | void | closeCommon() Disconnect if the connection and all the streams and the closed. | protected void | closeInputStream() Called once by each child input stream. | protected void | closeOutputStream() Called once by each child output stream. | abstract protected void | connect(String name, int mode, boolean timeouts) Connect to a target. | abstract protected void | disconnect() Free up the connection resources. | protected void | ensureNoStreamsOpen() Check if the streams are open. | protected void | ensureOpen() Check if the connection is open. | protected void | flush() Forces any buffered output bytes to be written out. | public synchronized void | mark(int readlimit) Marks the current position in input stream for a connection. | public boolean | markSupported() Tests if input stream for a connection supports the mark and
reset methods. | public DataInputStream | openDataInputStream() Open and return a data input stream for a connection. | public DataOutputStream | openDataOutputStream() Open and return a data output stream for a connection. | public InputStream | openInputStream() Returns an input stream. | public OutputStream | openOutputStream() Returns an output stream. | public Connection | openPrim(String name, int mode, boolean timeouts) Check for required permission and open a connection to a target. | public Connection | openPrim(String name) Check for required permission and open a connection to a target.
This method can be used with permissions greater than
the current app. | abstract protected int | readBytes(byte b, int off, int len) Reads up to len bytes of data from the input stream into
an array of bytes, blocks until at least one byte is available.
Parameters: b - the buffer into which the data is read. Parameters: off - the start offset in array b at which the data is written. Parameters: len - the maximum number of bytes to read. | public synchronized void | reset() Repositions input stream for a connection to the position at the time the
mark method was last called on this input stream. | abstract protected int | writeBytes(byte b, int off, int len) Writes len bytes from the specified byte array
starting at offset off to this output stream.
Polling the native code is done here to allow for simple
asynchronous native code to be written. |
connectionOpen | protected boolean connectionOpen(Code) | | Flag indicating if the connection is open.
|
iStreams | protected static int iStreams(Code) | | Number of input streams that were opened.
|
maxIStreams | protected int maxIStreams(Code) | | Maximum number of open input streams. Set this
to zero to prevent openInputStream from giving out a stream in
write-only mode.
|
maxOStreams | protected int maxOStreams(Code) | | Maximum number of output streams. Set this
to zero to prevent openOutputStream from giving out a stream in
read-only mode.
|
oStreams | protected static int oStreams(Code) | | Number of output streams were opened.
|
available | public int available() throws IOException(Code) | | Returns the number of bytes that can be read (or skipped over) from
this input stream without blocking by the next caller of a method for
this input stream. The next caller might be the same thread or
another thread. This classes implementation always returns
0 . It is up to subclasses to override this method.
the number of bytes that can be read from this input streamwithout blocking. exception: IOException - if an I/O error occurs. |
checkForPermission | protected void checkForPermission() throws SecurityException, InterruptedIOException(Code) | | Overridden by Protocols to check for permissions.
This implementation always throws a security exception.
The subclass is responsible for checking permissions and
maintaining the state (in private local fields) as to whether
it was granted.
Parameters: token - security token of the calling class or null Parameters: name - the URL of the connection without the protocol exception: SecurityException - if permissions are not granted exception: InterruptedIOException - if I/O associated with permissions is interrupted |
close | public void close() throws IOException(Code) | | Close the connection.
exception: IOException - if an I/O error occurs when closing theconnection. |
closeCommon | void closeCommon() throws IOException(Code) | | Disconnect if the connection and all the streams and the closed.
exception: IOException - if an I/O error occurs when closing theconnection. |
closeInputStream | protected void closeInputStream() throws IOException(Code) | | Called once by each child input stream.
If the input stream is marked open, it will be marked closed and
the if the connection and output stream are closed the disconnect
method will be called.
exception: IOException - if the subclass throws one |
closeOutputStream | protected void closeOutputStream() throws IOException(Code) | | Called once by each child output stream.
If the output stream is marked open, it will be marked closed and
the if the connection and input stream are closed the disconnect
method will be called.
exception: IOException - if the subclass throws one |
connect | abstract protected void connect(String name, int mode, boolean timeouts) throws IOException(Code) | | Connect to a target.
Parameters: name - URL for the connection, without the protocolpart Parameters: mode - I/O access mode, see Connector Parameters: timeouts - flag to indicate that the called wantstimeout exceptions exception: IllegalArgumentException - If a parameter is invalid. exception: ConnectionNotFoundException - If the connection cannot befound. exception: IOException - If some other kind of I/O error occurs. |
disconnect | abstract protected void disconnect() throws IOException(Code) | | Free up the connection resources.
exception: IOException - if an I/O error occurs. |
ensureNoStreamsOpen | protected void ensureNoStreamsOpen() throws IOException(Code) | | Check if the streams are open.
exception: IOException - is thrown, if the stream is still open. |
ensureOpen | protected void ensureOpen() throws IOException(Code) | | Check if the connection is open.
exception: IOException - is thrown, if the stream is not open. |
flush | protected void flush() throws IOException(Code) | | Forces any buffered output bytes to be written out.
The general contract of flush is
that calling it is an indication that, if any bytes previously
written that have been buffered by the connection,
should immediately be written to their intended destination.
The flush method of ConnectionBaseAdapter
does nothing.
exception: IOException - if an I/O error occurs. |
mark | public synchronized void mark(int readlimit)(Code) | | Marks the current position in input stream for a connection.
A subsequent call to the reset method repositions this
stream at the last marked position so that subsequent reads re-read
the same bytes.
The mark method of ConnectionBaseAdapter
does nothing.
Subclasses should override this method if they support own mark/reset
functionality.
Parameters: readlimit - the maximum limit of bytes that can be read beforethe mark position becomes invalid. See Also: java.io.InputStream.reset |
markSupported | public boolean markSupported()(Code) | | Tests if input stream for a connection supports the mark and
reset methods.
The markSupported method of
ConnectionBaseAdapter returns false .
Subclasses should override this method if they support own mark/reset
functionality.
true if input stream for this connection supportsthe mark and reset methods;false otherwise. See Also: java.io.InputStream.mark(int) See Also: java.io.InputStream.reset |
openInputStream | public InputStream openInputStream() throws IOException(Code) | | Returns an input stream.
an input stream for writing bytes to this port. exception: IOException - if an I/O error occurs when creating theoutput stream. |
openOutputStream | public OutputStream openOutputStream() throws IOException(Code) | | Returns an output stream.
an output stream for writing bytes to this port. exception: IOException - if an I/O error occurs when creating theoutput stream. |
openPrim | public Connection openPrim(String name, int mode, boolean timeouts) throws IOException(Code) | | Check for required permission and open a connection to a target.
Parameters: name - URL for the connection, without thewithout the protocol part Parameters: mode - I/O access mode, see Connector Parameters: timeouts - flag to indicate that the callerwants timeout exceptions this Connection object exception: IllegalArgumentException - If a parameter is invalid. exception: ConnectionNotFoundException - If the connection cannotbe found. exception: IOException - If some other kind of I/O error occurs. |
openPrim | public Connection openPrim(String name) throws IOException(Code) | | Check for required permission and open a connection to a target.
This method can be used with permissions greater than
the current app. Assume read/write and no timeouts.
Parameters: token - security token of the calling class Parameters: name - URL for the connection, without thewithout the protocol part this Connection object exception: IllegalArgumentException - If a parameter is invalid. exception: ConnectionNotFoundException - If the connection cannotbe found. exception: IOException - If some other kind of I/O error occurs. |
readBytes | abstract protected int readBytes(byte b, int off, int len) throws IOException(Code) | | Reads up to len bytes of data from the input stream into
an array of bytes, blocks until at least one byte is available.
Parameters: b - the buffer into which the data is read. Parameters: off - the start offset in array b at which the data is written. Parameters: len - the maximum number of bytes to read. the total number of bytes read into the buffer, or-1 if there is no more data because the end ofthe stream has been reached. exception: IOException - if an I/O error occurs. |
reset | public synchronized void reset() throws IOException(Code) | | Repositions input stream for a connection to the position at the time the
mark method was last called on this input stream.
The method reset for ConnectionBaseAdapter
class does nothing and always throws an IOException .
Subclasses should override this method if they support own mark/reset
functionality.
exception: IOException - if this stream has not been marked or if themark has been invalidated. See Also: java.io.InputStream.reset See Also: java.io.InputStream.mark(int) See Also: java.io.IOException |
writeBytes | abstract protected int writeBytes(byte b, int off, int len) throws IOException(Code) | | Writes len bytes from the specified byte array
starting at offset off to this output stream.
Polling the native code is done here to allow for simple
asynchronous native code to be written. Not all implementations
work this way (they block in the native code) but the same
Java code works for both.
Parameters: b - the data. Parameters: off - the start offset in the data. Parameters: len - the number of bytes to write. number of bytes written exception: IOException - if an I/O error occurs. In particular,an IOException is thrown if the outputstream is closed. |
|
|