-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
CBZip2InputStream closes the underlying (wrapped) stream in CBZip2InputStream#bsFinishedWithStream().
This can lead to unexpected stream is closed IOExceptions. For example when you read objects from the PGP stream:
while ((streamObject = objectFactory.nextObject()) != null) { ... }
When all data is read, CBZip2InputStream closes the underlying stream which will then result in an IOException when calling objectFactory.nextObject(). Because this is a general IOException, the caller cannot know whether this was because CBZip2InputStream closed the input stream or because of some other problem.
The behaviour of CBZip2InputStream is different from the other compression streams, i.e., the other compression streams to not close the input stream. In my view a stream wrapper should in most cases not close the input stream. Closing the input stream is the responsibility of the creator of the input stream.
My workaround for now is that I wrap the input stream with a CloseShieldInputStream which ignores closing the stream
PGPObjectFactory objectFactory = new JcaPGPObjectFactory(CloseShieldInputStream.wrap(decoderStream));