List of usage examples for com.amazonaws ReadLimitInfo getReadLimit
public int getReadLimit();
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. *//*from w w w . jav a 2 s . co 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; }