/** * This method is a shorthand for {@link #readUntilEOF(java.io.InputStream, int)} called with a * {@link BufferPool#getDefaultBufferSize default buffer size}. * * @param in the InputStream to read * @throws IOException if an I/O error occurs */ public static void readUntilEOF(InputStream in) throws IOException { readUntilEOF(in, BufferPool.getDefaultBufferSize()); }
private void assertReadable(InputStream in) throws IOException { assert in != null; StreamUtils.readUntilEOF(in); in.close(); }
private void assertReadable(URL url) throws IOException { assert url != null; InputStream in = url.openStream(); StreamUtils.readUntilEOF(in); in.close(); }
/** * Returns the checksum (also referred to as <i>hash</i> or <i>digest</i>) of the given <code>InputStream</code> * calculated by reading the stream and feeding the bytes to the given <code>MessageDigest</code> until EOF is * reached. * * <p><b>Important:</b> this method does not close the <code>InputStream</code>, and does not reset the * <code>MessageDigest</code> after the checksum has been calculated.</p> * * @param in the InputStream for which to calculate the checksum * @param messageDigest the MessageDigest to use for calculating the checksum * @return the given InputStream's checksum, as an hexadecimal string * @throws IOException if an I/O error occurred while calculating the checksum */ public static String calculateChecksum(InputStream in, MessageDigest messageDigest) throws IOException { ChecksumInputStream cin = new ChecksumInputStream(in, messageDigest); try { StreamUtils.readUntilEOF(cin); return cin.getChecksumString(); } catch(IOException e) { throw new FileTransferException(FileTransferError.READING_SOURCE); } }