Skip to content

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
xinsong-cui added a commit that referenced this pull request Jan 7, 2025
* misc: enhance support for replayable instances of `InputStream` (#1197)

* chore: release 1.3.31

* chore: bump snapshot version to 1.3.32-SNAPSHOT

* fix: CBOR protocol test assertions / blob serialization (#1198)

* fix: correctly serialize subset of shape's members when configured (#1199)

* chore: release 1.3.32

* chore: bump snapshot version to 1.3.33-SNAPSHOT

---------

Co-authored-by: Matas <[email protected]>
Co-authored-by: aws-sdk-kotlin-ci <[email protected]>
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