Skip to content
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

misc: enhance support for replayable instances of InputStream #1197

Merged
merged 6 commits into from
Dec 18, 2024

Conversation

lauzadis
Copy link
Contributor

Issue #

Description of changes

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@lauzadis lauzadis requested a review from a team as a code owner December 17, 2024 15:45

This comment has been minimized.

@lauzadis lauzadis changed the title misc: enhance support for replayable instances of [InputStream] misc: enhance support for replayable instances of InputStream Dec 17, 2024
Comment on lines 116 to 137
public fun InputStream.asByteStream(contentLength: Long? = null): ByteStream.SourceStream {
val source = source()
if (markSupported() && contentLength != null) {
mark(contentLength.toInt())
}

return object : ByteStream.SourceStream() {
override val contentLength: Long? = contentLength
override val isOneShot: Boolean = !markSupported()
override fun readFrom(): SdkSource = source
override fun readFrom(): SdkSource {
if (markSupported() && contentLength != null) {
reset()
mark(contentLength.toInt())
return object : SdkSource by source() {
// no-op close
override fun close() { }
}
}

return source()
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Is this a behavioral change wrt closing? It seems like before we returned the raw underlying SdkSource before which, if closed, would close the underlying InputStream. Now it looks like that won't happen...why is that necessary?

Copy link
Contributor Author

@lauzadis lauzadis Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is. Without this change the underlying InputStream is closed after hashing (because we call a .use { } on the SdkSource) and subsequent attempts to read the body (e.g. during transmission) fail with IOException: Stream closed

This comment has been minimized.

Copy link

Affected Artifacts

Changed in size
Artifact Pull Request (bytes) Latest Release (bytes) Delta (bytes) Delta (percentage)
runtime-core-jvm.jar 812,469 811,179 1,290 0.16%

@lauzadis lauzadis merged commit 4575023 into main Dec 18, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants