|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ca.unbc.cpsc101.JavaPipe
public class JavaPipe
The JavaPipe provides a means to start a separate java program
and communicate with its System.in and System.out using Readers
and Writers.
The JavaPipe class uses the Process
and
ProcessBuilder
classes to create
a process that runs on the other side of the JavaPipe.
Field Summary | |
---|---|
static String |
DEFAULT_EXEC_PATH
The default PATH used to search for the java executable. |
static String |
version
describes the version of the JavaPipe class. |
Constructor Summary | |
---|---|
JavaPipe(String className)
Sets up, but does not start a JavaPipe. |
Method Summary | |
---|---|
JavaPipe |
destroy()
This method provides an explicit means by which to release the resources acquired by a JavaPipe. |
String |
getClassPath()
returns the CLASSPATH that is inserted in the environment when starting java for this JavaPipe. |
String |
getExecPath()
This is the path that is used to locate the java
executable. |
Reader |
getInputReader()
This Reader provides the text that the corresponding process writes on System.out. |
PrintWriter |
getOutputWriter()
This Writer provides the text written to it to the corresponding processes’ System.in. |
JavaPipe |
setClassPath(String cp)
set the CLASSPATH environment variable to be used when starting the java process for this JavaPipe. |
JavaPipe |
setExecPath(String ep)
Set the path used to find the java executable. |
JavaPipe |
start()
creates a java process and connects pipes for communication with it. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String version
public static final String DEFAULT_EXEC_PATH
setExecPath
is called before start
, this is where the
java executable is searched for.
setExecPath.
,
Constant Field ValuesConstructor Detail |
---|
public JavaPipe(String className)
Between the creation of the JavaPipe and when it is started,
.setExecPath
() can be used to change the
path where the java
command is found, and .setClassPath
(...)
can be used to set
the CLASSPATH variable used by java to find the requested
class.
Note that the constructor does not begin execution of
java, and does not check the legitimacy of the className
argument.
className
- specifies the name of
the class whose main is to be run to create the pipe.start
Method Detail |
---|
public String getClassPath()
public JavaPipe setClassPath(String cp)
cp
- the value to which to set the CLASSPATH.
JavaPipe
that called this object.
(allows for “chained” calls like
fred.setClassPath(".:..").start()
.public String getExecPath()
java
executable. When the start method
is executed,
JavaPipe attempts to start another java session remotely over a
pipe using the path specified by getExecPath.
public JavaPipe setExecPath(String ep)
java
executable.
When the start
method is executed,
JavaPipe attempts to start another java session remotely over a
pipe using the path last path specified by setExecPath.
The default is DEFAULT_EXEC_PATH
.
ep
- the value to which to set the PATH on which java
will be found.
JavaPipe
that called this object.
(allows for “chained” calls like
fred.setExecPath(".:..").start()
.public JavaPipe start() throws IOException
getOutputWriter
(), and what
it prints on System.out
appears on this JavaPipe’s this.getInputReader
().
JavaPipe
that called this object.
(allows for “chained” calls like
fred..start().getInputReader()
.
IOException
- when the start
method of the underlying ProcessBuilder
does.
IllegalThreadStateException
- when this method
is able to detect early failure of the java
program
(perhaps due to being unable to find the specified class).
This is not guaranteed to work. Some errors may not be
detected until attempting perform i/o with the JavaPipe.public JavaPipe destroy()
JavaPipe
that called this object.
(allows for “chained” calls like
fred.destroy().start()
.public Reader getInputReader()
.start()
ed and when it is
.destroy()
ed, provided that the corresponding process is well
behaved and does not quit.
public PrintWriter getOutputWriter()
.start()
ed and when it is
.destroy()
ed, provided that the corresponding process is well
behaved and doesn't quit.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |