Concurrently consume stdout from an external process
<p>Is there a thread-safe way to concurrently consume the stdout from an external process, using ProcessBuilder in Java 1.6?</p>

<p>Background: I need to invoke pbzip2 to unzip large files to stdout and to process each line as the file is decompressed (pbzip2 utilizes multiple CPUs, unlike other implementations).</p>

<p>The logical approach is to create a child thread to loop over the InputStream (i.e. stdout; don't you just love the naming?), as follows:</p>

<pre><code>while((line = reader.readLine()) != null)
{
     // do stuff
}
</code></pre>

<p>However, unzipping is slow, so what I really need is for the reader.readLine method to quietly wait for the next line(s) to become available, instead of exiting.</p>

<p>Is there a good way to do this?</p>
