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.j2me.http
Class Protocol

    java.lang.Object
      com.sun.squawk.io.ConnectionBase
          com.sun.squawk.io.j2me.http.Protocol

All Implemented Interfaces:
  Connection, ContentConnection, HttpConnection, InputConnection, OutputConnection, StreamConnection

    public class Protocol

extends ConnectionBase
implements HttpConnection

This class implements the necessary functionality for an HTTP connection.

Field Summary

Fields inherited from interface javax.microedition.io.HttpConnection
`GET, HEAD, HTTP_ACCEPTED, HTTP_BAD_GATEWAY, HTTP_BAD_METHOD, HTTP_BAD_REQUEST, HTTP_CLIENT_TIMEOUT, HTTP_CONFLICT, HTTP_CREATED, HTTP_ENTITY_TOO_LARGE, HTTP_EXPECT_FAILED, HTTP_FORBIDDEN, HTTP_GATEWAY_TIMEOUT, HTTP_GONE, HTTP_INTERNAL_ERROR, HTTP_LENGTH_REQUIRED, HTTP_MOVED_PERM, HTTP_MOVED_TEMP, HTTP_MULT_CHOICE, HTTP_NO_CONTENT, HTTP_NOT_ACCEPTABLE, HTTP_NOT_AUTHORITATIVE, HTTP_NOT_FOUND, HTTP_NOT_IMPLEMENTED, HTTP_NOT_MODIFIED, HTTP_OK, HTTP_PARTIAL, HTTP_PAYMENT_REQUIRED, HTTP_PRECON_FAILED, HTTP_PROXY_AUTH, HTTP_REQ_TOO_LONG, HTTP_RESET, HTTP_SEE_OTHER, HTTP_TEMP_REDIRECT, HTTP_UNAUTHORIZED, HTTP_UNAVAILABLE, HTTP_UNSUPPORTED_RANGE, HTTP_UNSUPPORTED_TYPE, HTTP_USE_PROXY, HTTP_VERSION, POST`

Constructor Summary
`Protocol()` Create a new instance of this class.

