Slide 5.7: Fetching a page using an HttpConnection
  Slide 6.1: Palm OS
  Home


Fetching a Page Using an HttpConnection (Cont.)


HttpConnection c = null;
The interface javax.microedition.io.HttpConnection defines the necessary methods and constants for an HTTP connection. HTTP is a request-response protocol in which the parameters of request must be set before the request is sent. The connection exists in one of the three states: Setup, Connected, and Closed.

len = c.getLength( );
while ( (ch = is.read( )) != -1 ) {
The method public abstract int java.io.InputStream.read( ) reads the next byte of data from the input stream. The value byte is returned as an integer in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

b.append( (char) ch );
The method public StringBuffer java.lang.StringBuffer.append(char c) appends the string representation of the char argument to this string buffer. The length of this string buffer increases by 1.

len = is.available( );
The method public int java.io.InputStream.available( ) returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream.