openlsd.common.LSDStreamGobbler Class Reference

Inheritance diagram for openlsd.common.LSDStreamGobbler:

Inheritance graph
[legend]
Collaboration diagram for openlsd.common.LSDStreamGobbler:

Collaboration graph
[legend]

List of all members.


Detailed Description

Class to make a fix for Runtime.exec bug.
The API was not really well documented but now there is at least a warning (as of the 1.6 version) in the Process API:
"All its standard io (i.e. stdin, stdout, stderr) operations will be redirected to the parent process through three streams (getOutputStream(), getInputStream(), getErrorStream()). The parent process uses these streams to feed input to and get output from the subprocess. Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock."
What does this means ? Well, if you launch a process but you don't care about its ErrorStream for instance and so you don't try to read anything from it, you likely will have a chance to block the subprocess and even the main JVM, so having a deadlock. To avoid this, I use a specific thread to read from error stream and input stream (read anything without action), the StreamGobbler class.

Author:
Frederic BREGIER LGPL 2007

Public Member Functions

 LSDStreamGobbler (Process p)
 LSDStreamGobbler (InputStream is)
 LSDStreamGobbler (InputStream is, OutputStream redirect)
void run ()

Static Public Member Functions

static int waitForProcess (Process p)

Public Attributes

int status = 0

Private Attributes

Process p = null
InputStream is = null
OutputStream os = null

Constructor & Destructor Documentation

openlsd.common.LSDStreamGobbler.LSDStreamGobbler ( Process  p  ) 

Init from only a Process without taking into account InputStream. InputStream is not read since it will be read by an external program.

Parameters:
p 

openlsd.common.LSDStreamGobbler.LSDStreamGobbler ( InputStream  is  ) 

Init from only an IntputStream

Parameters:
is 

openlsd.common.LSDStreamGobbler.LSDStreamGobbler ( InputStream  is,
OutputStream  redirect 
)

Init from InputStream and OutputStream

Parameters:
is 
redirect 


Member Function Documentation

void openlsd.common.LSDStreamGobbler.run (  ) 

Run the StreamGobbler or Wait for the process to finish, reading any err data.

static int openlsd.common.LSDStreamGobbler.waitForProcess ( Process  p  )  [static]

Wait for the process to finish, reading any in/err data

Parameters:
p 
Returns:
the status of the process


Member Data Documentation

Process openlsd.common.LSDStreamGobbler.p = null [private]

Process

Returned status

InputStream openlsd.common.LSDStreamGobbler.is = null [private]

IntputStream

OutputStream openlsd.common.LSDStreamGobbler.os = null [private]

OutputStream


The documentation for this class was generated from the following file: