diff --git a/src/main/java/net/ladenthin/streambuffer/StreamBuffer.java b/src/main/java/net/ladenthin/streambuffer/StreamBuffer.java index 15bab5af..54ebe7e1 100644 --- a/src/main/java/net/ladenthin/streambuffer/StreamBuffer.java +++ b/src/main/java/net/ladenthin/streambuffer/StreamBuffer.java @@ -28,6 +28,15 @@ public class StreamBuffer implements Closeable { static final String EXCEPTION_MESSAGE_VALIDATE_OFFSET_AND_LENGTH_TO_WRITE_INDEX_OUT_OF_BOUNDS_EXCEPTION = "Invalid offset or length given to validateOffsetAndLengthToWrite."; + /** + * Largest {@code byte[]} length this class allocates: {@code Integer.MAX_VALUE - 8}. + * Same value as {@code jdk.internal.util.ArraysSupport.SOFT_MAX_ARRAY_LENGTH}, mirrored + * because that class is JDK-internal (not exported, absent on Java 8). + * Reason: VMs reserve array header words; HotSpot rejects {@code Integer.MAX_VALUE} and + * {@code Integer.MAX_VALUE - 1} with "Requested array size exceeds VM limit", on any heap size. + */ + static final int MAX_ARRAY_LENGTH = Integer.MAX_VALUE - 8; + /** * An object to get an unique access to the {@link #buffer}. It is needed to * get an exclusive access for read and write operations. @@ -132,15 +141,6 @@ public class StreamBuffer implements Closeable { */ private final AtomicLong totalBytesRead = new AtomicLong(); - /** - * Largest {@code byte[]} length this class allocates: {@code Integer.MAX_VALUE - 8}. - * Same value as {@code jdk.internal.util.ArraysSupport.SOFT_MAX_ARRAY_LENGTH}, mirrored - * because that class is JDK-internal (not exported, absent on Java 8). - * Reason: VMs reserve array header words; HotSpot rejects {@code Integer.MAX_VALUE} and - * {@code Integer.MAX_VALUE - 1} with "Requested array size exceeds VM limit", on any heap size. - */ - static final int MAX_ARRAY_LENGTH = Integer.MAX_VALUE - 8; - /** * Maximum size of a single byte array during consolidation. Default {@link #MAX_ARRAY_LENGTH}. */