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 class
AwsChunkedEncodingInputStream.Builder<T extends AwsChunkedEncodingInputStream.Builder>
-
Field Summary
Fields Modifier and Type Field Description protected byte[]
calculatedChecksum
protected String
checksumHeaderForTrailer
protected static String
CRLF
protected static byte[]
FINAL_CHUNK
protected static String
HEADER_COLON_SEPARATOR
protected boolean
isTrailingTerminated
-
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 protected
AwsChunkedEncodingInputStream(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.void
mark(int readlimit)
The readlimit parameter is ignored.int
read(byte[] b, int off, int len)
void
reset()
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. SeeAwsChunkedEncodingConfig
for default values.
-
-
Method Detail
-
read
public int read(byte[] b, int off, int len) throws IOException
- Overrides:
read
in classInputStream
- Throws:
IOException
-
mark
public void mark(int readlimit)
The readlimit parameter is ignored.- Overrides:
mark
in classInputStream
-
reset
public void reset() throws IOException
Reset the stream, either by resetting the wrapped stream or using the buffer created by this class.- Overrides:
reset
in 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.
-
-