Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| " 2013 FRC Java API "
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.sun.squawk.io
Class ConnectionBaseAdapter

    java.lang.Object
      com.sun.squawk.io.ConnectionBase
          com.sun.squawk.io.ConnectionBaseAdapter

All Implemented Interfaces:
  Connection, InputConnection, OutputConnection, StreamConnection

Direct Known Subclasses:
  Protocol

    public abstract class ConnectionBaseAdapter

extends ConnectionBase
implements StreamConnection

Protocol classes extend this class to gain some of the common functionality needed to implement a CLDC 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[], int, int)`, which is called by `InputStream.read()`
- Provides a more efficient implementation of `OutputStream.write(byte[], int, int)`, 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 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 int` | `oStreams` Number of output streams were opened.

Constructor Summary
`ConnectionBaseAdapter()`

Method Summary
`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.
`void` | `close()` Close the connection.
`protected void` | `closeInputStream()` Called once by each child input stream.
`protected void` | `closeOutputStream()` Called once by each child output stream.
`protected abstract void` | `disconnect()` Free up the connection resources.
`protected void` | `ensureOpen()` Check if the connection is open.
`protected void` | `flush()` Forces any buffered output bytes to be written out.
`void` | `initStreamConnection(int mode)` Check the mode argument and initialize the StreamConnection.
`void` | `mark(int readlimit)` Marks the current position in input stream for a connection.
`boolean` | `markSupported()` Tests if input stream for a connection supports the `mark` and `reset` methods.
`protected void` | `notifyClosedInput()` Notify blocked Java threads waiting for an input data that all InputStream instances of the connection are closed
`protected void` | `notifyClosedOutput()` Notify blocked Java threads trying to output data that all OutputStream instances of the connection are closed
`DataInputStream` | `openDataInputStream()` Open and return a data input stream for a connection.
`DataOutputStream` | `openDataOutputStream()` Open and return a data output stream for a connection.
`InputStream` | `openInputStream()` Returns an input stream.
`OutputStream` | `openOutputStream()` Returns an output stream.
`abstract Connection` | `openPrim(String name, int mode, boolean timeouts)` Initialize the StreamConnection and return it.
`protected abstract 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.
`void` | `reset()` Repositions input stream for a connection to the position at the time the `mark` method was last called on this input stream.
`protected abstract int` | `writeBytes(byte[] b, int off, int len)` Writes `len` bytes from the specified byte array starting at offset `off` to this output stream.

Methods inherited from class com.sun.squawk.io.ConnectionBase
`open`

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### connectionOpen

    protected boolean connectionOpen

  Flag indicating if the connection is open.

### iStreams

    protected int iStreams

  Number of input streams that were opened.

### maxIStreams

    protected int maxIStreams

  Maximum number of open input streams. Set this to zero to prevent openInputStream from giving out a stream in write-only mode.

### oStreams

    protected int oStreams

  Number of output streams were opened.

### maxOStreams

    protected int maxOStreams

  Maximum number of output streams. Set this to zero to prevent openOutputStream from giving out a stream in read-only mode.

Constructor Detail

### ConnectionBaseAdapter

    public ConnectionBaseAdapter()

Method Detail

### openPrim

    public abstract Connection openPrim(String name,
                                        int mode,
                                        boolean timeouts)
                                 throws IOException

  Initialize the StreamConnection and return it.

  Parameters:
    `name` - URL for the connection, without the without the protocol part
    `mode` - I/O access mode, see `Connector`
    `timeouts` - flag to indicate that the caller wants timeout exceptions
  Returns:
    this Connection object
  Throws:
    `IllegalArgumentException` - If a parameter is invalid.
    `ConnectionNotFoundException` - If the connection cannot be found.
    `IOException` - If some other kind of I/O error occurs.

### initStreamConnection

    public void initStreamConnection(int mode)
                              throws IOException

  Check the mode argument and initialize the StreamConnection. Any permissions checks should be checked before this method is called because the TCK expects the security check to fail before the arguments are called even though the spec does not mandate it.

  Parameters:
    `mode` - I/O access mode, see `Connector`
  Throws:
    `IllegalArgumentException` - If a parameter is invalid.
    `IOException` - If some other kind of I/O error occurs.

