
import java.util.*;
import java.io.*;



/** 
 * An object to load text from a file into a string buffer
 *
 * @author matth3wbishop<at>yahoo!<dot>com
 */

public class BufferLoad extends Object
{

  //--------------------------------------------
  //private StringBuffer sbFileContents;
  //-------------------------------------------------
  private Date startTime;
  //-------------------------------------------------
  private Date finishTime;
  //-------------------------------------------------
  private String fileName;
  //-------------------------------------------------
  private String errors;
  //-------------------------------------------------


  //-------------------------------------------------
  /**  */
   public BufferLoad() 
   {
     this.fileName = "";
   } 


  //--------------------------------------------
  public static String loadBuffer(String sFileName) 
  {

      BufferedReader brReader;
      FileReader frTextFile;
      StringBuffer sbFileContents = new StringBuffer("");
      String sFileContents;

      try
      {
        frTextFile = new FileReader(sFileName);
      }
      catch (FileNotFoundException e)
      {
        System.err.println("couldn't find the file ");
        System.err.println(e);
        return "";
      }

      //this.sCurrentFileLocalName =
      //  new File(wdLoad.getFileName()).getAbsolutePath();

      brReader = new BufferedReader(frTextFile);
      int ii;

      try
      {
        ii = brReader.read();
        while (ii != -1)
        {
          sbFileContents.append((char)ii);
          ii = brReader.read();
        }

        brReader.close();
        frTextFile.close();
      }
      catch (IOException e)
      {
        System.err.println(e);
        return "";
      }
      return sbFileContents.toString();

  } //-- m: loadBuffer

  //--------------------------------------------
  /** A main method to test from the console */
  public static void main(String[] args) throws Exception
  {
    StringBuffer sbUsageMessage = new StringBuffer("");
    sbUsageMessage.append("usage: java BufferLoad file-name");

    if (args.length == 0)
    {	    
      System.out.println(sbUsageMessage);
      System.exit(-1);
    }

    String sContents;
    sContents = BufferLoad.loadBuffer(args[0]);
    System.out.println("Contents of the file " + args[0]);
    System.out.println(sContents);
    System.out.println("");

  } //-- main()    
    
} //-- class: BufferLoad


