List of usage examples for com.google.common.hash HashingInputStream close
public void close() throws IOException
From source file:org.swiftexplorer.util.FileUtils.java
public static String readAllAndgetMD5(InputStream in) throws IOException { com.google.common.hash.HashingInputStream his = null; try {/*from w ww .ja va 2 s .c o m*/ his = new com.google.common.hash.HashingInputStream(Hashing.md5(), in); final int bufferSize = 2097152; final ReadableByteChannel inputChannel = Channels.newChannel(his); final ByteBuffer buffer = ByteBuffer.allocateDirect(bufferSize); while (inputChannel.read(buffer) != -1) { buffer.clear(); } /* byte[] bytesBuffer = new byte[bufferSize] ; int r = his.read(bytesBuffer, 0, bufferSize) ; while (r != -1) r = his.read(bytesBuffer) ; */ HashCode hc = his.hash(); return (hc != null) ? (hc.toString()) : (null); } finally { if (his != null) his.close(); } }