next up previous contents
Next: EndsWithFilter Class Up: MyIO Package Previous: MyIO Package

xFileInputStream Class

The xFileInputStream is a simple extension of the FileInputStream. This class adds a readString() method which creates a String from the contents of a file. The NetWorKs class uses this class to read a file into a String which is then passed to the GraphPanel. This was done so the GraphPanel could avoid file I/O, which is very restricted in applets.

package MyIO;

import java.io.*;

public class xFileInputStream extends FileInputStream {

/*
Adds the readString method to FileInputStream.
Note: reads entire file into a single String Object
*/

   public xFileInputStream(String name) throws FileNotFoundException,
                                               IOException {
      super(name);
   }

   public xFileInputStream(File file) throws FileNotFoundException,
                                             IOException {
      super(file);
   }

   public xFileInputStream(FileDescriptor fdObj) {
      super(fdObj);
   }

   public String readString() {
      try {int size;
           size=this.available();
           if (size==0)
              return null;
           byte buf[] = new byte[size];
           int i=0;
           while(i<size)
             i+=this.read(buf,i,size-i);
           return new String(buf,0);
           }
      catch (IOException e) { return null; }
   }

}



Kelly Waters
Mon Oct 27 18:18:15 EST 1997