Method Summary
`void` | `close()` Close
`protected void` | `connect()`
`protected void` | `disconnect()`
`long` | `getDate()` Returns the value of the `date` header field.
`String` | `getEncoding()` Returns a string describing the encoding of the content which the resource connected to is providing.
`long` | `getExpiration()` Returns the value of the `expires` header field.
`String` | `getFile()` Returns the file portion of the URL of this `HttpConnection`.
`String` | `getHeaderField(int index)` Gets a header field value by index.
`String` | `getHeaderField(String name)` Returns the value of the named header field.
`long` | `getHeaderFieldDate(String name, long def)` Returns the value of the named field parsed as date.
`int` | `getHeaderFieldInt(String name, int def)` Returns the value of the named field parsed as a number.
`String` | `getHeaderFieldKey(int index)` Gets a header field key by index.
`String` | `getHost()` Returns the host information of the URL of this `HttpConnection`.
`long` | `getLastModified()` Returns the value of the `last-modified` header field.
`long` | `getLength()` Returns the length of the content which is being provided.
`int` | `getPort()` Returns the network port number of the URL for this `HttpConnection`.
`String` | `getProtocol()` Returns the protocol name of the URL of this `HttpConnection`.
`String` | `getQuery()` Returns the query portion of the URL of this `HttpConnection`.
`String` | `getRef()` Returns the ref portion of the URL of this `HttpConnection`.
`String` | `getRequestMethod()` Get the current request method.
`String` | `getRequestProperty(String key)` Returns the value of the named general request property for this connection.
`int` | `getResponseCode()` Returns the HTTP response status code.
`String` | `getResponseMessage()` Gets the HTTP response message, if any, returned along with the response code from a server.
`String` | `getType()` Returns the type of content that the resource connected to is providing.
`String` | `getURL()` Return a string representation of the URL for this connection.
`static void` | `main(String[] args)` Call using a full URL (rmeber to include the FILE part!" > squawk com.sun.squawk.io.j2me.http.Protocol http://www.yahoo.com/index.html
`Connection` | `open(String protocol, String url, int mode, boolean timeouts)` Open a connection to a target.
`InputStream` | `openInputStream()` Open and return a data input stream for a connection.
`OutputStream` | `openOutputStream()` Open and return a data output stream for a connection.
`protected void` | `parseURL()`
`void` | `setRequestMethod(String method)` Set the method for the URL request, one of: GET POST HEAD are legal, subject to protocol restrictions.
`void` | `setRequestProperty(String key, String value)` Sets the general request property.

Methods inherited from class com.sun.squawk.io.ConnectionBase
`openDataInputStream, openDataOutputStream`

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

Methods inherited from interface javax.microedition.io.InputConnection
`openDataInputStream`

Methods inherited from interface javax.microedition.io.OutputConnection
`openDataOutputStream`

Constructor Detail

### Protocol

    public Protocol()

  Create a new instance of this class. We are initially unconnected.

Method Detail

### main

    public static void main(String[] args)

  Call using a full URL (rmeber to include the FILE part!" > squawk com.sun.squawk.io.j2me.http.Protocol http://www.yahoo.com/index.html

### open

    public Connection open(String protocol,
                           String url,
                           int mode,
                           boolean timeouts)
                    throws IOException

  Description copied from class: `ConnectionBase`
  Open a connection to a target.

  Specified by:
    `open` in class `ConnectionBase`
  Parameters:
    `protocol` - The URL protocol
    `url` - 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:
    `ConnectionNotFoundException` - If the connection cannot be found.
    `IOException` - If some other kind of I/O error occurs.

### close

    public void close()
               throws IOException

  Description copied from class: `ConnectionBase`
  Close

  Specified by:
    `close` in interface `Connection`
  Overrides:
    `close` in class `ConnectionBase`
  Throws:
    `IOException` - If an I/O error occurs

### openInputStream

    public InputStream openInputStream()
                                throws IOException

  Description copied from class: `ConnectionBase`
  Open and return a data input stream for a connection.

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

### openOutputStream

    public OutputStream openOutputStream()
                                  throws IOException

  Description copied from class: `ConnectionBase`
  Open and return a data output stream for a connection.

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

### getURL

    public String getURL()

  Description copied from interface: `HttpConnection`
  Return a string representation of the URL for this connection.

  Specified by:
    `getURL` in interface `HttpConnection`
  Returns:
    the string representation of the URL for this connection.

### getProtocol

    public String getProtocol()

  Description copied from interface: `HttpConnection`
  Returns the protocol name of the URL of this `HttpConnection`. e.g., http or https

  Specified by:
    `getProtocol` in interface `HttpConnection`
  Returns:
    the protocol of the URL of this `HttpConnection`.

### getHost

    public String getHost()

  Description copied from interface: `HttpConnection`
  Returns the host information of the URL of this `HttpConnection`. e.g. host name or IPv4 address

  Specified by:
    `getHost` in interface `HttpConnection`
  Returns:
    the host information of the URL of this `HttpConnection`.

### getFile

    public String getFile()

  Description copied from interface: `HttpConnection`
  Returns the file portion of the URL of this `HttpConnection`.

  Specified by:
    `getFile` in interface `HttpConnection`
  Returns:
    the file portion of the URL of this `HttpConnection`. `null` is returned if there is no file.

### getRef

    public String getRef()

  Description copied from interface: `HttpConnection`
  Returns the ref portion of the URL of this `HttpConnection`. RFC2396 specifies the optional fragment identifier as the the text after the crosshatch (#) character in the URL. This information may be used by the user agent as additional reference information after the resource is successfully retrieved. The format and interpretation of the fragment identifier is dependent on the media type[RFC2046] of the retrieved information.

  Specified by:
    `getRef` in interface `HttpConnection`
  Returns:
    the ref portion of the URL of this `HttpConnection`. `null` is returned if there is no value.

### getQuery

    public String getQuery()

  Description copied from interface: `HttpConnection`
  Returns the query portion of the URL of this `HttpConnection`. RFC2396 defines the query component as the text after the first question-mark (?) character in the URL.

  Specified by:
    `getQuery` in interface `HttpConnection`
  Returns:
    the query portion of the URL of this `HttpConnection`. `null` is returned if there is no value.

### getPort

    public int getPort()

  Description copied from interface: `HttpConnection`
  Returns the network port number of the URL for this `HttpConnection`.

  Specified by:
    `getPort` in interface `HttpConnection`
  Returns:
    the network port number of the URL for this `HttpConnection`. The default HTTP port number (80) is returned if there was no port number in the string passed to `Connector.open`.

### getRequestMethod

    public String getRequestMethod()

  Description copied from interface: `HttpConnection`
  Get the current request method. e.g. HEAD, GET, POST The default value is GET.

  Specified by:
    `getRequestMethod` in interface `HttpConnection`
  Returns:
    the HTTP request method
  See Also:
    `HttpConnection.setRequestMethod(java.lang.String)`

### setRequestMethod

    public void setRequestMethod(String method)
                          throws IOException

  Description copied from interface: `HttpConnection`
  Set the method for the URL request, one of:
  - GET
  - POST
  - HEAD
  are legal, subject to protocol restrictions. The default method is GET.

  Specified by:
    `setRequestMethod` in interface `HttpConnection`
  Parameters:
    `method` - the HTTP method
  Throws:
    `IOException` - if the method cannot be reset or if the requested method isn't valid for HTTP.
  See Also:
    `HttpConnection.getRequestMethod()`

### getRequestProperty

    public String getRequestProperty(String key)

  Description copied from interface: `HttpConnection`
  Returns the value of the named general request property for this connection.

  Specified by:
    `getRequestProperty` in interface `HttpConnection`
  Parameters:
    `key` - the keyword by which the request property is known (e.g., "accept").
  Returns:
    the value of the named general request property for this connection. If there is no key with the specified name then `null` is returned.
  See Also:
    `HttpConnection.setRequestProperty(java.lang.String, java.lang.String)`

### setRequestProperty

    public void setRequestProperty(String key,
                                   String value)
                            throws IOException

  Description copied from interface: `HttpConnection`
  Sets the general request property. If a property with the key already exists, overwrite its value with the new value.

  Note: HTTP requires all request properties which can legally have multiple instances with the same key to use a comma-separated list syntax which enables multiple properties to be appended into a single property.

  Specified by:
    `setRequestProperty` in interface `HttpConnection`
  Parameters:
    `key` - the keyword by which the request is known (e.g., "`accept`").
    `value` - the value associated with it.
  Throws:
    `IOException` - is thrown if the connection is in the connected state.
  See Also:
    `HttpConnection.getRequestProperty(java.lang.String)`

### getResponseCode

    public int getResponseCode()
                        throws IOException

  Description copied from interface: `HttpConnection`
  Returns the HTTP response status code. It parses responses like:

       HTTP/1.0 200 OK
       HTTP/1.0 401 Unauthorized

  and extracts the ints 200 and 401 respectively. from the response (i.e., the response is not valid HTTP).

  Specified by:
    `getResponseCode` in interface `HttpConnection`
  Returns:
    the HTTP Status-Code or -1 if no status code can be discerned.
  Throws:
    `IOException` - if an error occurred connecting to the server.

### getResponseMessage

    public String getResponseMessage()
                              throws IOException

  Description copied from interface: `HttpConnection`
  Gets the HTTP response message, if any, returned along with the response code from a server. From responses like:

       HTTP/1.0 200 OK
       HTTP/1.0 404 Not Found

  Extracts the Strings "OK" and "Not Found" respectively. Returns null if none could be discerned from the responses (the result was not valid HTTP).

  Specified by:
    `getResponseMessage` in interface `HttpConnection`
  Returns:
    the HTTP response message, or `null`
  Throws:
    `IOException` - if an error occurred connecting to the server.

### getLength

    public long getLength()

  Description copied from interface: `ContentConnection`
  Returns the length of the content which is being provided. E.g. if the connection is via HTTP, then the value of the `content-length` header field is returned.

  Specified by:
    `getLength` in interface `ContentConnection`
  Returns:
    the content length of the resource that this connection's URL references, or `-1` if the content length is not known.

### getType

    public String getType()

  Description copied from interface: `ContentConnection`
  Returns the type of content that the resource connected to is providing. For instance, if the connection is via HTTP, then the value of the `content-type` header field is returned.

  Specified by:
    `getType` in interface `ContentConnection`
  Returns:
    the content type of the resource that the URL references, or `null` if not known.

### getEncoding

    public String getEncoding()

  Description copied from interface: `ContentConnection`
  Returns a string describing the encoding of the content which the resource connected to is providing. E.g. if the connection is via HTTP, the value of the `content-encoding` header field is returned.

  Specified by:
    `getEncoding` in interface `ContentConnection`
  Returns:
    the content encoding of the resource that the URL references, or `null` if not known.

### getExpiration

    public long getExpiration()

  Description copied from interface: `HttpConnection`
  Returns the value of the `expires` header field.

  Specified by:
    `getExpiration` in interface `HttpConnection`
  Returns:
    the expiration date of the resource that this URL references, or 0 if not known. The value is the number of milliseconds since January 1, 1970 GMT.

### getDate

    public long getDate()

  Description copied from interface: `HttpConnection`
  Returns the value of the `date` header field.

  Specified by:
    `getDate` in interface `HttpConnection`
  Returns:
    the sending date of the resource that the URL references, or `0` if not known. The value returned is the number of milliseconds since January 1, 1970 GMT.

### getLastModified

    public long getLastModified()

  Description copied from interface: `HttpConnection`
  Returns the value of the `last-modified` header field. The result is the number of milliseconds since January 1, 1970 GMT.

  Specified by:
    `getLastModified` in interface `HttpConnection`
  Returns:
    the date the resource referenced by this `HttpConnection` was last modified, or 0 if not known.

### getHeaderField

    public String getHeaderField(String name)

  Description copied from interface: `HttpConnection`
  Returns the value of the named header field.

  Specified by:
    `getHeaderField` in interface `HttpConnection`
  Parameters:
    `name` - of a header field.
  Returns:
    the value of the named header field, or `null` if there is no such field in the header.

### getHeaderField

    public String getHeaderField(int index)

  Description copied from interface: `HttpConnection`
  Gets a header field value by index.

  Specified by:
    `getHeaderField` in interface `HttpConnection`
  Parameters:
    `index` - the index of the header field
  Returns:
    the value of the nth header field or `null` if the array index is out of range. An empty String is returned if the field does not have a value.

### getHeaderFieldKey

    public String getHeaderFieldKey(int index)

  Description copied from interface: `HttpConnection`
  Gets a header field key by index.

  Specified by:
    `getHeaderFieldKey` in interface `HttpConnection`
  Parameters:
    `index` - the index of the header field
  Returns:
    the key of the nth header field or `null` if the array index is out of range.

### getHeaderFieldInt

    public int getHeaderFieldInt(String name,
                                 int def)

  Description copied from interface: `HttpConnection`
  Returns the value of the named field parsed as a number.

  This form of `getHeaderField` exists because some connection types (e.g., `http-ng`) have pre-parsed headers. Classes for that connection type can override this method and short-circuit the parsing.

  Specified by:
    `getHeaderFieldInt` in interface `HttpConnection`
  Parameters:
    `name` - the name of the header field.
    `def` - the default value.
  Returns:
    the value of the named field, parsed as an integer. The `def` value is returned if the field is missing or malformed.

### getHeaderFieldDate

    public long getHeaderFieldDate(String name,
                                   long def)

  Description copied from interface: `HttpConnection`
  Returns the value of the named field parsed as date. The result is the number of milliseconds since January 1, 1970 GMT represented by the named field.

  This form of `getHeaderField` exists because some connection types (e.g., `http-ng`) have pre-parsed headers. Classes for that connection type can override this method and short-circuit the parsing.

  Specified by:
    `getHeaderFieldDate` in interface `HttpConnection`
  Parameters:
    `name` - the name of the header field.
    `def` - a default value.
  Returns:
    the value of the field, parsed as a date. The value of the `def` argument is returned if the field is missing or malformed.

### connect

    protected void connect()
                    throws IOException

  Throws:
    `IOException`

### disconnect

    protected void disconnect()
                       throws IOException

  Throws:
    `IOException`

### parseURL

    protected void parseURL()
                     throws IOException

  Throws:
    `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
"