Menu

Pipe does not close streams properly

2011-05-25
2013-04-30
  • florianhackenberger

    The Pipe class is buggy, as it does not close the streams after processing input/output/error. This is important for replicating functionality like:

    offset=0; for image in .jpg; do
    convert $image -resize 100x100 +polaroid -repage +$offset+0\! MIFF:-;
    (( offset = $offset + 100 ));
    done |
    convert MIFF:- -layers merge +repage out.png && xdg-open out.png

    with im4java using SequenceInputStream, PipedInputStream and PipedOutputStream. The problem is that after reading the output of the first convert process within the loop, SequenceInputStream receives a "Pipe broken" IOException from PipedInputStream, as the stream was not closed by Pipe in provideInput().

    A simple iSource/Sink.close(); after each copyBytes solves the problem.

     
  • Bernhard Bablok

    Bernhard Bablok - 2011-05-26

    I'm not quite sure if this is the correct solution. I have been working on this issue recently, and temporarily thought about adding an explicit close()-method to Pipe, but discarded the idea because all my test-programs work fine without it. But maybe my programs don't cover all relevant issues, so you might want to post your code and I will further investigate the issue.

    The main argument against closing the stream within Pipe is that the streams are created outside and passed to Pipe in the constructor. In a way they are foreign objects and the creator should be responsible of changing them.

    Bernhard

     

Log in to post a comment.