2222import software .amazon .awssdk .annotations .SdkInternalApi ;
2323import software .amazon .awssdk .core .checksums .SdkChecksum ;
2424import software .amazon .awssdk .core .internal .chunked .AwsChunkedEncodingConfig ;
25- import software .amazon .awssdk .core .io .SdkInputStream ;
26- import software .amazon .awssdk .utils .Logger ;
2725import software .amazon .awssdk .utils .Validate ;
2826
2927/**
3735 * the wrapped stream.
3836 */
3937@ SdkInternalApi
40- public abstract class AwsChunkedEncodingInputStream extends SdkInputStream {
38+ public abstract class AwsChunkedEncodingInputStream extends AwsChunkedInputStream {
4139
42- public static final int DEFAULT_CHUNK_SIZE = 128 * 1024 ;
43- protected static final int SKIP_BUFFER_SIZE = 256 * 1024 ;
4440 protected static final String CRLF = "\r \n " ;
4541 protected static final byte [] FINAL_CHUNK = new byte [0 ];
4642 protected static final String HEADER_COLON_SEPARATOR = ":" ;
47- private static final Logger log = Logger .loggerFor (AwsChunkedEncodingInputStream .class );
4843 protected byte [] calculatedChecksum = null ;
4944 protected final String checksumHeaderForTrailer ;
5045 protected boolean isTrailingTerminated = true ;
51- private InputStream is = null ;
5246 private final int chunkSize ;
5347 private final int maxBufferSize ;
5448 private final SdkChecksum sdkChecksum ;
5549 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-
7150
7251 /**
7352 * Creates a chunked encoding input stream initialized with the originating stream. The configuration allows
@@ -89,10 +68,10 @@ protected AwsChunkedEncodingInputStream(InputStream in,
8968 AwsChunkedEncodingInputStream originalChunkedStream = (AwsChunkedEncodingInputStream ) in ;
9069 providedMaxBufferSize = Math .max (originalChunkedStream .maxBufferSize , providedMaxBufferSize );
9170 is = originalChunkedStream .is ;
92- decodedStreamBuffer = originalChunkedStream .decodedStreamBuffer ;
71+ underlyingStreamBuffer = originalChunkedStream .underlyingStreamBuffer ;
9372 } else {
9473 is = in ;
95- decodedStreamBuffer = null ;
74+ underlyingStreamBuffer = null ;
9675 }
9776 this .chunkSize = awsChunkedEncodingConfig .chunkSize ();
9877 this .maxBufferSize = providedMaxBufferSize ;
@@ -153,19 +132,6 @@ public T checksumHeaderForTrailer(String checksumHeaderForTrailer) {
153132
154133 }
155134
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-
169135 @ Override
170136 public int read (byte [] b , int off , int len ) throws IOException {
171137 abortIfNeeded ();
@@ -211,32 +177,6 @@ private boolean setUpTrailingChunks() {
211177 return true ;
212178 }
213179
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-
240180 /**
241181 * The readlimit parameter is ignored.
242182 */
@@ -256,7 +196,7 @@ public void mark(int readlimit) {
256196 } else {
257197 log .debug (() -> "AwsChunkedEncodingInputStream marked at the start of the stream "
258198 + "(initializing the buffer since the wrapped stream is not mark-supported)." );
259- decodedStreamBuffer = new DecodedStreamBuffer (maxBufferSize );
199+ underlyingStreamBuffer = new UnderlyingStreamBuffer (maxBufferSize );
260200 }
261201 }
262202
@@ -280,8 +220,8 @@ public void reset() throws IOException {
280220 is .reset ();
281221 } else {
282222 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 ();
285225 }
286226 isAtStart = true ;
287227 isTerminating = false ;
@@ -298,14 +238,14 @@ private boolean setUpNextChunk() throws IOException {
298238 int chunkSizeInBytes = 0 ;
299239 while (chunkSizeInBytes < chunkSize ) {
300240 /** 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 ();
303243 } else { /** Read from the wrapped stream */
304244 int bytesToRead = chunkSize - chunkSizeInBytes ;
305245 int count = is .read (chunkData , chunkSizeInBytes , bytesToRead );
306246 if (count != -1 ) {
307- if (null != decodedStreamBuffer ) {
308- decodedStreamBuffer .buffer (chunkData , chunkSizeInBytes , count );
247+ if (null != underlyingStreamBuffer ) {
248+ underlyingStreamBuffer .buffer (chunkData , chunkSizeInBytes , count );
309249 }
310250 chunkSizeInBytes += count ;
311251 } else {
@@ -333,13 +273,6 @@ private boolean setUpNextChunk() throws IOException {
333273 }
334274 }
335275
336-
337- @ Override
338- protected InputStream getWrappedInputStream () {
339- return is ;
340- }
341-
342-
343276 /**
344277 * The final chunk.
345278 *
@@ -361,5 +294,4 @@ protected InputStream getWrappedInputStream() {
361294 * @return ChecksumChunkHeader in bytes based on the Header name field.
362295 */
363296 protected abstract byte [] createChecksumChunkHeader ();
364-
365- }
297+ }
0 commit comments