WMA - JSR120

javax.microedition.io
Class Connector

java.lang.Object
  |
  +--javax.microedition.io.Connector

public class Connector
extends java.lang.Object

This class is factory for creating new Connection objects.

The creation of connections is performed dynamically by looking up a protocol implementation class whose name is formed from the platform name (read from a system property) and the protocol name of the requested connection (extracted from the parameter string supplied by the application programmer). The parameter string that describes the target should conform to the URL format as described in RFC 2396. This takes the general form:

{scheme}:[{target}][{parms}]

where:

An optional second parameter may be specified to the open function. This is a mode flag that indicates to the protocol handler the intentions of the calling code. The options here specify if the connection is going to be read (READ), written (WRITE), or both (READ_WRITE). The validity of these flag settings is protocol dependent. For example, a connection for a printer would not allow read access, and would throw an IllegalArgumentException. If the mode parameter is not specified, READ_WRITE is used by default.

An optional third parameter is a boolean flag that indicates if the calling code can handle timeout exceptions. If this flag is set, the protocol implementation may throw an InterruptedIOException when it detects a timeout condition. This flag is only a hint to the protocol handler, and it does not guarantee that such exceptions will actually be thrown. If this parameter is not set, no timeout exceptions will be thrown.

Because connections are frequently opened just to gain access to a specific input or output stream, convenience functions are provided for this purpose. See also: DatagramConnection for information relating to datagram addressing

Since:
CLDC 1.0

Field Summary
static int READ
          Access mode READ.
static int READ_WRITE
          Access mode READ_WRITE.
static int WRITE
          Access mode WRITE.
 
Method Summary
static Connection open(java.lang.String name)
          Creates and opens a Connection.
static Connection open(java.lang.String name, int mode)
          Creates and opens a Connection.
static Connection open(java.lang.String name, int mode, boolean timeouts)
          Creates and opens a Connection.
static java.io.DataInputStream openDataInputStream(java.lang.String name)
          Creates and opens a connection input stream.
static java.io.DataOutputStream openDataOutputStream(java.lang.String name)
          Creates and opens a connection output stream.
static java.io.InputStream openInputStream(java.lang.String name)
          Creates and opens a connection input stream.
static java.io.OutputStream openOutputStream(java.lang.String name)
          Creates and opens a connection output stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

READ

public static final int READ
Access mode READ.

WRITE

public static final int WRITE
Access mode WRITE.

READ_WRITE

public static final int READ_WRITE
Access mode READ_WRITE.
Method Detail

open

public static Connection open(java.lang.String name)
                       throws java.io.IOException
Creates and opens a Connection.
Parameters:
name - the URL for the connection
Returns:
a new Connection object
Throws:
java.lang.IllegalArgumentException - if a parameter is invalid
ConnectionNotFoundException - if the requested connection cannot be made, or the protocol type does not exist
java.io.IOException - if some other kind of I/O error occurs
java.lang.SecurityException - if a requested protocol handler is not permitted

open

public static Connection open(java.lang.String name,
                              int mode)
                       throws java.io.IOException
Creates and opens a Connection.
Parameters:
name - the URL for the connection
mode - the access mode
Returns:
a new Connection object
Throws:
java.lang.IllegalArgumentException - if a parameter is invalid
ConnectionNotFoundException - if the requested connection cannot be made, or the protocol type does not exist
java.io.IOException - if some other kind of I/O error occurs
java.lang.SecurityException - if a requested protocol handler is not permitted

open

public static Connection open(java.lang.String name,
                              int mode,
                              boolean timeouts)
                       throws java.io.IOException
Creates and opens a Connection.
Parameters:
name - the URL for the connection
mode - the access mode
timeouts - a flag to indicate that the caller wants timeout exceptions
Returns:
a new Connection object
Throws:
java.lang.IllegalArgumentException - if a parameter is invalid
ConnectionNotFoundException - if the requested connection cannot be made, or the protocol type does not exist
java.io.IOException - if some other kind of I/O error occurs
java.lang.SecurityException - if a requested protocol handler is not permitted

openDataInputStream

public static java.io.DataInputStream openDataInputStream(java.lang.String name)
                                                   throws java.io.IOException
Creates and opens a connection input stream.
Parameters:
name - the URL for the connection
Returns:
a DataInputStream
Throws:
java.lang.IllegalArgumentException - if a parameter is invalid
ConnectionNotFoundException - if the connection cannot be found
java.io.IOException - if some other kind of I/O error occurs
java.lang.SecurityException - if access to the requested stream is not permitted

openDataOutputStream

public static java.io.DataOutputStream openDataOutputStream(java.lang.String name)
                                                     throws java.io.IOException
Creates and opens a connection output stream.
Parameters:
name - the URL for the connection
Returns:
a DataOutputStream
Throws:
java.lang.IllegalArgumentException - if a parameter is invalid
ConnectionNotFoundException - if the connection cannot be found
java.io.IOException - if some other kind of I/O error occurs
java.lang.SecurityException - if access to the requested stream is not permitted

openInputStream

public static java.io.InputStream openInputStream(java.lang.String name)
                                           throws java.io.IOException
Creates and opens a connection input stream.
Parameters:
name - the URL for the connection
Returns:
an InputStream
Throws:
java.lang.IllegalArgumentException - if a parameter is invalid
ConnectionNotFoundException - if the connection cannot be found
java.io.IOException - if some other kind of I/O error occurs
java.lang.SecurityException - if access to the requested stream is not permitted

openOutputStream

public static java.io.OutputStream openOutputStream(java.lang.String name)
                                             throws java.io.IOException
Creates and opens a connection output stream.
Parameters:
name - the URL for the connection
Returns:
an OutputStream
Throws:
java.lang.IllegalArgumentException - if a parameter is invalid
ConnectionNotFoundException - if the connection cannot be found
java.io.IOException - if some other kind of I/O error occurs
java.lang.SecurityException - if access to the requested stream is not permitted

WMA - JSR120

Submit a comment or suggestion Version 1.0 of WMA Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries. Copyright 1993-2002 Sun Microsystems, Inc. 901 San Antonio Road,Palo Alto, California, 94303, U.S.A. All Rights Reserved.