22
22
import software .amazon .awssdk .annotations .SdkInternalApi ;
23
23
import software .amazon .awssdk .core .checksums .SdkChecksum ;
24
24
import software .amazon .awssdk .core .internal .chunked .AwsChunkedEncodingConfig ;
25
- import software .amazon .awssdk .core .io .SdkInputStream ;
26
- import software .amazon .awssdk .utils .Logger ;
27
25
import software .amazon .awssdk .utils .Validate ;
28
26
29
27
/**
37
35
* the wrapped stream.
38
36
*/
39
37
@ SdkInternalApi
40
- public abstract class AwsChunkedEncodingInputStream extends SdkInputStream {
38
+ public abstract class AwsChunkedEncodingInputStream extends AwsChunkedInputStream {
41
39
42
- public static final int DEFAULT_CHUNK_SIZE = 128 * 1024 ;
43
- protected static final int SKIP_BUFFER_SIZE = 256 * 1024 ;
44
40
protected static final String CRLF = "\r \n " ;
45
41
protected static final byte [] FINAL_CHUNK = new byte [0 ];
46
42
protected static final String HEADER_COLON_SEPARATOR = ":" ;
47
- private static final Logger log = Logger .loggerFor (AwsChunkedEncodingInputStream .class );
48
43
protected byte [] calculatedChecksum = null ;
49
44
protected final String checksumHeaderForTrailer ;
50
45
protected boolean isTrailingTerminated = true ;
51
- private InputStream is = null ;
52
46
private final int chunkSize ;
53
47
private final int maxBufferSize ;
54
48
private final SdkChecksum sdkChecksum ;
55
49
private boolean isLastTrailingCrlf ;
56
- /**
57
- * Iterator on the current chunk.
58
- */
59
- private ChunkContentIterator currentChunkIterator ;
60
-
61
- /**
62
- * Iterator on the buffer of the decoded stream,
63
- * Null if the wrapped stream is marksupported,
64
- * otherwise it will be initialized when this wrapper is marked.
65
- */
66
- private DecodedStreamBuffer decodedStreamBuffer ;
67
-
68
- private boolean isAtStart = true ;
69
- private boolean isTerminating = false ;
70
-
71
50
72
51
/**
73
52
* Creates a chunked encoding input stream initialized with the originating stream. The configuration allows
@@ -89,10 +68,10 @@ protected AwsChunkedEncodingInputStream(InputStream in,
89
68
AwsChunkedEncodingInputStream originalChunkedStream = (AwsChunkedEncodingInputStream ) in ;
90
69
providedMaxBufferSize = Math .max (originalChunkedStream .maxBufferSize , providedMaxBufferSize );
91
70
is = originalChunkedStream .is ;
92
- decodedStreamBuffer = originalChunkedStream .decodedStreamBuffer ;
71
+ underlyingStreamBuffer = originalChunkedStream .underlyingStreamBuffer ;
93
72
} else {
94
73
is = in ;
95
- decodedStreamBuffer = null ;
74
+ underlyingStreamBuffer = null ;
96
75
}
97
76
this .chunkSize = awsChunkedEncodingConfig .chunkSize ();
98
77
this .maxBufferSize = providedMaxBufferSize ;
@@ -153,19 +132,6 @@ public T checksumHeaderForTrailer(String checksumHeaderForTrailer) {
153
132
154
133
}
155
134
156
- @ Override
157
- public int read () throws IOException {
158
- byte [] tmp = new byte [1 ];
159
- int count = read (tmp , 0 , 1 );
160
- if (count > 0 ) {
161
- log .debug (() -> "One byte read from the stream." );
162
- int unsignedByte = (int ) tmp [0 ] & 0xFF ;
163
- return unsignedByte ;
164
- } else {
165
- return count ;
166
- }
167
- }
168
-
169
135
@ Override
170
136
public int read (byte [] b , int off , int len ) throws IOException {
171
137
abortIfNeeded ();
@@ -211,32 +177,6 @@ private boolean setUpTrailingChunks() {
211
177
return true ;
212
178
}
213
179
214
- @ Override
215
- public long skip (long n ) throws IOException {
216
- if (n <= 0 ) {
217
- return 0 ;
218
- }
219
- long remaining = n ;
220
- int toskip = (int ) Math .min (SKIP_BUFFER_SIZE , n );
221
- byte [] temp = new byte [toskip ];
222
- while (remaining > 0 ) {
223
- int count = read (temp , 0 , toskip );
224
- if (count < 0 ) {
225
- break ;
226
- }
227
- remaining -= count ;
228
- }
229
- return n - remaining ;
230
- }
231
-
232
- /**
233
- * @see java.io.InputStream#markSupported()
234
- */
235
- @ Override
236
- public boolean markSupported () {
237
- return true ;
238
- }
239
-
240
180
/**
241
181
* The readlimit parameter is ignored.
242
182
*/
@@ -256,7 +196,7 @@ public void mark(int readlimit) {
256
196
} else {
257
197
log .debug (() -> "AwsChunkedEncodingInputStream marked at the start of the stream "
258
198
+ "(initializing the buffer since the wrapped stream is not mark-supported)." );
259
- decodedStreamBuffer = new DecodedStreamBuffer (maxBufferSize );
199
+ underlyingStreamBuffer = new UnderlyingStreamBuffer (maxBufferSize );
260
200
}
261
201
}
262
202
@@ -280,8 +220,8 @@ public void reset() throws IOException {
280
220
is .reset ();
281
221
} else {
282
222
log .debug (() -> "AwsChunkedEncodingInputStream reset (will use the buffer of the decoded stream)." );
283
- Validate .notNull (decodedStreamBuffer , "Cannot reset the stream because the mark is not set." );
284
- decodedStreamBuffer .startReadBuffer ();
223
+ Validate .notNull (underlyingStreamBuffer , "Cannot reset the stream because the mark is not set." );
224
+ underlyingStreamBuffer .startReadBuffer ();
285
225
}
286
226
isAtStart = true ;
287
227
isTerminating = false ;
@@ -298,14 +238,14 @@ private boolean setUpNextChunk() throws IOException {
298
238
int chunkSizeInBytes = 0 ;
299
239
while (chunkSizeInBytes < chunkSize ) {
300
240
/** Read from the buffer of the decoded stream */
301
- if (null != decodedStreamBuffer && decodedStreamBuffer .hasNext ()) {
302
- chunkData [chunkSizeInBytes ++] = decodedStreamBuffer .next ();
241
+ if (null != underlyingStreamBuffer && underlyingStreamBuffer .hasNext ()) {
242
+ chunkData [chunkSizeInBytes ++] = underlyingStreamBuffer .next ();
303
243
} else { /** Read from the wrapped stream */
304
244
int bytesToRead = chunkSize - chunkSizeInBytes ;
305
245
int count = is .read (chunkData , chunkSizeInBytes , bytesToRead );
306
246
if (count != -1 ) {
307
- if (null != decodedStreamBuffer ) {
308
- decodedStreamBuffer .buffer (chunkData , chunkSizeInBytes , count );
247
+ if (null != underlyingStreamBuffer ) {
248
+ underlyingStreamBuffer .buffer (chunkData , chunkSizeInBytes , count );
309
249
}
310
250
chunkSizeInBytes += count ;
311
251
} else {
@@ -333,13 +273,6 @@ private boolean setUpNextChunk() throws IOException {
333
273
}
334
274
}
335
275
336
-
337
- @ Override
338
- protected InputStream getWrappedInputStream () {
339
- return is ;
340
- }
341
-
342
-
343
276
/**
344
277
* The final chunk.
345
278
*
@@ -361,5 +294,4 @@ protected InputStream getWrappedInputStream() {
361
294
* @return ChecksumChunkHeader in bytes based on the Header name field.
362
295
*/
363
296
protected abstract byte [] createChecksumChunkHeader ();
364
-
365
- }
297
+ }
0 commit comments