• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Antonio Bernal
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic