ZsyncUtil { public static String computeSha1(ReadableByteChannel channel) throws IOException { final MessageDigest sha1 = newSHA1(); final ByteBuffer buf = ByteBuffer.allocate(8192); while (channel.read(buf) != -1) { buf.flip(); sha1.update(buf); buf.clear(); } return toHexString(ByteBuffer.wrap(sha1.digest())); }  static String toHexString(ByteBuffer buffer); static int computeRsum(byte[] block); static int toInt(short x, short y); static long toLong(int x, int y); static short unsigned(byte b); static String computeSha1(ReadableByteChannel channel); static MessageDigest newMD4(); static MessageDigest newSHA1(); static Path getPath(URI uri);  }
@Test public void testComputeSha1() throws IOException { final byte[] buf = new byte[] {0, 1, 2, 3, 4, 5, 6, 7}; ReadableByteChannel c = Channels.newChannel(new ByteArrayInputStream(buf)); assertEquals("67423ebfa8454f19ac6f4686d6c0dc731a3ddd6b", ZsyncUtil.computeSha1(c));; }