Skip to content

Commit 418c559

Browse files
committed
Preserve content-length when calling mark in SdkLengthAwareInputStream
1 parent 0e00199 commit 418c559

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "AWS SDK for Java v2",
4+
"contributor": "",
5+
"description": "Preserve the initial content-length when calling mark in SdkLengthAwareInputStream."
6+
}

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/io/SdkLengthAwareInputStream.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
@SdkInternalApi
3333
public class SdkLengthAwareInputStream extends FilterInputStream {
3434
private static final Logger LOG = Logger.loggerFor(SdkLengthAwareInputStream.class);
35-
private long length;
35+
private final long length;
3636
private long remaining;
37+
private long markedRemaining;
3738

3839
public SdkLengthAwareInputStream(InputStream in, long length) {
3940
super(in);
@@ -104,15 +105,14 @@ public int available() throws IOException {
104105
@Override
105106
public void mark(int readlimit) {
106107
super.mark(readlimit);
107-
// mark() causes reset() to change the stream's position back to the current position. Therefore, when reset() is called,
108-
// the new length of the stream will be equal to the current value of 'remaining'.
109-
length = remaining;
108+
// Store the current remaining bytes to restore on reset()
109+
markedRemaining = remaining;
110110
}
111111

112112
@Override
113113
public void reset() throws IOException {
114114
super.reset();
115-
remaining = length;
115+
remaining = markedRemaining;
116116
}
117117

118118
public long remaining() {

0 commit comments

Comments
 (0)