public class BufferUtils extends Object
Buffer parent buffer type. It resolves issues with covariant return types in Java 9+ for
ByteBuffer and CharBuffer. Explicit casting resolves the NoSuchMethodErrors (e.g
java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip(I)Ljava/nio/ByteBuffer) when the project is compiled with
newer Java version and run on Java 8.
Java 8 doesn't provide override the
following Buffer methods in subclasses:
Buffer clear() Buffer flip() Buffer limit(int newLimit) Buffer mark() Buffer position(int newPosition) Buffer reset() Buffer rewind()Java 9 introduces the overrides in child classes (e.g the ByteBuffer), but the return type is the specialized one and not the abstract
Buffer.
So the code compiled with newer Java is not working on Java 8 unless a workaround with explicit casting is used.| Constructor and Description |
|---|
BufferUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
clear(Buffer buffer) |
static void |
flip(Buffer buffer) |
static void |
limit(Buffer buffer,
int newLimit) |
static void |
mark(Buffer buffer) |
static void |
position(Buffer buffer,
int newPosition) |
static void |
reset(Buffer buffer) |
static void |
rewind(Buffer buffer) |
public static void flip(Buffer buffer)
buffer - byteBufferpublic static void clear(Buffer buffer)
buffer - byteBufferpublic static void limit(Buffer buffer, int newLimit)
buffer - byteBufferpublic static void mark(Buffer buffer)
buffer - byteBufferpublic static void position(Buffer buffer, int newPosition)
buffer - byteBufferpublic static void rewind(Buffer buffer)
buffer - byteBufferpublic static void reset(Buffer buffer)
buffer - byteBufferCopyright © 2024. All rights reserved.