private static void ensureAssumptions(List<ByteBuffer> buffers) { if (buffers.isEmpty()) { throw new IllegalArgumentException("Buffer list must not be empty."); } if (buffers.size() == 1) { // Special case of just a single buffer, conditions don't apply. } else { final int blockPage = determineBlockPage(buffers); // First buffer decides on block page length. if (!isPowerOfTwo(blockPage)) { throw new IllegalArgumentException("The first buffer must have power-of-two position() + remaining(): 0x" + Integer.toHexString(blockPage)); } // Any block from 2..last-1 should have the same page size. for (int i = 1, last = buffers.size() - 1; i < last; i++) { ByteBuffer buffer = buffers.get(i); if (buffer.position() != 0) { throw new IllegalArgumentException("All buffers except for the first one must have position() == 0: " + buffer); } if (i != last && buffer.remaining() != blockPage) { throw new IllegalArgumentException("Intermediate buffers must share an identical remaining() power-of-two block size: 0x" + Integer.toHexString(blockPage)); } } } }
private static void ensureAssumptions(List<ByteBuffer> buffers) { if (buffers.isEmpty()) { throw new IllegalArgumentException("Buffer list must not be empty."); } if (buffers.size() == 1) { // Special case of just a single buffer, conditions don't apply. } else { final int blockPage = determineBlockPage(buffers); // First buffer decides on block page length. if (!isPowerOfTwo(blockPage)) { throw new IllegalArgumentException("The first buffer must have power-of-two position() + remaining(): 0x" + Integer.toHexString(blockPage)); } // Any block from 2..last-1 should have the same page size. for (int i = 1, last = buffers.size() - 1; i < last; i++) { ByteBuffer buffer = buffers.get(i); if (buffer.position() != 0) { throw new IllegalArgumentException("All buffers except for the first one must have position() == 0: " + buffer); } if (i != last && buffer.remaining() != blockPage) { throw new IllegalArgumentException("Intermediate buffers must share an identical remaining() power-of-two block size: 0x" + Integer.toHexString(blockPage)); } } } }