public class FThread extends Thread {
private File inputFile;
private DataInputStream input; //input file stream
private String infoString;
private StringBuffer outputString;
private String inputName;
public FThread(String Name, String FName) {
super(Name);
outputString=new StringBuffer(10); // hold the output info.
inputName=new String(FName);
}
public void run()
{
// now process the list of URLs by reading them, getting info, finding results, and printing results to a file
try {
loadInfo(inputName); //loading the list of URLs into a String.
}
catch (IOException e)
{
System.out.println(e.toString());
}
processList();
System.out.println("\nFinishing Up...."

;
finishup(); //finish up with the files and write output to a file.
}
private void processList()
{
// the processing of the list of URLs is done here.
String part;
int start=0;
int pos1=0, pos2=0, pos3=0;
long positionOut=1;
while (pos1!=-1)
{
pos1=infoString.indexOf(".com", start);
if (pos1!=-1)
{
part=infoString.substring(start,pos1+4);
// got it System.out.println("\n\n"+part+"\n"

;
process(part); // ie process the URL
start=pos1+5; //ie. eliminate the new line character
positionOut++;
}
if ((positionOut%10000)==0)
System.out.println("Thread "+getName()+ "done 10000 lines"

;
}
}
private void process(String urlName)
{
// get the information
URL currURL;
String resultS1,resultS2;
String result="";
try
{
//currURL=new URL("
String temp="
currURL=new URL(temp);
HttpURLConnection conn=(HttpURLConnection)currURL.openConnection();
conn.connect();
//get an input stream from the URL connection object
InputStreamReader isr=new InputStreamReader(conn.getInputStream());
BufferedReader in =new BufferedReader(isr);
String hold;
while ((hold=in.readLine())!=null)
{
result+=hold+"\n";
}
in.close();
//now try processing this garbage
int ind1=result.indexOf("<tr bgcolor=#333333>",0);
int ind2;
if (ind1!=-1)
{
ind2=result.indexOf("</td>",ind1+83);
resultS1=result.substring(ind1+83,ind2);
// also write the result to a string that will be piped at the end to an outputFile.
outputString.append(urlName+" "+resultS1+"\n"

;
in=null;
isr=null;
}
//String hold = currURL.getContent().toString();
//System.out.println("\ngot here"

;
// System.out.println(urlName);
// no need to replace anything
//System.out.println("\ngot here"

;
}
catch (ConnectException w)
{
System.out.println("Problem connecting with URL Info: "+ urlName);
System.out.println("Retrying......"

;
process(urlName); //internal call.
}
catch (BindException b)
{
//ie. too many processes running simultaneously.
System.out.println("Problem connecting with URL Info: "+ urlName);
System.out.println("Retrying...."

;
process(urlName); //internal call.
}
catch (Exception e)
{
System.out.println("Error. Retrying..."

;
System.out.println(e.toString());
process(urlName); //internal call
}
currURL=null; // clear up the memory
}
private void loadInfo(String FName) throws IOException
{
inputFile=new File(FName);
StringBuffer infoList;
try {
input=new DataInputStream(new FileInputStream(inputFile));
}
catch (IOException e) {
System.out.println("Error Opening File"

;
}
infoList=new StringBuffer(10);
char tmp;
try {
while(true) {
tmp=(char)input.readByte();
infoList.append(tmp);
}
}
catch (EOFException e) { }
System.out.println("Opened "+FName);
//now set the text for the text area
infoString=new String(infoList.toString());
input.close();
}
public void finishup()
{
DataOutputStream output;
String fn=inputFile.getName();
int i = fn.indexOf(".txt"

;
String nn=fn.substring(0,i);
String outputName=nn+"O.txt";
File outFile =new File (outputName);
String outputN=new String(outputString.toString());
//output the string to a file
try {
output=new DataOutputStream(new FileOutputStream(outputName));
for (int j=0; j<outputN.length(); j++)
{
output.writeByte(outputN.charAt(j));
}
output.close();
}
catch (IOException e) {
System.out.println("Error Opening Save File"

;
}
System.gc();
System.out.println("Thread "+getName()+" done...Exiting"

;
}
}