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

class URLSearcher
{   public URLSearcher (String source_name, String target)
    {   sourceURL    = source_name;
        searchTarget = target;
    }

    public void search ()
    {   // Open URL sourceURL for input on data stream in
	BufferedReader in;
        try 
        {   URL urlin = new URL(sourceURL); 
	    in  = new BufferedReader
	        (new InputStreamReader(urlin.openStream()));
        } 
	catch (MalformedURLException e)
        {   System.out.println("Malformed URL:  " + sourceURL); 
	    return;
	} 
	catch (IOException e) 
	{   System.out.println("Cannot open URL:  " + sourceURL); 
	    return;
	}

        String line;
	int n = 1;
	try
	{   for (line = in.readLine(); line != null; line = in.readLine())
	    {   if (line.indexOf(searchTarget) >= 0)
                    System.out.println(sourceURL + " " + n + ":  " +line);
	        n++;
	    }
	} 
	catch (IOException e) { }

	// Close the input file
	try { in.close(); } catch (IOException e) { }
    }

    private String sourceURL;
    private String searchTarget;
}

public class URLSearcherTest  
{   public static void main(String[] args) 
    {   if (args.length != 2)
            System.err.println("Usage: java URLSearcherTest " + 
                    "<URL to search> <string to be located>");
        else 
	{   URLSearcher u = new URLSearcher(args[0],args[1]);
	    u.search();
	}
        System.exit(0);
    }

}


