| 
 | " 2013 FRC Java API" | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.squawk.io.ConnectionBase
com.sun.squawk.io.j2me.http.Protocol
public class Protocol
This class implements the necessary functionality for an HTTP connection.
| Field Summary | 
|---|
| 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 dateheader 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 expiresheader 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-modifiedheader 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 | 
|---|
public Protocol()
| Method Detail | 
|---|
public static void main(String[] args)
public Connection open(String protocol,
                       String url,
                       int mode,
                       boolean timeouts)
                throws IOException
ConnectionBase
open in class ConnectionBaseprotocol - The URL protocolurl - The URL for the connectionmode - The access modetimeouts - A flag to indicate that the caller
                         wants timeout exceptions
ConnectionNotFoundException - If the connection cannot
                                        be found.
IOException - If some other kind of I/O error occurs.
public void close()
           throws IOException
ConnectionBase
close in interface Connectionclose in class ConnectionBaseIOException - If an I/O error occurs
public InputStream openInputStream()
                            throws IOException
ConnectionBase
openInputStream in interface InputConnectionopenInputStream in class ConnectionBaseIOException - If an I/O error occurs
public OutputStream openOutputStream()
                              throws IOException
ConnectionBase
openOutputStream in interface OutputConnectionopenOutputStream in class ConnectionBaseIOException - If an I/O error occurspublic String getURL()
HttpConnection
getURL in interface HttpConnectionpublic String getProtocol()
HttpConnectionHttpConnection. e.g., http or https
getProtocol in interface HttpConnectionHttpConnection.public String getHost()
HttpConnectionHttpConnection. e.g. host name or IPv4 address
getHost in interface HttpConnectionHttpConnection.public String getFile()
HttpConnectionHttpConnection.
getFile in interface HttpConnectionHttpConnection.
 null is returned if there is no file.public String getRef()
HttpConnectionHttpConnection.
 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.
getRef in interface HttpConnectionHttpConnection.
 null is returned if there is no value.public String getQuery()
HttpConnectionHttpConnection.
 RFC2396 defines the query component as the text after the first
 question-mark (?)  character in the URL.
getQuery in interface HttpConnectionHttpConnection.
 null is returned if there is no value.public int getPort()
HttpConnectionHttpConnection.
getPort in interface HttpConnectionHttpConnection.
 The default HTTP port number (80) is returned if there was
 no port number in the string passed to Connector.open.public String getRequestMethod()
HttpConnection
getRequestMethod in interface HttpConnectionHttpConnection.setRequestMethod(java.lang.String)
public void setRequestMethod(String method)
                      throws IOException
HttpConnection
setRequestMethod in interface HttpConnectionmethod - the HTTP method
IOException - if the method cannot be reset or if
              the requested method isn't valid for HTTP.HttpConnection.getRequestMethod()public String getRequestProperty(String key)
HttpConnection
getRequestProperty in interface HttpConnectionkey - the keyword by which the request property is
  known (e.g., "accept").
null is returned.HttpConnection.setRequestProperty(java.lang.String, java.lang.String)
public void setRequestProperty(String key,
                               String value)
                        throws IOException
HttpConnectionNote: 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.
setRequestProperty in interface HttpConnectionkey - the keyword by which the request is known
                  (e.g., "accept").value - the value associated with it.
IOException - is thrown if the connection is in the
  connected state.HttpConnection.getRequestProperty(java.lang.String)
public int getResponseCode()
                    throws IOException
HttpConnectionHTTP/1.0 200 OK HTTP/1.0 401 Unauthorizedand extracts the ints 200 and 401 respectively. from the response (i.e., the response is not valid HTTP).
getResponseCode in interface HttpConnectionIOException - if an error occurred connecting to the server.
public String getResponseMessage()
                          throws IOException
HttpConnectionHTTP/1.0 200 OK HTTP/1.0 404 Not FoundExtracts the Strings "OK" and "Not Found" respectively. Returns null if none could be discerned from the responses (the result was not valid HTTP).
getResponseMessage in interface HttpConnectionnull
IOException - if an error occurred connecting to the server.public long getLength()
ContentConnectioncontent-length header field is returned.
getLength in interface ContentConnection-1 if the content length
          is not known.public String getType()
ContentConnectioncontent-type header field is returned.
getType in interface ContentConnectionnull if not known.public String getEncoding()
ContentConnectioncontent-encoding header field is returned.
getEncoding in interface ContentConnectionnull if not known.public long getExpiration()
HttpConnectionexpires header field.
getExpiration in interface HttpConnectionpublic long getDate()
HttpConnectiondate header field.
getDate in interface HttpConnection0 if not known. The value returned is the
          number of milliseconds since January 1, 1970 GMT.public long getLastModified()
HttpConnectionlast-modified header field.
 The result is the number of milliseconds since January 1, 1970 GMT.
getLastModified in interface HttpConnectionHttpConnection was last modified, or
  0 if not known.public String getHeaderField(String name)
HttpConnection
getHeaderField in interface HttpConnectionname - of a header field.
null
          if there is no such field in the header.public String getHeaderField(int index)
HttpConnection
getHeaderField in interface HttpConnectionindex - the index of the header field
null if the array index is out of range.
 An empty String is returned if the field does not have a value.public String getHeaderFieldKey(int index)
HttpConnection
getHeaderFieldKey in interface HttpConnectionindex - the index of the header field
null if the array index is out of range.
public int getHeaderFieldInt(String name,
                             int def)
HttpConnection
 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.
getHeaderFieldInt in interface HttpConnectionname - the name of the header field.def - the default value.
def value is returned if the field is
          missing or malformed.
public long getHeaderFieldDate(String name,
                               long def)
HttpConnection
 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.
getHeaderFieldDate in interface HttpConnectionname - the name of the header field.def - a default value.
def argument is returned if the field is
          missing or malformed.
protected void connect()
                throws IOException
IOException
protected void disconnect()
                   throws IOException
IOException
protected void parseURL()
                 throws IOException
IOException| 
 | " 2013 FRC Java API" | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||