Smart CODE
Your on-line guide to the generated code

URLs

INTRODUCTION

The C and C++ URL software is intended for thin-client interfaces and applications that need access to Internet resources. It has been modelled on the Java(TM) URL and URLConnection classes, to facilitate the transition to Java, and to maintain a common API across all targets.

Note that the C and C++ implementations are sufficient for their purpose, and anything written to these interfaces should transfer easily to Java. They are not full implementations of the Java API, and are not intended for recoding Java applications in C.

Overview of Language Differences
LanguageUsageComments
Java

     import java.io.*;
     import java.net.*;

     void mymethod( String myurl)
     {
	URL u             = new URL(myurl);
	InputStream i     = u.openStream();
	DataInputStream d = new DataInputStream( i);
		// process the data
     }

C++

     #include "URL.h"

     void
     myclass::mymethod( char * myurl)
     {
	URL * u = new URL( myurl);
	InputStream * i = u->openStream();
	DataInputStream * d = new DataInputStream( i);
		// process the data
	delete d;
	delete u;
     }
  • The objects are pointers
    (URL * u and u->openStream())
  • They must be deleted. They are NOT garbage collected.
  • C
    
         #include "URL.h"
    
         void
         myfunction( char * myurl)
         {
    	URL * u = newURL( myurl);
    	InputStream * i = (*u->openStream)( u);
    	DataInputStream * d = newDataInputStream(i);
    		/* process the data */
    	(*d->delete)( d);
    	(*u->delete)( u);
         }
  • The objects are pointers
    (URL * u)
  • Constructors are functions of the form newType()
  • Public methods are function pointers in the object. The object itself MUST be the first argument of the call,eg
    (*d->delete)( d);
  • They must be deleted. They are NOT garbage collected.
  • A similar example for Input and OUtput streams shows how the data might be processed inthe above example.

    SYNOPSIS

    The following classes (and C objects) are available. parentheses indicate that the class or object is a private implementation structure, that may not conform to any public API.
    URL
    URLConnectionabstract

    (SocketURLConnection)abstract


    HttpURLConnection

    FileURLConnection

    (URLSocket)
    (HttpHeader)
    (ProxyNameList)

    DESCRIPTION

    FileURLConnection

    FileURLConnection implements the abstract URLConnection for File I/O. the URLConnection* object is accessed through the URL interface.

    Internal: HttpHeader

    HttpHeader is an internal object that parses the header information returned from a web server.

    HttpURLConnection

    HttpURLConnection implements the abstract URLConnection for HTTP I/O. the URLConnection* object is accessed through the URL interface.

    Internal: ProxyNameList

    ProxyNameList is an internal object that manages the use of proxies, and hosts that are connected directly.

    Internal: SocketURLConnection (abstract)

    SocketURLConnection is an abstract class used by HttpURLConnection.

    URL

    URL is the class you should use to establish and manage connections to the URL resources either as files locally, or through web servers on the Internet.

    Constructor/s
    C++

    C

    Public Methods
  • URLConnection* openConnection();
  • URLConnection* getConnection();
    Gets the current URLConnection
    C version: getConnection(URL*)
  • InputStream* openStream();
    for simple URL access, you can simply open the stream and get a handle on the returning data. If you are posting data or need finer control, you need to access the URLConnection directly.
    C version: openStream(URL*)
  • InputData* getContent();
    this is an extra public method. It is not available in the Java API. It allows you to retrieve the data from the URL as data and size of data, bypassing even the InputStream.
    C version: getContent(URL*)
  • URLConnection (abstract)

    URLConnection is the abstract class that defines the interfaces for the public methods for accessing and writing URLs.
  • OutputStream* getOutputStream()
  • InputStream* getInputStream()
  • InputData* getContent()
  • void setDoOutput( int set)
  • void setDoInput( int set)
  • void setAllowUserInteraction( int set)
  • char* getContentType()
  • int getContentLength()
  • Internal: URLSocket

    URLSocket is the internal class that manages socket I/O.