Skip to content

Commit 8013806

Browse files
authored
Rename SdkLengthAwareInputStream to LengthAwareInputStream (#6504)
1 parent 325bfcf commit 8013806

File tree

7 files changed

+41
-41
lines changed

7 files changed

+41
-41
lines changed

core/http-auth-aws/src/main/java/software/amazon/awssdk/http/auth/aws/internal/signer/chunkedencoding/ChunkInputStream.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
import java.io.IOException;
1919
import java.io.InputStream;
2020
import software.amazon.awssdk.annotations.SdkInternalApi;
21-
import software.amazon.awssdk.utils.io.SdkLengthAwareInputStream;
21+
import software.amazon.awssdk.utils.io.LengthAwareInputStream;
2222

2323
/**
2424
* A wrapped stream to represent a "chunk" of data
2525
*/
2626
@SdkInternalApi
27-
public final class ChunkInputStream extends SdkLengthAwareInputStream {
27+
public final class ChunkInputStream extends LengthAwareInputStream {
2828

2929
public ChunkInputStream(InputStream inputStream, long length) {
3030
super(inputStream, length);

core/sdk-core/src/main/java/software/amazon/awssdk/core/async/BlockingInputStreamAsyncRequestBody.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import software.amazon.awssdk.core.internal.util.NoopSubscription;
3030
import software.amazon.awssdk.utils.Validate;
3131
import software.amazon.awssdk.utils.async.InputStreamConsumingPublisher;
32-
import software.amazon.awssdk.utils.io.SdkLengthAwareInputStream;
32+
import software.amazon.awssdk.utils.io.LengthAwareInputStream;
3333

3434
/**
3535
* An implementation of {@link AsyncRequestBody} that allows performing a blocking write of an input stream to a downstream
@@ -89,7 +89,7 @@ public long writeInputStream(InputStream inputStream) {
8989
try {
9090
waitForSubscriptionIfNeeded();
9191
if (contentLength != null) {
92-
return delegate.doBlockingWrite(new SdkLengthAwareInputStream(inputStream, contentLength));
92+
return delegate.doBlockingWrite(new LengthAwareInputStream(inputStream, contentLength));
9393
}
9494

9595
return delegate.doBlockingWrite(inputStream);

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/handler/BaseClientHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
import software.amazon.awssdk.metrics.MetricCollector;
4949
import software.amazon.awssdk.utils.Pair;
5050
import software.amazon.awssdk.utils.StringUtils;
51-
import software.amazon.awssdk.utils.io.SdkLengthAwareInputStream;
51+
import software.amazon.awssdk.utils.io.LengthAwareInputStream;
5252

5353
@SdkInternalApi
5454
public abstract class BaseClientHandler {
@@ -136,7 +136,7 @@ private static RequestBody getBody(SdkHttpFullRequest request) {
136136
ContentStreamProvider streamProvider = contentStreamProviderOptional.get();
137137
if (contentLengthOptional.isPresent()) {
138138
ContentStreamProvider toWrap = contentStreamProviderOptional.get();
139-
streamProvider = () -> new SdkLengthAwareInputStream(toWrap.newStream(), contentLength);
139+
streamProvider = () -> new LengthAwareInputStream(toWrap.newStream(), contentLength);
140140
}
141141

142142
return new SdkInternalOnlyRequestBody(streamProvider,

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/http/pipeline/stages/MakeHttpRequestStage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import software.amazon.awssdk.metrics.MetricCollector;
3939
import software.amazon.awssdk.utils.Logger;
4040
import software.amazon.awssdk.utils.Pair;
41-
import software.amazon.awssdk.utils.io.SdkLengthAwareInputStream;
41+
import software.amazon.awssdk.utils.io.LengthAwareInputStream;
4242

4343
/**
4444
* Delegate to the HTTP implementation to make an HTTP request and receive the response.
@@ -119,8 +119,8 @@ private static SdkHttpFullRequest enforceContentLengthIfPresent(SdkHttpFullReque
119119
}
120120

121121
ContentStreamProvider requestContentProvider = requestContentStreamProviderOptional.get();
122-
ContentStreamProvider lengthVerifyingProvider = () -> new SdkLengthAwareInputStream(requestContentProvider.newStream(),
123-
contentLength.get());
122+
ContentStreamProvider lengthVerifyingProvider = () -> new LengthAwareInputStream(requestContentProvider.newStream(),
123+
contentLength.get());
124124
return request.toBuilder()
125125
.contentStreamProvider(lengthVerifyingProvider)
126126
.build();

core/sdk-core/src/test/java/software/amazon/awssdk/core/internal/http/pipeline/stages/MakeHttpRequestStageTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import software.amazon.awssdk.core.internal.http.HttpClientDependencies;
4141
import software.amazon.awssdk.core.internal.http.RequestExecutionContext;
4242
import software.amazon.awssdk.core.internal.http.timers.TimeoutTracker;
43-
import software.amazon.awssdk.utils.io.SdkLengthAwareInputStream;
43+
import software.amazon.awssdk.utils.io.LengthAwareInputStream;
4444
import software.amazon.awssdk.http.ContentStreamProvider;
4545
import software.amazon.awssdk.http.HttpExecuteRequest;
4646
import software.amazon.awssdk.http.SdkHttpClient;
@@ -135,9 +135,9 @@ public void execute_testLengthChecking(String description,
135135
InputStream requestContentStream = capturedRequest.contentStreamProvider().get().newStream();
136136

137137
if (expectLengthAware) {
138-
assertThat(requestContentStream).isInstanceOf(SdkLengthAwareInputStream.class);
138+
assertThat(requestContentStream).isInstanceOf(LengthAwareInputStream.class);
139139
} else {
140-
assertThat(requestContentStream).isNotInstanceOf(SdkLengthAwareInputStream.class);
140+
assertThat(requestContentStream).isNotInstanceOf(LengthAwareInputStream.class);
141141
}
142142
} else {
143143
assertThat(capturedRequest.contentStreamProvider()).isEmpty();

utils/src/main/java/software/amazon/awssdk/utils/io/SdkLengthAwareInputStream.java renamed to utils/src/main/java/software/amazon/awssdk/utils/io/LengthAwareInputStream.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@
3030
* has less bytes (i.e. reaches EOF) before the expected length is reached, it will throw {@code IOException}.
3131
*/
3232
@SdkProtectedApi
33-
public class SdkLengthAwareInputStream extends FilterInputStream {
34-
private static final Logger LOG = Logger.loggerFor(SdkLengthAwareInputStream.class);
33+
public class LengthAwareInputStream extends FilterInputStream {
34+
private static final Logger LOG = Logger.loggerFor(LengthAwareInputStream.class);
3535
private final long length;
3636
private long remaining;
3737
private long markedRemaining;
3838

39-
public SdkLengthAwareInputStream(InputStream in, long length) {
39+
public LengthAwareInputStream(InputStream in, long length) {
4040
super(in);
4141
this.length = Validate.isNotNegative(length, "length");
4242
this.remaining = this.length;
4343
this.markedRemaining = this.remaining;
4444
}
4545

4646
@Override
47-
public int read() throws IOException {
47+
public final int read() throws IOException {
4848
if (!hasMoreBytes()) {
4949
LOG.debug(() -> String.format("Specified InputStream length of %d has been reached. Returning EOF.", length));
5050
return -1;
@@ -66,7 +66,7 @@ public int read() throws IOException {
6666
}
6767

6868
@Override
69-
public int read(byte[] b, int off, int len) throws IOException {
69+
public final int read(byte[] b, int off, int len) throws IOException {
7070
if (!hasMoreBytes()) {
7171
LOG.debug(() -> String.format("Specified InputStream length of %d has been reached. Returning EOF.", length));
7272
return -1;
@@ -90,33 +90,33 @@ public int read(byte[] b, int off, int len) throws IOException {
9090
}
9191

9292
@Override
93-
public long skip(long requestedBytesToSkip) throws IOException {
93+
public final long skip(long requestedBytesToSkip) throws IOException {
9494
requestedBytesToSkip = Math.min(requestedBytesToSkip, remaining);
9595
long skippedActual = super.skip(requestedBytesToSkip);
9696
remaining -= skippedActual;
9797
return skippedActual;
9898
}
9999

100100
@Override
101-
public int available() throws IOException {
101+
public final int available() throws IOException {
102102
int streamAvailable = super.available();
103103
return Math.min(streamAvailable, saturatedCast(remaining));
104104
}
105105

106106
@Override
107-
public void mark(int readlimit) {
107+
public final void mark(int readlimit) {
108108
super.mark(readlimit);
109109
// Store the current remaining bytes to restore on reset()
110110
markedRemaining = remaining;
111111
}
112112

113113
@Override
114-
public void reset() throws IOException {
114+
public final void reset() throws IOException {
115115
super.reset();
116116
remaining = markedRemaining;
117117
}
118118

119-
public long remaining() {
119+
public final long remaining() {
120120
return remaining;
121121
}
122122

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.junit.jupiter.api.BeforeEach;
2929
import org.junit.jupiter.api.Test;
3030

31-
class SdkLengthAwareInputStreamTest {
31+
class LengthAwareInputStreamTest {
3232
private InputStream delegateStream;
3333

3434
@BeforeEach
@@ -40,7 +40,7 @@ void setup() {
4040
void read_lengthIs0_returnsEof() throws IOException {
4141
when(delegateStream.available()).thenReturn(Integer.MAX_VALUE);
4242

43-
SdkLengthAwareInputStream is = new SdkLengthAwareInputStream(delegateStream, 0);
43+
LengthAwareInputStream is = new LengthAwareInputStream(delegateStream, 0);
4444

4545
assertThat(is.read()).isEqualTo(-1);
4646
assertThat(is.read(new byte[16], 0, 16)).isEqualTo(-1);
@@ -51,7 +51,7 @@ void read_lengthNonZero_delegateEof_returnsEof() throws IOException {
5151
when(delegateStream.read()).thenReturn(-1);
5252
when(delegateStream.read(any(byte[].class), any(int.class), any(int.class))).thenReturn(-1);
5353

54-
SdkLengthAwareInputStream is = new SdkLengthAwareInputStream(delegateStream, 0);
54+
LengthAwareInputStream is = new LengthAwareInputStream(delegateStream, 0);
5555

5656
assertThat(is.read()).isEqualTo(-1);
5757
assertThat(is.read(new byte[16], 0, 16)).isEqualTo(-1);
@@ -61,7 +61,7 @@ void read_lengthNonZero_delegateEof_returnsEof() throws IOException {
6161
void readByte_lengthNonZero_delegateHasAvailable_returnsDelegateData() throws IOException {
6262
when(delegateStream.read()).thenReturn(42);
6363

64-
SdkLengthAwareInputStream is = new SdkLengthAwareInputStream(delegateStream, 16);
64+
LengthAwareInputStream is = new LengthAwareInputStream(delegateStream, 16);
6565

6666
assertThat(is.read()).isEqualTo(42);
6767
}
@@ -70,7 +70,7 @@ void readByte_lengthNonZero_delegateHasAvailable_returnsDelegateData() throws IO
7070
void readArray_lengthNonZero_delegateHasAvailable_returnsDelegateData() throws IOException {
7171
when(delegateStream.read(any(byte[].class), any(int.class), any(int.class))).thenReturn(8);
7272

73-
SdkLengthAwareInputStream is = new SdkLengthAwareInputStream(delegateStream, 16);
73+
LengthAwareInputStream is = new LengthAwareInputStream(delegateStream, 16);
7474

7575
assertThat(is.read(new byte[16], 0, 16)).isEqualTo(8);
7676
}
@@ -79,7 +79,7 @@ void readArray_lengthNonZero_delegateHasAvailable_returnsDelegateData() throws I
7979
void readArray_lengthNonZero_propagatesCallToDelegate() throws IOException {
8080
when(delegateStream.read(any(byte[].class), any(int.class), any(int.class))).thenReturn(8);
8181

82-
SdkLengthAwareInputStream is = new SdkLengthAwareInputStream(delegateStream, 16);
82+
LengthAwareInputStream is = new LengthAwareInputStream(delegateStream, 16);
8383
byte[] buff = new byte[16];
8484
is.read(buff, 0, 16);
8585

@@ -90,7 +90,7 @@ void readArray_lengthNonZero_propagatesCallToDelegate() throws IOException {
9090
void read_markAndReset_availableReflectsNewLength() throws IOException {
9191
delegateStream = new ByteArrayInputStream(new byte[32]);
9292

93-
SdkLengthAwareInputStream is = new SdkLengthAwareInputStream(delegateStream, 16);
93+
LengthAwareInputStream is = new LengthAwareInputStream(delegateStream, 16);
9494

9595
for (int i = 0; i < 4; ++i) {
9696
is.read();
@@ -113,7 +113,7 @@ void read_markAndReset_availableReflectsNewLength() throws IOException {
113113
void skip_markAndReset_availableReflectsNewLength() throws IOException {
114114
delegateStream = new ByteArrayInputStream(new byte[32]);
115115

116-
SdkLengthAwareInputStream is = new SdkLengthAwareInputStream(delegateStream, 16);
116+
LengthAwareInputStream is = new LengthAwareInputStream(delegateStream, 16);
117117

118118
is.skip(4);
119119

@@ -141,7 +141,7 @@ void skip_delegateSkipsLessThanRequested_availableUpdatedCorrectly() throws IOEx
141141

142142
when(delegateStream.read(any(byte[].class), any(int.class), any(int.class))).thenReturn(1);
143143

144-
SdkLengthAwareInputStream is = new SdkLengthAwareInputStream(delegateStream, 16);
144+
LengthAwareInputStream is = new LengthAwareInputStream(delegateStream, 16);
145145

146146
long skipped = is.skip(4);
147147

@@ -156,7 +156,7 @@ void readArray_delegateReadsLessThanRequested_availableUpdatedCorrectly() throws
156156
return n / 2;
157157
});
158158

159-
SdkLengthAwareInputStream is = new SdkLengthAwareInputStream(delegateStream, 16);
159+
LengthAwareInputStream is = new LengthAwareInputStream(delegateStream, 16);
160160

161161
long read = is.read(new byte[16], 0, 8);
162162

@@ -169,7 +169,7 @@ void readArray_delegateShorterThanExpected_throws() {
169169
int delegateLength = 16;
170170
ByteArrayInputStream delegate = new ByteArrayInputStream(new byte[delegateLength]);
171171

172-
SdkLengthAwareInputStream is = new SdkLengthAwareInputStream(delegate, delegateLength + 1);
172+
LengthAwareInputStream is = new LengthAwareInputStream(delegate, delegateLength + 1);
173173

174174
assertThatThrownBy(() -> {
175175
int read;
@@ -186,7 +186,7 @@ void readArray_readExactLength_doesNotThrow() throws IOException {
186186
int delegateLength = 16;
187187
ByteArrayInputStream delegate = new ByteArrayInputStream(new byte[delegateLength]);
188188

189-
SdkLengthAwareInputStream is = new SdkLengthAwareInputStream(delegate, delegateLength);
189+
LengthAwareInputStream is = new LengthAwareInputStream(delegate, delegateLength);
190190

191191
int total = 0;
192192
int read;
@@ -204,7 +204,7 @@ void readArray_delegateLongerThanRequired_truncated() throws IOException {
204204
int length = 16;
205205
ByteArrayInputStream delegate = new ByteArrayInputStream(new byte[delegateLength]);
206206

207-
SdkLengthAwareInputStream is = new SdkLengthAwareInputStream(delegate, length);
207+
LengthAwareInputStream is = new LengthAwareInputStream(delegate, length);
208208

209209
int total = 0;
210210
int read;
@@ -221,7 +221,7 @@ void readByte_delegateShorterThanExpected_throws() {
221221
int delegateLength = 16;
222222
ByteArrayInputStream delegate = new ByteArrayInputStream(new byte[delegateLength]);
223223

224-
SdkLengthAwareInputStream is = new SdkLengthAwareInputStream(delegate, delegateLength + 1);
224+
LengthAwareInputStream is = new LengthAwareInputStream(delegate, delegateLength + 1);
225225

226226
assertThatThrownBy(() -> {
227227
int read;
@@ -237,7 +237,7 @@ void readByte_readExactLength_doesNotThrow() throws IOException {
237237
int delegateLength = 16;
238238
ByteArrayInputStream delegate = new ByteArrayInputStream(new byte[delegateLength]);
239239

240-
SdkLengthAwareInputStream is = new SdkLengthAwareInputStream(delegate, delegateLength);
240+
LengthAwareInputStream is = new LengthAwareInputStream(delegate, delegateLength);
241241

242242
int total = 0;
243243
while (total != delegateLength && is.read() != -1) {
@@ -253,7 +253,7 @@ void readBytePartialThenMark_doesNotResetContentLength() throws IOException {
253253
int expectedContentLength = delegateLength + 1;
254254
ByteArrayInputStream delegate = new ByteArrayInputStream(new byte[delegateLength]);
255255

256-
SdkLengthAwareInputStream is = new SdkLengthAwareInputStream(delegate, expectedContentLength);
256+
LengthAwareInputStream is = new LengthAwareInputStream(delegate, expectedContentLength);
257257
is.read(); // read one byte
258258
is.mark(1024);
259259
// read another byte and reset, the length should not be reset based on the byte that was already read
@@ -274,7 +274,7 @@ void readByte_delegateLongerThanRequired_truncated() throws IOException {
274274
int length = 16;
275275
ByteArrayInputStream delegate = new ByteArrayInputStream(new byte[delegateLength]);
276276

277-
SdkLengthAwareInputStream is = new SdkLengthAwareInputStream(delegate, length);
277+
LengthAwareInputStream is = new LengthAwareInputStream(delegate, length);
278278

279279
int total = 0;
280280
while (total != delegateLength && is.read() != -1) {
@@ -290,7 +290,7 @@ public void skip_thenReadByteUntilEof_doesNotThrowLengthMismatch() throws IOExce
290290

291291
ByteArrayInputStream delegate = new ByteArrayInputStream(new byte[delegateLength]);
292292

293-
SdkLengthAwareInputStream is = new SdkLengthAwareInputStream(delegate, delegateLength);
293+
LengthAwareInputStream is = new LengthAwareInputStream(delegate, delegateLength);
294294

295295
int bytesToSkip = 8;
296296
int skippedBytes = 0;
@@ -315,7 +315,7 @@ public void skip_thenReadArrayUntilEof_doesNotThrowLengthMismatch() throws IOExc
315315

316316
ByteArrayInputStream delegate = new ByteArrayInputStream(new byte[delegateLength]);
317317

318-
SdkLengthAwareInputStream is = new SdkLengthAwareInputStream(delegate, delegateLength);
318+
LengthAwareInputStream is = new LengthAwareInputStream(delegate, delegateLength);
319319

320320
int bytesToSkip = 8;
321321
int skippedBytes = 0;

0 commit comments

Comments
 (0)