--- old/src/java.base/share/classes/java/util/zip/Adler32.java 2014-10-21 11:27:08.504850583 -0700 +++ new/src/java.base/share/classes/java/util/zip/Adler32.java 2014-10-21 11:27:08.356850589 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -34,9 +34,8 @@ * can be computed much faster. * *

Passing a {@code null} argument to a method in this class will cause - * a {@link NullPointerException} to be thrown. + * a {@link NullPointerException} to be thrown.

* - * @see Checksum * @author David Connelly */ public @@ -53,9 +52,8 @@ /** * Updates the checksum with the specified byte (the low eight * bits of the argument b). - * - * @param b the byte to update the checksum with */ + @Override public void update(int b) { adler = update(adler, b); } @@ -63,11 +61,12 @@ /** * Updates the checksum with the specified array of bytes. * - * @throws ArrayIndexOutOfBoundsException - * if {@code off} is negative, or {@code len} is negative, - * or {@code off+len} is greater than the length of the - * array {@code b} + * @throws ArrayIndexOutOfBoundsException + * if {@code off} is negative, or {@code len} is negative, or + * {@code off+len} is negative or greater than the length of + * the array {@code b}. */ + @Override public void update(byte[] b, int off, int len) { if (b == null) { throw new NullPointerException(); @@ -79,28 +78,15 @@ } /** - * Updates the checksum with the specified array of bytes. - * - * @param b the byte array to update the checksum with - */ - public void update(byte[] b) { - adler = updateBytes(adler, b, 0, b.length); - } - - - /** * Updates the checksum with the bytes from the specified buffer. * - * The checksum is updated using - * buffer.{@link java.nio.Buffer#remaining() remaining()} - * bytes starting at - * buffer.{@link java.nio.Buffer#position() position()} - * Upon return, the buffer's position will be updated to its - * limit; its limit will not have been changed. + * The checksum is updated with the remaining bytes in the buffer, starting + * at the buffer's position. Upon return, the buffer's position will be + * updated to its limit; its limit will not have been changed. * - * @param buffer the ByteBuffer to update the checksum with * @since 1.8 */ + @Override public void update(ByteBuffer buffer) { int pos = buffer.position(); int limit = buffer.limit(); @@ -123,6 +109,7 @@ /** * Resets the checksum to initial value. */ + @Override public void reset() { adler = 1; } @@ -130,6 +117,7 @@ /** * Returns the checksum value. */ + @Override public long getValue() { return (long)adler & 0xffffffffL; } --- old/src/java.base/share/classes/java/util/zip/CRC32.java 2014-10-21 11:27:08.908850569 -0700 +++ new/src/java.base/share/classes/java/util/zip/CRC32.java 2014-10-21 11:27:08.760850574 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -32,9 +32,8 @@ * A class that can be used to compute the CRC-32 of a data stream. * *

Passing a {@code null} argument to a method in this class will cause - * a {@link NullPointerException} to be thrown. + * a {@link NullPointerException} to be thrown.

* - * @see Checksum * @author David Connelly */ public @@ -51,9 +50,8 @@ /** * Updates the CRC-32 checksum with the specified byte (the low * eight bits of the argument b). - * - * @param b the byte to update the checksum with */ + @Override public void update(int b) { crc = update(crc, b); } @@ -61,11 +59,12 @@ /** * Updates the CRC-32 checksum with the specified array of bytes. * - * @throws ArrayIndexOutOfBoundsException - * if {@code off} is negative, or {@code len} is negative, - * or {@code off+len} is greater than the length of the - * array {@code b} + * @throws ArrayIndexOutOfBoundsException + * if {@code off} is negative, or {@code len} is negative, or + * {@code off+len} is negative or greater than the length of + * the array {@code b}. */ + @Override public void update(byte[] b, int off, int len) { if (b == null) { throw new NullPointerException(); @@ -77,27 +76,15 @@ } /** - * Updates the CRC-32 checksum with the specified array of bytes. - * - * @param b the array of bytes to update the checksum with - */ - public void update(byte[] b) { - crc = updateBytes(crc, b, 0, b.length); - } - - /** - * Updates the checksum with the bytes from the specified buffer. + * Updates the CRC-32 checksum with the bytes from the specified buffer. * - * The checksum is updated using - * buffer.{@link java.nio.Buffer#remaining() remaining()} - * bytes starting at - * buffer.{@link java.nio.Buffer#position() position()} - * Upon return, the buffer's position will - * be updated to its limit; its limit will not have been changed. + * The checksum is updated with the remaining bytes in the buffer, starting + * at the buffer's position. Upon return, the buffer's position will be + * updated to its limit; its limit will not have been changed. * - * @param buffer the ByteBuffer to update the checksum with * @since 1.8 */ + @Override public void update(ByteBuffer buffer) { int pos = buffer.position(); int limit = buffer.limit(); @@ -120,6 +107,7 @@ /** * Resets CRC-32 to initial value. */ + @Override public void reset() { crc = 0; } @@ -127,6 +115,7 @@ /** * Returns CRC-32 value. */ + @Override public long getValue() { return (long)crc & 0xffffffffL; } --- old/src/java.base/share/classes/java/util/zip/Checksum.java 2014-10-21 11:27:09.312850555 -0700 +++ new/src/java.base/share/classes/java/util/zip/Checksum.java 2014-10-21 11:27:09.164850560 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1999, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,16 +22,17 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package java.util.zip; +import java.nio.ByteBuffer; + /** * An interface representing a data checksum. * - * @author David Connelly + * @author David Connelly */ -public -interface Checksum { +public interface Checksum { + /** * Updates the current checksum with the specified byte. * @@ -41,6 +42,24 @@ /** * Updates the current checksum with the specified array of bytes. + * + * @implSpec This default implementation is equal to calling + * {@code update(b, 0, b.length)}. + * + * @param b the array of bytes to update the checksum with + * + * @throws NullPointerException + * if {@code b} is {@code null} + * + * @since 1.9 + */ + default public void update(byte[] b) { + update(b, 0, b.length); + } + + /** + * Updates the current checksum with the specified array of bytes. + * * @param b the byte array to update the checksum with * @param off the start offset of the data * @param len the number of bytes to use for the update @@ -48,7 +67,56 @@ public void update(byte[] b, int off, int len); /** + * Updates the current checksum with the bytes from the specified buffer. + * + * The checksum is updated with the remaining bytes in the buffer, starting + * at the buffer's position. Upon return, the buffer's position will be + * updated to its limit; its limit will not have been changed. + * + * @apiNote For best performance with DirectByteBuffer and other ByteBuffer + * implementations without a backing array implementers of this interface + * should override this method. + * + * @implSpec The default implementation has the following behavior.
+ * For ByteBuffers backed by an accessible byte array.
{@code
+     * update(buffer.array(),
+     *        buffer.position() + buffer.arrayOffset(),
+     *        buffer.limit() - buffer.position());
+     * }
For ByteBuffers not backed by an accessible byte array. + *
{@code
+     * byte[] b = new byte[buffer.limit() - buffer.position()];
+     * buffer.get(b);
+     * update(b, 0, b.length);
+     * }
+ * + * @param buffer the ByteBuffer to update the checksum with + * + * @throws NullPointerException + * if {@code buffer} is {@code null} + * + * @since 1.9 + */ + default public void update(ByteBuffer buffer) { + int pos = buffer.position(); + int limit = buffer.limit(); + assert (pos <= limit); + int rem = limit - pos; + if (rem <= 0) { + return; + } + if (buffer.hasArray()) { + update(buffer.array(), pos + buffer.arrayOffset(), rem); + } else { + byte[] b = new byte[rem]; + buffer.get(b); + update(b, 0, b.length); + } + buffer.position(limit); + } + + /** * Returns the current checksum value. + * * @return the current checksum value */ public long getValue(); --- old/src/java.base/share/classes/java/util/zip/package.html 2014-10-21 11:27:09.716850541 -0700 +++ new/src/java.base/share/classes/java/util/zip/package.html 2014-10-21 11:27:09.568850546 -0700 @@ -2,7 +2,7 @@