Class AwsChunkedEncodingInputStream

All Implemented Interfaces:
Closeable, AutoCloseable, Releasable
Direct Known Subclasses:
AwsUnsignedChunkedEncodingInputStream

@SdkInternalApi 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.
  • Field Details

    • CRLF

      protected static final String CRLF
      See Also:
    • FINAL_CHUNK

      protected static final byte[] FINAL_CHUNK
    • HEADER_COLON_SEPARATOR

      protected static final String HEADER_COLON_SEPARATOR
      See Also:
    • calculatedChecksum

      protected byte[] calculatedChecksum
    • checksumHeaderForTrailer

      protected final String checksumHeaderForTrailer
    • isTrailingTerminated

      protected boolean isTrailingTerminated
  • Constructor Details

    • AwsChunkedEncodingInputStream

      protected AwsChunkedEncodingInputStream(InputStream in, ChecksumAlgorithm checksumAlgorithm, SdkChecksum sdkChecksum, PayloadChecksumStore checksumStore, 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. See AwsChunkedEncodingConfig for default values.
  • Method Details

    • read

      public int read(byte[] b, int off, int len) throws IOException
      Overrides:
      read in class InputStream
      Throws:
      IOException
    • mark

      public void mark(int readlimit)
      The readlimit parameter is ignored.
      Overrides:
      mark in class InputStream
    • 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 class InputStream
      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.