package commands; import java.io.*; import kernel.*; /** * Prints given input. * * @author Tomáš Podskalský */ public class echo extends AbstractProcess { public void realization() throws AppException { PipedOutputStream output = (this.getOut() != null) ? (PipedOutputStream) this .getOut() : null; try { for (String arg : getArgs()) { String s = new String(arg + " "); output.write(s.getBytes()); } String s = new String("\n"); output.write(s.getBytes()); output.flush(); } catch (IOException ioe) { ioe.printStackTrace(); throw new AppException(" I/O Error\n" + ioe.getMessage(), ioe); } catch (NullPointerException npe) { npe.printStackTrace(); throw new AppException("Output is not specified\n" + npe.getMessage(), npe); } catch (Exception e) { e.printStackTrace(); throw new AppException("Unknown error.\n" + e.getMessage(), e); } } /** * Provides help for users. * */ public String getHelp() { return "\n\nDescription:\nPrints given input.\n\nPoužití:\n" + "echo [arg1 [arg2 [...]]]\n\n" + "arg1, arg2, ...\tstrings to print."; } }