<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">/*
	An applet to read a URL
 */

import java.applet.*;
import java.net.URL ;
import java.io.InputStream ;

public class URL2String extends Applet
{
    // DATA
    private boolean success_flag ;
    
    // PUBLIC METHODS
	public URL2String() {
	    success_flag = false ;
	}
	
	public boolean success() { return success_flag ; } 
	
	public String read_relative_URL( String url_string ) 
	{
	    success_flag = false ;
	    try {
	        URL url = new URL( getDocumentBase(), url_string ) ;
	        return read_URL( url ) ; }
        catch( Exception e ) {
            System.err.println( "URL2String: Exception when reading from "+url_string) ;
            System.err.println( "            Message is : "+e.getMessage() ) ;
            System.err.println( "            Stack trace is" ) ;
            e.printStackTrace() ;
            return "" ; }
    }

	
	public String read_absolute_URL( String url_string ) 
	{
	    success_flag = false ;
	    try {
	        URL url = new URL( url_string ) ;
	        return read_URL( url ) ; }
        catch( Exception e ) {
            System.err.println( "URL2String: Exception when reading from "+url_string) ;
            System.err.println( "            Message is : "+e.getMessage() ) ;
            System.err.println( "            Stack trace is" ) ;
            e.printStackTrace() ;
            return "" ; }
    }

    // PRIVATE METHODS
    
	private String read_URL( URL url ) 
	{
	    try {
	        InputStream input_stream = url.openStream() ;
	        byte[] byte_buff = new byte[256] ;
	        char[] char_buff = new char[256] ;
            StringBuffer str_buff = new StringBuffer() ;
            while(true) {
                int bytes_read = input_stream.read( byte_buff ) ;
                if( bytes_read == -1 ) break ;
                for( int i=0 ; i &lt; bytes_read ; ++i ) {
                    char_buff[i] = (char) byte_buff[i] ; }
                str_buff.append( char_buff, 0, bytes_read ) ; }
            success_flag = true ;
            return str_buff.toString() ; }
        catch( Exception e ) {
            System.err.println( "URL2String: Exception when reading from "+url.toString()) ;
            System.err.println( "            Message is : "+e.getMessage() ) ;
            System.err.println( "            Stack trace is" ) ;
            e.printStackTrace() ;
            return "" ; }
    }
	        
	public void init()
	{
		// This code is automatically generated by Visual Cafe when you add
		// components to the visual environment. It instantiates and initializes
		// the components. To modify the code, only use code syntax that matches
		// what Visual Cafe can generate, or Visual Cafe may be unable to back
		// parse your Java file into its visual environment.
		//{{INIT_CONTROLS
		setLayout(null);
		setSize(1,1);
		//}}
	}
	
	//{{DECLARE_CONTROLS
	//}}
}
</pre></body></html>