Example usage for com.amazonaws SignableRequest getContent

List of usage examples for com.amazonaws SignableRequest getContent

Introduction

In this page you can find the example usage for com.amazonaws SignableRequest getContent.

Prototype

InputStream getContent();

Source Link

Document

Returns the optional stream containing the payload data to include for this request.

Usage

From source file:com.ibm.og.s3.v4.AWSS3V4Signer.java

License:Open Source License

/**
 * If necessary, creates a chunk-encoding wrapper on the request payload.
 *///ww w .  jav  a 2 s .  com
@Override
protected void processRequestPayload(final SignableRequest<?> request, final byte[] signature,
        final byte[] signingKey, final AWS4SignerRequestParams signerRequestParams) {
    if (useChunkEncoding(request)) {
        final AwsChunkedEncodingInputStream chunkEncodededStream = new AwsChunkedEncodingInputStream(
                request.getContent(), signingKey, signerRequestParams.getFormattedSigningDateTime(),
                signerRequestParams.getScope(), BinaryUtils.toHex(signature), this, this.digestCache);
        request.setContent(chunkEncodededStream);
    }
}

From source file:com.ibm.og.s3.v4.AWSS3V4Signer.java

License:Open Source License

/**
 * Read the content of the request to get the length of the stream. This method will wrap the
 * stream by SdkBufferedInputStream if it is not mark-supported.
 *//* w w w  .  jav  a  2 s .  c o  m*/
static long getContentLength(final SignableRequest<?> request) throws IOException {
    final InputStream content = request.getContent();
    if (!content.markSupported()) {
        throw new IllegalStateException(
                "Bug: request input stream must have been made mark-and-resettable at this point");
    }
    final ReadLimitInfo info = request.getReadLimitInfo();
    final int readLimit = info.getReadLimit();
    long contentLength = 0;
    final byte[] tmp = new byte[4096];
    int read;
    content.mark(readLimit);
    while ((read = content.read(tmp)) != -1) {
        contentLength += read;
    }
    try {
        content.reset();
    } catch (final IOException ex) {
        throw new ResetException("Failed to reset the input stream", ex);
    }
    return contentLength;
}