Class AwsChecksumInputStream

java.lang.Object
java.io.InputStream
com.adobe.testing.s3mock.util.AwsChecksumInputStream
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
AwsChunkedDecodingChecksumInputStream

public class AwsChecksumInputStream extends InputStream
Reads checksum from incoming stream. When the AWS client sends a checksum in the request, it's embedded into the request body and surrounds the payload. The stream looks like this:
 24
 ## sample test file ##

 demo=content
 0
 x-amz-checksum-sha1:+AXXQmKfnxMv0B57SJutbNpZBww=
 
The format is this:
 [hex-encoded-number-of-bytes-in-payload][crlf]
 [payload-bytes]
 0[crlf]
 [amazon-checksum-header]:[checksum][crlf]
 
  • Field Details

    • CHECKSUM_HEADER

      protected static final byte[] CHECKSUM_HEADER
    • checksum

      protected String checksum
    • algorithm

      protected ChecksumAlgorithm algorithm
    • CRLF

      protected static final byte[] CRLF
    • DELIMITER

      protected static final byte[] DELIMITER
    • source

      protected final InputStream source
    • payloadLength

      protected long payloadLength
  • Constructor Details

    • AwsChecksumInputStream

      public AwsChecksumInputStream(InputStream source)
  • Method Details

    • read

      public int read() throws IOException
      Specified by:
      read in class InputStream
      Throws:
      IOException
    • extractAlgorithmAndChecksum

      protected void extractAlgorithmAndChecksum() throws IOException
      Throws:
      IOException
    • getChecksum

      public String getChecksum()
    • getAlgorithm

      public ChecksumAlgorithm getAlgorithm()
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InputStream
      Throws:
      IOException
    • readUntil

      protected byte[] readUntil(byte[] endSequence) throws IOException
      Reads this stream until the byte sequence was found.
      Parameters:
      endSequence - The byte sequence to look for in the stream. The source stream is read until the last bytes read are equal to this sequence.
      Returns:
      The bytes read before the end sequence started.
      Throws:
      IOException
    • endsWith

      protected boolean endsWith(ByteBuffer buffer, byte[] endSequence)
    • setPayloadLength

      protected void setPayloadLength(byte[] hexLengthBytes)