// beginner's guide to applets:
//
// K.Becker

// you will the following libraries

import java.awt.*;// awt = Abstract Windows Toolkit

import java.net.*; // to get at stuff over the net
import java.io.*;  // for reading and stuff

import java.lang.Character;
import java.lang.String;

public class Read {

    // the name of the data file to be read
    private static final String urlName =
       	"http://www.cpsc.ucalgary.ca/~becker/461/Asst/SearchEngine/Resources/text.bin";

    String s;

    int i,j,k;

    Read() {
	s = "testing";
    }

    // read the data
    public String doit() throws Exception {

        try {
	    // for opening a network file
	    URL binfile = new URL( urlName );
	    // allows for binary input in blocks or by byte
	    BufferedInputStream in =
		new BufferedInputStream( binfile.openStream() );

	    int b = 0;
	    s = "START::";
	    // read will return -1 at end-of-file
	    while( ( b = in.read() ) >= 0 ) {
		// reads in a single signed byte at a time
		// this example converts it to character to display

		s = s + (char)b;
		// question: what's happenning to the white space?
	    }
	    in.close();
	    s = s + "::END";
	    
	}
	catch( IOException e ) { System.err.println( e.toString() ); }
	   
	return s;
	    
    } // end doit   

} // end Read
