Exemplo n.º 1
0
 /**
  * Includes a script.
  *
  * @param f The file describing the script file to be included
  * @return result Object of eval if successful, null otherwise
  */
 public Object includeScript(File f) {
   Object result = null;
   try {
     FileReader fr = new FileReader(f);
     try {
       result = ((ScriptEngine) ScriptPlugin.this.sEngine).eval(fr);
     } catch (Throwable t) {
       log(
           Level.SEVERE,
           "Failed to include script " + f.getPath() + " from " + file.getPath(),
           t);
     }
     fr.close();
   } catch (Throwable t) {
     log(Level.SEVERE, "Failed to read file " + f.getPath() + " from " + file.getPath(), t);
   }
   return result;
 }
Exemplo n.º 2
0
    /**
     * Gets the contents of a file.
     *
     * @param file The file describing the file whose contents are to be read
     * @return The file's contents, or null if an error occured, or the file does not exist.
     */
    public String getFileContents(File file) {
      StringBuffer sb = new StringBuffer(1024);
      FileReader fr = null;
      BufferedReader reader = null;
      try {
        fr = new FileReader(file);
        reader = new BufferedReader(fr);
        char[] chars = new char[1024];
        int numRead = 0;
        while ((numRead = reader.read(chars)) > -1) {
          sb.append(String.valueOf(chars));
        }
      } catch (Throwable e) {
        return null;
      } finally {
        try {
          fr.close();
          reader.close();

        } catch (Throwable e) {
        }
      }
      return sb.toString();
    }