/*
* $Id: AnyProcess.java,v 1.14 2002/09/16 08:05:02 jkl Exp $
*
* Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
*
* Use is subject to license terms, as defined in
* Anvil Sofware License, Version 1.1. See LICENSE
* file, or http://njet.org/license-1.1.txt
*/
package anvil.core.io;
import anvil.core.Any;
import anvil.core.AnyAbstractClass;
import anvil.script.Context;
import java.io.BufferedOutputStream;
/// @class Process
/// Native process created by <code>exec</code>.
/**
* class AnyProcess
*
* @author: Jani Lehtim�ki
*/
public class AnyProcess extends AnyAbstractClass
{
public static final anvil.script.compiler.NativeClass __class__ =
new anvil.script.compiler.NativeClass("Process", AnyProcess.class,
//DOC{{
""+
" @class Process\n" +
" Native process created by <code>exec</code>.\n" +
" @method getInputStream\n" +
" Gets the input stream of the subprocess.\n" +
" @synopsis InputStream getInputStream()\n" +
" @method getErrorStream\n" +
" Gets the error stream of the subprocess.\n" +
" @synopsis OutputStream getErrorStream()\n" +
" @method getOutputStream\n" +
" Gets the output stream of the subprocess.\n" +
" @synopsis OutputStream getOutputStream()\n" +
" @method waitFor\n" +
" causes the current thread to wait, if necessary, until the \n" +
" process represented by this Process object hasterminated.\n" +
" @synopsis int waitFor()\n" +
" @return the exit value of the process. \n" +
" By convention, 0 indicates normal termination.\n" +
" @throws Interrupted if the current thread is interrupted \n" +
" by another thread while it is waiting, then the wait is ended \n" +
" and an Interrupted is thrown.\n" +
" @method exitValue\n" +
" Returns the exit value of process.\n" +
" @synopsis int exitValue()\n" +
" @return Exit value of process, or <code>null</code> if the\n" +
" process is not yet terminated.\n" +
" @method destroy\n" +
" Kills the subprocess. The subprocess represented by this \n" +
" Process is forcibly terminated.\n" +
" @synopsis void destroy()\n"
//}}DOC
);
static {
IOModule.class.getName();
}
private Process _process;
public AnyProcess(Process process)
{
_process = process;
}
public final anvil.script.ClassType classOf() {
return __class__;
}
public Object toObject()
{
return _process;
}
/// @method getInputStream
/// Gets the input stream of the subprocess.
/// @synopsis InputStream getInputStream()
public Any m_getInputStream()
{
return new AnyInputStream(_process.getInputStream());
}
/// @method getErrorStream
/// Gets the error stream of the subprocess.
/// @synopsis OutputStream getErrorStream()
public Any m_getErrorStream()
{
return new AnyInputStream(_process.getErrorStream());
}
/// @method getOutputStream
/// Gets the output stream of the subprocess.
/// @synopsis OutputStream getOutputStream()
public Any m_getOutputStream()
{
return new AnyOutputStream(new BufferedOutputStream(_process.getOutputStream()));
}
/// @method waitFor
/// causes the current thread to wait, if necessary, until the
/// process represented by this Process object hasterminated.
/// @synopsis int waitFor()
/// @return the exit value of the process.
/// By convention, 0 indicates normal termination.
/// @throws Interrupted if the current thread is interrupted
/// by another thread while it is waiting, then the wait is ended
/// and an Interrupted is thrown.
public Any m_waitFor(Context context)
{
try {
return Any.create(_process.waitFor());
} catch (InterruptedException e) {
throw context.Interrupted(e.getMessage());
}
}
/// @method exitValue
/// Returns the exit value of process.
/// @synopsis int exitValue()
/// @return Exit value of process, or <code>null</code> if the
/// process is not yet terminated.
public Any m_exitValue(Context context)
{
try {
return Any.create(_process.exitValue());
} catch (IllegalThreadStateException e) {
throw context.BadState(e.getMessage());
}
}
/// @method destroy
/// Kills the subprocess. The subprocess represented by this
/// Process is forcibly terminated.
/// @synopsis void destroy()
public Any m_destroy()
{
_process.destroy();
return this;
}
}