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
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply 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: 18652
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
 
IntelliJ Java IDE
 
subject: Why don't write array of characters in a BufferedOutputStream using Piped?
 
Threads others viewed
Apache Commons Exec Piping to Input Stream using PipedInputStream
PipedStreams fail for FTP upload a XML file
Stall when reading variable
Piped Streams ( pipedinputstream and pipedoutputstream )
serialization instead of cloning?
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture