code: public static String calculateTreeHash(InputStream input)
              throws AmazonClientException {
          try {
              TreeHashInputStream treeHashInputStream =
                  new TreeHashInputStream(input);
              byte[] buffer = new byte[1024];
              while (treeHashInputStream.read(buffer, 0, buffer.length) != -1);
              // closing is currently required to compute the checksum 
              treeHashInputStream.close();
              return calculateTreeHash(treeHashInputStream.getChecksums());
          } catch (Exception e) {
              throw new AmazonClientException("Unable to compute hash", e);
          }
      }
docs: Calculates a hex encoded binary hash using a tree hashing algorithm for
  the data in the specified input stream. The method will consume all the
  inputStream and close it when returned.
  
  @param input
  The input stream containing the data to hash.
  
  @return The hex encoded binary tree hash for the data in the specified
  input stream.
  
  @throws AmazonClientException
  If problems were encountered reading the data or calculating
  the hash.