Skip to content

EntityInputStream should override readAllBytes() #5787

@gredler

Description

@gredler

The default implementation of InputStream.readAllBytes() always creates a new byte[]. By relying on the default implementation, EntityInputStream always reflects this default behavior, instead of reflecting the behavior of the wrapped stream.

An application that wants to make the request body readable more than once can call request.setEntityStream(new MyInputStreamWrapper(request.getEntityStream())) in a ContainerRequestFilter. If the application also wants to avoid creating multiple copies of the request body, MyInputStreamWrapper.readAllBytes() can return the original underlying byte[].

However, resource handlers receive an EntityInputStream wrapping the MyInputStreamWrapper, and a call to EntityInputStream.readAllBytes() will create an unwanted copy of the byte[], since EntityInputStream.readAllBytes() does not call MyInputStreamWrapper.readAllBytes().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions