private void openStream ( ) throws IOException { if ( mIn != null ) { // stream is already open return ; } GetObjectRequest getReq = new GetObjectRequest ( mBucketName , mKey ) ; // If the position is 0, setting range is redundant and causes an error if the file is 0 length if ( mPos > 0 ) { getReq . setRange ( mPos ) ; } AmazonS3Exception lastException = null ; while ( mRetryPolicy . attempt ( ) ) { try { mIn = mClient . getObject ( getReq ) . getObjectContent ( ) ; return ; } catch ( AmazonS3Exception e ) { LOG . warn ( "Attempt {} to open key {} in bucket {} failed with exception : {}" , mRetryPolicy . getAttemptCount ( ) , mKey , mBucketName , e . toString ( ) ) ; if ( e . getStatusCode ( ) != HttpStatus . SC_NOT_FOUND ) { throw new IOException ( e ) ; } // Key does not exist lastException = e ; } } // Failed after retrying key does not exist throw new IOException ( lastException ) ; }
Opens a new stream at mPos if the wrapped stream mIn is null .