Skip to content

CBZip2InputStream closes input stream when all data is read #2150

@martijnbrinkers

Description

@martijnbrinkers

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));

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions