-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BinaryRequestBody and ContentBody use InputStream.transferTo(OutputStream) #1983
Conversation
Allow for optimization when underlying input stream (such as ByteArrayInputStream, ChannelInputStream) overrides transferTo(OutputStream) to avoid extra array allocations and copy larger chunks at a time (e.g. allowing 16KiB chunks via ApacheHttpClientBlockingChannel.ModulatingOutputStream from #1790). When moving to JDK 21+, this will also enable 16KiB byte chunk copies via InputStream.transferTo(OutputStream) per JDK-8299336, where as on JDK < 21 and when using Guava ByteStreams.copy 8KiB byte chunk copies are used. References: * palantir/hadoop-crypto#586 * https://bugs.openjdk.org/browse/JDK-8299336 * https://bugs.openjdk.org/browse/JDK-8067661 * https://bugs.openjdk.org/browse/JDK-8265891 * https://bugs.openjdk.org/browse/JDK-8273038 * https://bugs.openjdk.org/browse/JDK-8279283 * https://bugs.openjdk.org/browse/JDK-8296431
Generate changelog in
|
Released 3.88.0 |
@@ -39,7 +38,7 @@ final class InputStreamContentBody implements ContentBody { | |||
|
|||
@Override | |||
public void writeTo(OutputStream output) throws IOException { | |||
ByteStreams.copy(inputStream, output); | |||
inputStream.transferTo(output); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we get this into error-prone if this is now the preferred approach? I know I'm guilty of many uses of this method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call, I'd like to write up an error-prone rule to migrate folks soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this PR
Dialogue used Guava
ByteStreams.copy
for 8KiB byte buffer chunk copies.After this PR
==COMMIT_MSG==
BinaryRequestBody
andContentBody
useInputStream.transferTo(OutputStream)
Allow for optimization when underlying input stream (such as
ByteArrayInputStream
,ChannelInputStream
) overridestransferTo(OutputStream)
to avoid extra array allocations and copy larger chunks at a time (e.g. allowing 16KiB chunks viaApacheHttpClientBlockingChannel.ModulatingOutputStream
from #1790).When running on JDK 21+, this also enables 16KiB byte chunk copies via
InputStream.transferTo(OutputStream)
per JDK-8299336, where as on JDK < 21 and when using GuavaByteStreams.copy
8KiB byte chunk copies are used.References:
==COMMIT_MSG==
Possible downsides?