DCT Lightfoot v3 API specification

com.dctl.j2me.io.http
Class Connection

java.lang.Object
  |
  +--com.dctl.j2me.io.BaseConnection
        |
        +--com.dctl.j2me.io.http.BaseHttpConnection
              |
              +--com.dctl.j2me.io.http.Connection
All Implemented Interfaces:
Connection, ContentConnection, HttpConnection, InputConnection, OutputConnection, StreamConnection

public class Connection
extends BaseHttpConnection
implements HttpConnection

An http connection allows information to be retrieved from a web server. Connections are created by using the Connector open method. e.g. Connector.open("http://www.javasoft.com/index.html");


Field Summary
 
Fields inherited from class com.dctl.j2me.io.http.BaseHttpConnection
ACCEPT_PROPERTY, ACCEPT_VALUE, ASCTIME, CHUNKED_ENCODING, CLOSED, COLON_SPACE, COMMA, CONNECTION_CLOSE, CONNECTION_KEEP_ALIVE, CONNECTION_PROPERTY, CONTENT_ENCODING_PROPERTY, CONTENT_LENGTH_PROPERTY, CONTENT_TYPE_PROPERTY, CRLF, DASH, DATE_PROPERTY, DAY, EXPIRES_PROPERTY, FIELDS, handle, HOST_PROPERTY, HOUR, inputNames, inputProperties, is, LAST_MODIFIED_PROPERTY, method, MIN, MONTH, MONTH_STRING, opens, os, outputProperties, PROTOCOL, RECEIVING, responseCode, responseMessage, RFC1123, RFC850, SEC, SENDING, SETUP, SPACE, state, TRANSFER_ENCODING_PROPERTY, USER_AGENT_PROPERTY, USER_AGENT_VALUE, VERSION, YEAR
 
Fields inherited from class com.dctl.j2me.io.BaseConnection
protocol
 
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, PUT
 
Constructor Summary
Connection()
          Default constructor
Connection(int address, int port)
          Constructor taking an address and port
 
Method Summary
 boolean equals(Object obj)
          Equals method
protected  java.lang.String generateFirstOutput()
          Generate the first output line
 long getDate()
          Get the date header field
 java.lang.String getEncoding()
          Get the encoding
 long getExpiration()
          Get the expires header field
 java.lang.String getHeaderField(int index)
          Get a header field indexed by the index
 java.lang.String getHeaderField(java.lang.String name)
          Get the header field
 long getHeaderFieldDate(java.lang.String name, long defaultValue)
          Get a header field parsed as a date value
 int getHeaderFieldInt(java.lang.String name, int defaultValue)
          Get a header field parsed as a number
 java.lang.String getHeaderFieldKey(int index)
          Get the header field key at the index
 long getLastModified()
          Get the last modified date
 long getLength()
          Get the length
 java.lang.String getRequestProperty(java.lang.String key)
          Get the request property specified by the key
 int getResponseCode()
          Get the response code
 java.lang.String getResponseMessage()
          Get the response message
 java.lang.String getType()
          Get the type
protected  boolean handleFirstInput(java.lang.String line)
          handle the first input line
 int hashcode()
          Hashcode method
protected  void openConnection()
          Open the connection using the values in address, port and parameters
 InputStream openInputStream()
          Open an input stream
 OutputStream openOutputStream()
          Open an output stream if it was not already open.
protected  void parseResponse()
          Parse the response
 void recycle()
          Recycle the connection
 void setParameters(java.lang.String url, int mode, boolean timeouts)
          Set the URL, mode and timeouts
 void setProtocol(ProtocolString protocol)
          Set the protocol
 void setRequestMethod(java.lang.String method)
          Set the request method - only valid until the request has been got
 void setRequestProperty(java.lang.String key, java.lang.String value)
          Set the request property for the key.
 
Methods inherited from class com.dctl.j2me.io.http.BaseHttpConnection
close, getFieldDate, getFieldInt, getFile, getHost, getInputFieldKey, getPort, getProtocol, getQuery, getRef, getRequestMethod, getURL, invalidState, openDataInputStream, openDataOutputStream, parseInput, sendOutput
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.microedition.io.HttpConnection
getFile, getHost, getPort, getProtocol, getQuery, getRef, getRequestMethod, getURL
 
Methods inherited from interface javax.microedition.io.InputConnection
openDataInputStream
 
Methods inherited from interface javax.microedition.io.Connection
close
 
Methods inherited from interface javax.microedition.io.OutputConnection
openDataOutputStream
 

Constructor Detail

Connection

public Connection()
Default constructor


Connection

public Connection(int address,
                  int port)
Constructor taking an address and port

Parameters:
address - The address to connect to
port - The port to connect to
Method Detail

openConnection

protected void openConnection()
                       throws IOException
Open the connection using the values in address, port and parameters

Specified by:
openConnection in class BaseHttpConnection
Throws:
IOException - if there is an error or two connections already exist to the given internet host address.

hashcode

public int hashcode()
Hashcode method

Returns:
the hash value

equals

public boolean equals(Object obj)
Equals method

Overrides:
equals in class Object
Parameters:
obj - The other
Returns:
true if they are equivalent, which means the destination port and address are the same

recycle

public void recycle()
Recycle the connection

Overrides:
recycle in class BaseHttpConnection

setProtocol

public void setProtocol(ProtocolString protocol)
Set the protocol

Parameters:
protocol - The protocol

setParameters

public void setParameters(java.lang.String url,
                          int mode,
                          boolean timeouts)
                   throws IOException
Set the URL, mode and timeouts

Specified by:
setParameters in class BaseConnection
Parameters:
url - The URL passed to connector.open
mode - The mode passed to connector.open or DEFAULT
timeouts - true if timeout exceptions should occur
Throws:
IOException - if there is a problem

setRequestMethod

public void setRequestMethod(java.lang.String method)
                      throws IOException
Set the request method - only valid until the request has been got

Specified by:
setRequestMethod in interface HttpConnection
Overrides:
setRequestMethod in class BaseHttpConnection
Parameters:
method - The request method
Throws:
IOException - if the request has already been sent or the method is not valid

generateFirstOutput

protected final java.lang.String generateFirstOutput()
Generate the first output line

Specified by:
generateFirstOutput in class BaseHttpConnection
Returns:
the line

parseResponse

protected final void parseResponse()
                            throws IOException
Parse the response

Throws:
IOException - if there is an error

handleFirstInput

protected boolean handleFirstInput(java.lang.String line)
                            throws IOException
handle the first input line

Specified by:
handleFirstInput in class BaseHttpConnection
Parameters:
line - The first input line
Returns:
true if the line parsed ok, false if another line is requried
Throws:
IOException - if the line is incorrect

setRequestProperty

public void setRequestProperty(java.lang.String key,
                               java.lang.String value)
                        throws IOException
Set the request property for the key.

Specified by:
setRequestProperty in interface HttpConnection
Parameters:
key - The key
value - The value
Throws:
IOException - if the state is wrong

getRequestProperty

public java.lang.String getRequestProperty(java.lang.String key)
Get the request property specified by the key

Specified by:
getRequestProperty in interface HttpConnection
Parameters:
key - The request property to get
Returns:
the property

getResponseCode

public int getResponseCode()
                    throws IOException
Get the response code

Specified by:
getResponseCode in interface HttpConnection
Returns:
the response code (ie. 200, 400 ...)
Throws:
IOException - if there is an error

getResponseMessage

public java.lang.String getResponseMessage()
                                    throws IOException
Get the response message

Specified by:
getResponseMessage in interface HttpConnection
Returns:
the response message (ie Not found)
Throws:
IOException - if there is an error

getExpiration

public long getExpiration()
                   throws IOException
Get the expires header field

Specified by:
getExpiration in interface HttpConnection
Returns:
the value of the expires header field or 0
Throws:
IOException - if there is an error

getDate

public long getDate()
             throws IOException
Get the date header field

Specified by:
getDate in interface HttpConnection
Returns:
the value of the date header field or 0
Throws:
IOException - if there is an error

getLastModified

public long getLastModified()
                     throws IOException
Get the last modified date

Specified by:
getLastModified in interface HttpConnection
Returns:
the last modified or 0
Throws:
IOException - if there is an error

getHeaderField

public java.lang.String getHeaderField(java.lang.String name)
                                throws IOException
Get the header field

Specified by:
getHeaderField in interface HttpConnection
Parameters:
name - The name of the header field
Returns:
the value or null
Throws:
IOException - if there is an error

getType

public java.lang.String getType()
Get the type

Specified by:
getType in interface ContentConnection
Returns:
the value of the Content-Type field

getEncoding

public java.lang.String getEncoding()
Get the encoding

Specified by:
getEncoding in interface ContentConnection
Returns:
the value of the Content-Encoding field

getLength

public long getLength()
Get the length

Specified by:
getLength in interface ContentConnection
Returns:
the value of the Content-Length field

getHeaderFieldInt

public int getHeaderFieldInt(java.lang.String name,
                             int defaultValue)
                      throws IOException
Get a header field parsed as a number

Specified by:
getHeaderFieldInt in interface HttpConnection
Parameters:
name - The name of the field
defaultValue - The default value to use if the field cannot be parsed or if it does not exist
Returns:
the value of the field or the default value if it cannot be parsed
Throws:
IOException - if there is an error

getHeaderFieldDate

public long getHeaderFieldDate(java.lang.String name,
                               long defaultValue)
                        throws IOException
Get a header field parsed as a date value

Specified by:
getHeaderFieldDate in interface HttpConnection
Parameters:
name - Thename of the field
defaultValue - The default value to use if the field cannot be parsed or if it does not exist
Returns:
the value of the field or the default value if it cannot be parsed
Throws:
IOException - if there is an error

getHeaderField

public java.lang.String getHeaderField(int index)
                                throws IOException
Get a header field indexed by the index

Specified by:
getHeaderField in interface HttpConnection
Parameters:
index - The index
Returns:
the header field at the index or null if it is out of range
Throws:
IOException - if there is an error

getHeaderFieldKey

public java.lang.String getHeaderFieldKey(int index)
                                   throws IOException
Get the header field key at the index

Specified by:
getHeaderFieldKey in interface HttpConnection
Parameters:
index - the index
Returns:
the header field name at the index or null if it is out of range
Throws:
IOException - if there is an error

openInputStream

public InputStream openInputStream()
                            throws IOException
Open an input stream

Specified by:
openInputStream in interface InputConnection
Overrides:
openInputStream in class BaseHttpConnection
Returns:
the input stream
Throws:
IOException - if there is an error

openOutputStream

public OutputStream openOutputStream()
                              throws IOException
Open an output stream if it was not already open.

Specified by:
openOutputStream in interface OutputConnection
Overrides:
openOutputStream in class BaseHttpConnection
Returns:
the output stream
Throws:
IOException - if there is an error

DCT Lightfoot v3 API specification

DCT Lightfoot v3 API specification