Skip to content

ByteStreamJVM.writeToOutputStream is documented as not closing the provided stream, but does close it #1444

@cloudshiftchris

Description

@cloudshiftchris

Describe the bug

ByteStreamJVM.writeToOutputStream is documented as This method does not flush or close the given OutputStream. but does close the stream (indirectly).

outputStream.sink() ultimately creates an okio.OutputStreamSink that has override fun close() = out.close()

We ran across this writing S3 objects (in a loop) to a ZipOutputStream that was closed after the first call to body.writeOutputStream(...).

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected behavior

Expecting that writing to a stream does not close it. One may wish to write further data to the stream, as is the case with a ZipOutputStream with multiple entries.

Current behavior

writeOutputStream closes the stream, contradicting the documented behaviour.

Steps to Reproduce

Pass a stream into any ByteStream.writeToOutputStream and check its state after the call.

Possible Solution

Wrap in some form of close-suppressing sink, or a close-suppressing OutputStream.

We worked around this by doing body.toInputStream().copyTo(outputStream) (which isn't great, that InputStream may or may not need to be closed...)

Context

Good for now - pls restore the documented functionality!

AWS SDK for Kotlin version

1.3.52 (unclear where the regression happened, or if this ever worked as documented)

Platform (JVM/JS/Native)

JVM

Operating system and version

any

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.p1This is a high priority issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions