Example usage for com.amazonaws ResetException ResetException

List of usage examples for com.amazonaws ResetException ResetException

Introduction

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

Prototype

public ResetException(String message, Throwable t) 

Source Link

Usage

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 a2s  . c  om*/
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;
}