Package com.zaranux.os.client.commands

Source Code of com.zaranux.os.client.commands.echo

package com.zaranux.os.client.commands;

import com.zaranux.client.api.AsyncCallback;
import com.zaranux.client.java.io.PrintStream;


public class echo extends Command {

  public echo()
  {
    super.addOption("n", false, "do not output the trailing newline");
    super.addOption("e", false, "enable interpretation of backslash escapes");
    super.addOption("E", false, "disable interpretation of backslash escapes (default)");
    super.addOption("h", false, "print options");

  }
 
  @Override
  public void execute( final AsyncCallback<Boolean> callback) {
    /* if(_in == null)
    {
      super.reportError("echo.java: Input stream is null", callback);
    }else */ if(System.out == null)
    {
      super.reportError("echo.java: Output stream is null", callback);
    }else
    {
      if(! (System.out instanceof PrintStream) )
      {
         System.out = new PrintStream(System.out, true);
      }
     
      final PrintStream outPS = (PrintStream) System.out;
     
      StringBuffer output = new StringBuffer();
     
      String[] args = super.getArgs();
      for(int i = 0 ; i< args.length ; i++)
      {
        output.append(args[i]);
      }
     
      if(hasOption("h"))
      {
        super.printHelp(callback);
        return;
      }

    //  output.append("\n");
      outPS.print(output,new AsyncCallback<Boolean>()
      {
        public void onSuccess(Boolean b)
        {
        //  outPS.flush(callback);
          callback.onSuccess(true);
        }
        public void onFailure(Throwable t)
        {
          callback.onFailure(t);
        }
      });
    }
  }

}
TOP

Related Classes of com.zaranux.os.client.commands.echo

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.