Logo Search packages:      
Sourcecode: jmk version File versions  Download package

void edu::neu::ccs::jmk::CreateOperator::exec ( String[]  args,
java.io.PrintWriter  out 
) throws CommandFailedException [inline]

The create operator creates a file given by its first operand and than writes any remaining operands into the file as separate lines of text.

Parameters:
args parameters to the operation
out place to write messages

Implements edu::neu::ccs::jmk::Operator.

Definition at line 50 of file CreateOperator.java.

References getName().

  {
    if (args.length == 0) {
      String msg = getName() + " received no operands";
      throw new CommandFailedException(msg);
    }
    try {
      FileWriter fw = new FileWriter(args[0]);
      if (args.length == 1)
      fw.close();
      else {
      BufferedWriter bw = new BufferedWriter(fw);
      PrintWriter pw = new PrintWriter(bw);
      for (int i = 1; i < args.length; i++)
        pw.println(args[i]);
      pw.close();
      }
      return;
    }
    catch (FileNotFoundException ex) {
      out.println("Cannot open " + ex.getMessage());
    }
    catch (IOException ex) {
      out.println(ex.toString());
    }
    String msg = getName() + " " + args[0] + " operation failed";
    throw new CommandFailedException(msg);
  }


Generated by  Doxygen 1.6.0   Back to index