File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Why don't write array of characters in a BufferedOutputStream using Piped? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Why don Watch "Why don New topic
Author

Why don't write array of characters in a BufferedOutputStream using Piped?

Antonio Bernal
Greenhorn

Joined: Apr 10, 2002
Posts: 1
This morning I programed one program this code in one program, but when I compile the program, It was stoped in the "bOut.write(....)" line, It wasn't finish the program. Please, why don't found this code??
here It's the code.

byte nbuffer[] = new byte [1024*4];
PipedOutputStream pout = new PipedOutputStream();
PipedInputStream pin = new PipedInputStream(pout);
BufferedOutputStream bOut = new BufferedOutputStream( poutStream );
while ((lenToWrite=in.read(nbuffer)) != -1)
{
bOut.write( nbuffer , 0 , lenToWrite );
}
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Please take a moment to read our display name policy and edit your display name to comply. Thanks.
Your question is addressed in the API for PipedOutputStream:

Typically, data is written to a PipedOutputStream object by one thread and data is read from the connected PipedInputStream by some other thread. Attempting to use both objects from a single thread is not recommended as it may deadlock the thread.

The problem is, most likely, that your PipedOutputStream's internal buffer is full, because you're writing to the output stream, but no one is reading from the input stream. Eventually the system decides it's had enough, and blocks until you read. Which will never happen here, because you haven't created a separate thread to read from the input stream.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why don't write array of characters in a BufferedOutputStream using Piped?