Class AwsChunkedEncodingInputStream
- java.lang.Object
-
- java.io.InputStream
-
- software.amazon.awssdk.core.io.SdkInputStream
-
- software.amazon.awssdk.core.internal.io.AwsChunkedInputStream
-
- software.amazon.awssdk.core.internal.io.AwsChunkedEncodingInputStream
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Releasable
- Direct Known Subclasses:
AwsUnsignedChunkedEncodingInputStream
public abstract class AwsChunkedEncodingInputStream extends AwsChunkedInputStream
A wrapper of InputStream that implements pseudo-chunked-encoding. Each chunk will be buffered for the calculation of the chunk signature which is added at the head of each chunk.
The default chunk size cannot be customized, since we need to calculate the expected encoded stream length before reading the wrapped stream.
This class will use the mark() & reset() of the wrapped InputStream if they are supported, otherwise it will create a buffer for bytes read from the wrapped stream.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAwsChunkedEncodingInputStream.Builder<T extends AwsChunkedEncodingInputStream.Builder>
-
Field Summary
Fields Modifier and Type Field Description protected byte[]calculatedChecksumprotected StringchecksumHeaderForTrailerprotected static StringCRLFprotected static byte[]FINAL_CHUNKprotected static StringHEADER_COLON_SEPARATORprotected booleanisTrailingTerminated-
Fields inherited from class software.amazon.awssdk.core.internal.io.AwsChunkedInputStream
currentChunkIterator, DEFAULT_CHUNK_SIZE, is, isAtStart, isTerminating, log, SKIP_BUFFER_SIZE, underlyingStreamBuffer
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAwsChunkedEncodingInputStream(InputStream in, SdkChecksum sdkChecksum, String checksumHeaderForTrailer, AwsChunkedEncodingConfig config)Creates a chunked encoding input stream initialized with the originating stream.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract byte[]createChecksumChunkHeader()protected abstract byte[]createChunk(byte[] chunkData)Creates chunk for the given buffer.protected abstract byte[]createFinalChunk(byte[] finalChunk)The final chunk.voidmark(int readlimit)The readlimit parameter is ignored.intread(byte[] b, int off, int len)voidreset()Reset the stream, either by resetting the wrapped stream or using the buffer created by this class.-
Methods inherited from class software.amazon.awssdk.core.internal.io.AwsChunkedInputStream
getWrappedInputStream, markSupported, read, skip
-
Methods inherited from class software.amazon.awssdk.core.io.SdkInputStream
abort, abortIfNeeded, release
-
Methods inherited from class java.io.InputStream
available, close, read
-
-
-
-
Field Detail
-
CRLF
protected static final String CRLF
- See Also:
- Constant Field Values
-
FINAL_CHUNK
protected static final byte[] FINAL_CHUNK
-
HEADER_COLON_SEPARATOR
protected static final String HEADER_COLON_SEPARATOR
- See Also:
- Constant Field Values
-
calculatedChecksum
protected byte[] calculatedChecksum
-
checksumHeaderForTrailer
protected final String checksumHeaderForTrailer
-
isTrailingTerminated
protected boolean isTrailingTerminated
-
-
Constructor Detail
-
AwsChunkedEncodingInputStream
protected AwsChunkedEncodingInputStream(InputStream in, SdkChecksum sdkChecksum, String checksumHeaderForTrailer, AwsChunkedEncodingConfig config)
Creates a chunked encoding input stream initialized with the originating stream. The configuration allows specification of the size of each chunk, as well as the buffer size. Use the same values as when calculating total length of the stream.- Parameters:
in- The original InputStream.config- The configuration allows the user to customize chunk size and buffer size. SeeAwsChunkedEncodingConfigfor default values.
-
-
Method Detail
-
read
public int read(byte[] b, int off, int len) throws IOException- Overrides:
readin classInputStream- Throws:
IOException
-
mark
public void mark(int readlimit)
The readlimit parameter is ignored.- Overrides:
markin classInputStream
-
reset
public void reset() throws IOExceptionReset the stream, either by resetting the wrapped stream or using the buffer created by this class.- Overrides:
resetin classInputStream- Throws:
IOException
-
createFinalChunk
protected abstract byte[] createFinalChunk(byte[] finalChunk)
The final chunk.- Parameters:
finalChunk- The last byte which will be often 0 byte.- Returns:
- Final chunk that will be appended with CRLF or any required signatures.
-
createChunk
protected abstract byte[] createChunk(byte[] chunkData)
Creates chunk for the given buffer. The chucks could be appended with Signatures or any additional bytes by Concrete classes.- Parameters:
chunkData- The chunk of original data.- Returns:
- Chunked data which will have signature if signed or just data if unsigned.
-
createChecksumChunkHeader
protected abstract byte[] createChecksumChunkHeader()
- Returns:
- ChecksumChunkHeader in bytes based on the Header name field.
-
-