|
" 2013 FRC Java API " |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.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 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 |
---|
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 ConnectionBase
protocol
- 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 Connection
close
in class ConnectionBase
IOException
- If an I/O error occurspublic InputStream openInputStream() throws IOException
ConnectionBase
openInputStream
in interface InputConnection
openInputStream
in class ConnectionBase
IOException
- If an I/O error occurspublic OutputStream openOutputStream() throws IOException
ConnectionBase
openOutputStream
in interface OutputConnection
openOutputStream
in class ConnectionBase
IOException
- If an I/O error occurspublic String getURL()
HttpConnection
getURL
in interface HttpConnection
public String getProtocol()
HttpConnection
HttpConnection
. e.g., http or https
getProtocol
in interface HttpConnection
HttpConnection
.public String getHost()
HttpConnection
HttpConnection
. e.g. host name or IPv4 address
getHost
in interface HttpConnection
HttpConnection
.public String getFile()
HttpConnection
HttpConnection
.
getFile
in interface HttpConnection
HttpConnection
.
null
is returned if there is no file.public String getRef()
HttpConnection
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.
getRef
in interface HttpConnection
HttpConnection
.
null
is returned if there is no value.public String getQuery()
HttpConnection
HttpConnection
.
RFC2396 defines the query component as the text after the first
question-mark (?) character in the URL.
getQuery
in interface HttpConnection
HttpConnection
.
null
is returned if there is no value.public int getPort()
HttpConnection
HttpConnection
.
getPort
in interface HttpConnection
HttpConnection
.
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 HttpConnection
HttpConnection.setRequestMethod(java.lang.String)
public void setRequestMethod(String method) throws IOException
HttpConnection
setRequestMethod
in interface HttpConnection
method
- 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 HttpConnection
key
- 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
HttpConnection
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.
setRequestProperty
in interface HttpConnection
key
- 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
HttpConnection
HTTP/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 HttpConnection
IOException
- if an error occurred connecting to the server.public String getResponseMessage() throws IOException
HttpConnection
HTTP/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 HttpConnection
null
IOException
- if an error occurred connecting to the server.public long getLength()
ContentConnection
content-length
header field is returned.
getLength
in interface ContentConnection
-1
if the content length
is not known.public String getType()
ContentConnection
content-type
header field is returned.
getType
in interface ContentConnection
null
if not known.public String getEncoding()
ContentConnection
content-encoding
header field is returned.
getEncoding
in interface ContentConnection
null
if not known.public long getExpiration()
HttpConnection
expires
header field.
getExpiration
in interface HttpConnection
public long getDate()
HttpConnection
date
header field.
getDate
in interface HttpConnection
0
if not known. The value returned is the
number of milliseconds since January 1, 1970 GMT.public long getLastModified()
HttpConnection
last-modified
header field.
The result is the number of milliseconds since January 1, 1970 GMT.
getLastModified
in interface HttpConnection
HttpConnection
was last modified, or
0 if not known.public String getHeaderField(String name)
HttpConnection
getHeaderField
in interface HttpConnection
name
- of a header field.
null
if there is no such field in the header.public String getHeaderField(int index)
HttpConnection
getHeaderField
in interface HttpConnection
index
- 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 HttpConnection
index
- 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 HttpConnection
name
- 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 HttpConnection
name
- 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 |