001: /*
002: * $Id: AnyProcess.java,v 1.14 2002/09/16 08:05:02 jkl Exp $
003: *
004: * Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
005: *
006: * Use is subject to license terms, as defined in
007: * Anvil Sofware License, Version 1.1. See LICENSE
008: * file, or http://njet.org/license-1.1.txt
009: */
010: package anvil.core.io;
011:
012: import anvil.core.Any;
013: import anvil.core.AnyAbstractClass;
014: import anvil.script.Context;
015: import java.io.BufferedOutputStream;
016:
017: /// @class Process
018: /// Native process created by <code>exec</code>.
019:
020: /**
021: * class AnyProcess
022: *
023: * @author: Jani Lehtimäki
024: */
025: public class AnyProcess extends AnyAbstractClass {
026:
027: public static final anvil.script.compiler.NativeClass __class__ = new anvil.script.compiler.NativeClass(
028: "Process",
029: AnyProcess.class,
030: //DOC{{
031: ""
032: + " @class Process\n"
033: + " Native process created by <code>exec</code>.\n"
034: + " @method getInputStream\n"
035: + " Gets the input stream of the subprocess.\n"
036: + " @synopsis InputStream getInputStream()\n"
037: + " @method getErrorStream\n"
038: + " Gets the error stream of the subprocess.\n"
039: + " @synopsis OutputStream getErrorStream()\n"
040: + " @method getOutputStream\n"
041: + " Gets the output stream of the subprocess.\n"
042: + " @synopsis OutputStream getOutputStream()\n"
043: + " @method waitFor\n"
044: + " causes the current thread to wait, if necessary, until the \n"
045: + " process represented by this Process object hasterminated.\n"
046: + " @synopsis int waitFor()\n"
047: + " @return the exit value of the process. \n"
048: + " By convention, 0 indicates normal termination.\n"
049: + " @throws Interrupted if the current thread is interrupted \n"
050: + " by another thread while it is waiting, then the wait is ended \n"
051: + " and an Interrupted is thrown.\n"
052: + " @method exitValue\n"
053: + " Returns the exit value of process.\n"
054: + " @synopsis int exitValue()\n"
055: + " @return Exit value of process, or <code>null</code> if the\n"
056: + " process is not yet terminated.\n"
057: + " @method destroy\n"
058: + " Kills the subprocess. The subprocess represented by this \n"
059: + " Process is forcibly terminated.\n"
060: + " @synopsis void destroy()\n"
061: //}}DOC
062: );
063: static {
064: IOModule.class.getName();
065: }
066:
067: private Process _process;
068:
069: public AnyProcess(Process process) {
070: _process = process;
071: }
072:
073: public final anvil.script.ClassType classOf() {
074: return __class__;
075: }
076:
077: public Object toObject() {
078: return _process;
079: }
080:
081: /// @method getInputStream
082: /// Gets the input stream of the subprocess.
083: /// @synopsis InputStream getInputStream()
084: public Any m_getInputStream() {
085: return new AnyInputStream(_process.getInputStream());
086: }
087:
088: /// @method getErrorStream
089: /// Gets the error stream of the subprocess.
090: /// @synopsis OutputStream getErrorStream()
091: public Any m_getErrorStream() {
092: return new AnyInputStream(_process.getErrorStream());
093: }
094:
095: /// @method getOutputStream
096: /// Gets the output stream of the subprocess.
097: /// @synopsis OutputStream getOutputStream()
098: public Any m_getOutputStream() {
099: return new AnyOutputStream(new BufferedOutputStream(_process
100: .getOutputStream()));
101: }
102:
103: /// @method waitFor
104: /// causes the current thread to wait, if necessary, until the
105: /// process represented by this Process object hasterminated.
106: /// @synopsis int waitFor()
107: /// @return the exit value of the process.
108: /// By convention, 0 indicates normal termination.
109: /// @throws Interrupted if the current thread is interrupted
110: /// by another thread while it is waiting, then the wait is ended
111: /// and an Interrupted is thrown.
112: public Any m_waitFor(Context context) {
113: try {
114: return Any.create(_process.waitFor());
115: } catch (InterruptedException e) {
116: throw context.Interrupted(e.getMessage());
117: }
118: }
119:
120: /// @method exitValue
121: /// Returns the exit value of process.
122: /// @synopsis int exitValue()
123: /// @return Exit value of process, or <code>null</code> if the
124: /// process is not yet terminated.
125: public Any m_exitValue(Context context) {
126: try {
127: return Any.create(_process.exitValue());
128: } catch (IllegalThreadStateException e) {
129: throw context.BadState(e.getMessage());
130: }
131: }
132:
133: /// @method destroy
134: /// Kills the subprocess. The subprocess represented by this
135: /// Process is forcibly terminated.
136: /// @synopsis void destroy()
137: public Any m_destroy() {
138: _process.destroy();
139: return this;
140: }
141:
142: }
|