// AddLineNumbers.java
//
// You may use and distribute this example. This program is 
// provided WITHOUT WARRANTY either expressed or implied.
//
// (C) Henrik Björkman 1997
//
//
// History:
// 0.0 Created by Henrik Björkman 1998-06-05

import java.io.*;




public class AddLineNumbers extends Thread
{
  DataInputStream in;
  PrintStream out;
  int line=1;

  public AddLineNumbers(InputStream in, OutputStream out)
  {
    this.in = new DataInputStream(in);
    this.out = new PrintStream (out);
    this.start();
  }


  public void run() 
  {
    String str;
    try 
    {
      for(;;) 
      {
        // read in a line
        str = in.readLine();
        if (str == null) break;

        out.println(""+line+" "+str);
        line++;
      }
    }
    catch (IOException e) {System.err.println(e);}
    finally 
    { 
      try 
      {
        if (in!=null) {in.close();}
        if (out!=null) {out.close();}
      } 
      catch (IOException e) {System.err.println(e);}
    }
  }

  public static void main(String args[]) 
  {
    if (args.length < 1 )
    {
      System.out.println("Usage: java AddLineNumbers <filename>");
      System.exit(0);
    }
    try
    {
      new AddLineNumbers(new FileInputStream(args[0]),System.out);
    }
    catch (IOException e) 
    {
      System.err.println("AddLineNumbers: " + e);
    }
  }
}



