Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Java 1.8 NoSuchMethodError: java.nio.ByteBuffer.flip() #458

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions caliper-util/src/main/java/com/google/caliper/util/Uuids.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ public final class Uuids {
private Uuids() {}

/** Returns a buffer containing the 16 bytes of the given UUID. */
@SuppressWarnings("RedundantCast")
public static ByteBuffer toBytes(UUID uuid) {
ByteBuffer buf = ByteBuffer.allocate(UUID_BYTES);
buf.putLong(uuid.getMostSignificantBits());
buf.putLong(uuid.getLeastSignificantBits());
buf.flip();
((java.nio.Buffer) buf).flip(); // for Java 1.8 compatibility
return buf;
}

Expand All @@ -57,14 +58,15 @@ public static UUID fromBytes(ByteBuffer buf) {
}

/** Reads the next 16 bytes from the given channel as a UUID. */
@SuppressWarnings("RedundantCast")
public static UUID readFromChannel(ReadableByteChannel channel) throws IOException {
ByteBuffer buf = ByteBuffer.allocate(UUID_BYTES);
while (buf.hasRemaining()) {
if (channel.read(buf) == -1) {
throw new EOFException("unexpected EOF while reading UUID");
}
}
buf.flip();
((java.nio.Buffer) buf).flip(); // for Java 1.8 compatibility
return fromBytes(buf);
}
}