### openInputStream

    public InputStream openInputStream()
                                throws IOException

  Returns an input stream.

  Specified by:
    `openInputStream` in interface `InputConnection`
  Overrides:
    `openInputStream` in class `ConnectionBase`
  Returns:
    an input stream for writing bytes to this port.
  Throws:
    `IOException` - if an I/O error occurs when creating the output stream.

### openDataInputStream

    public DataInputStream openDataInputStream()
                                        throws IOException

  Open and return a data input stream for a connection.

  Specified by:
    `openDataInputStream` in interface `InputConnection`
  Overrides:
    `openDataInputStream` in class `ConnectionBase`
  Returns:
    An input stream
  Throws:
    `IOException` - If an I/O error occurs

### openOutputStream

    public OutputStream openOutputStream()
                                  throws IOException

  Returns an output stream.

  Specified by:
    `openOutputStream` in interface `OutputConnection`
  Overrides:
    `openOutputStream` in class `ConnectionBase`
  Returns:
    an output stream for writing bytes to this port.
  Throws:
    `IOException` - if an I/O error occurs when creating the output stream.

### openDataOutputStream

    public DataOutputStream openDataOutputStream()
                                          throws IOException

  Open and return a data output stream for a connection.

  Specified by:
    `openDataOutputStream` in interface `OutputConnection`
  Overrides:
    `openDataOutputStream` in class `ConnectionBase`
  Returns:
    An input stream
  Throws:
    `IOException` - If an I/O error occurs

### close

    public void close()
               throws IOException

  Close the connection.

  Specified by:
    `close` in interface `Connection`
  Overrides:
    `close` in class `ConnectionBase`
  Throws:
    `IOException` - if an I/O error occurs when closing the connection.

### closeInputStream

    protected void closeInputStream()
                             throws IOException

  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.

  Throws:
    `IOException` - if the subclass throws one

### closeOutputStream

    protected void closeOutputStream()
                              throws IOException

  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.

  Throws:
    `IOException` - if the subclass throws one

### notifyClosedInput

    protected void notifyClosedInput()

  Notify blocked Java threads waiting for an input data that all InputStream instances of the connection are closed

### notifyClosedOutput

    protected void notifyClosedOutput()

  Notify blocked Java threads trying to output data that all OutputStream instances of the connection are closed

### ensureOpen

    protected void ensureOpen()
                       throws IOException

  Check if the connection is open.

  Throws:
    `IOException` - is thrown, if the stream is not open.

### disconnect

    protected abstract void disconnect()
                                throws IOException

  Free up the connection resources.

  Throws:
    `IOException` - if an I/O error occurs.

### readBytes

    protected abstract int readBytes(byte[] b,
                                     int off,
                                     int len)
                              throws IOException

  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.
    `off` - the start offset in array `b` at which the data is written.
    `len` - the maximum number of bytes to read.
  Returns:
    the total number of bytes read into the buffer, or `-1` if there is no more data because the end of the stream has been reached.
  Throws:
    `IOException` - if an I/O error occurs.

### available

    public int available()
                  throws IOException

  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.

  Returns:
    the number of bytes that can be read from this input stream without blocking.
  Throws:
    `IOException` - if an I/O error occurs.

### writeBytes

    protected abstract int writeBytes(byte[] b,
                                      int off,
                                      int len)
                               throws IOException

  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.
    `off` - the start offset in the data.
    `len` - the number of bytes to write.
  Returns:
    number of bytes written
  Throws:
    `IOException` - if an I/O error occurs. In particular, an `IOException` is thrown if the output stream is closed.

### flush

    protected void flush()
                  throws IOException

  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.

  Throws:
    `IOException` - if an I/O error occurs.

### markSupported

    public boolean markSupported()

  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.

  Returns:
    `true` if input stream for this connection supports the `mark` and `reset` methods; `false` otherwise.
  See Also:
    `InputStream.mark(int)`, `InputStream.reset()`

### mark

    public void mark(int readlimit)

  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 before the mark position becomes invalid.
  See Also:
    `InputStream.reset()`

### reset

    public void reset()
               throws IOException

  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.

  Throws:
    `IOException` - if this stream has not been marked or if the mark has been invalidated.
  See Also:
    `InputStream.reset()`, `InputStream.mark(int)`, `IOException`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| " 2013 FRC Java API "
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

"
For updated information see the Java FRC site
"