Madden
Madden

Reputation: 1080

How to reuse a ByteArrayInputStream?

I have a piece of code that reads some binary data via an InputStream backed by a ByteArrayInputStream, like this

Object do(byte[] arr) {
    InputStream is = new ByteArrayInputStream(arr);
    return conv(is);

I would like to avoid constructing new ByteArrayInputStream each call and instead just load the arr parameter into an existing member stream, however I can't find a simple way to do this. Is this or similar behaviour allowed or this against the recommended use of streams?

Upvotes: 4

Views: 2921

Answers (1)

Argb32
Argb32

Reputation: 1405

You can use mark()/reset() methods for this.

Upvotes: 1

Related Questions