@Override public int ensureWritable(int minWritableBytes, boolean force) { checkPositiveOrZero(minWritableBytes, "minWritableBytes"); if (minWritableBytes == 0) { return 0; } return 1; }
@Override public ServerSocketChannelConfig setBacklog(int backlog) { checkPositiveOrZero(backlog, "backlog"); this.backlog = backlog; return this; }
@Override public ChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis) { checkPositiveOrZero(connectTimeoutMillis, "connectTimeoutMillis"); this.connectTimeoutMillis = connectTimeoutMillis; return this; }
/** * Increase the current write counter by the given delta */ public ChannelFlushPromiseNotifier increaseWriteCounter(long delta) { checkPositiveOrZero(delta, "delta"); writeCounter += delta; return this; }
protected AbstractByteBuf(int maxCapacity) { checkPositiveOrZero(maxCapacity, "maxCapacity"); this.maxCapacity = maxCapacity; }
private static void validateMaxContentLength(int maxContentLength) { checkPositiveOrZero(maxContentLength, "maxContentLength"); }
@Override public ByteBuf ensureWritable(int minWritableBytes) { checkPositiveOrZero(minWritableBytes, "minWritableBytes"); if (minWritableBytes != 0) { throw new IndexOutOfBoundsException(); } return this; }
private ByteBuf checkLength(int length) { checkPositiveOrZero(length, "length"); if (length != 0) { throw new IndexOutOfBoundsException(); } return this; } }
private ByteBuf checkIndex(int index, int length) { checkPositiveOrZero(length, "length"); if (index != 0 || length != 0) { throw new IndexOutOfBoundsException(); } return this; }
/** * Create a new instance using the given {@link File}. The {@link File} will be opened lazily or * explicitly via {@link #open()}. * * @param f the {@link File} which should be transferred * @param position the position from which the transfer should start * @param count the number of bytes to transfer */ public DefaultFileRegion(File f, long position, long count) { if (f == null) { throw new NullPointerException("f"); } checkPositiveOrZero(position, "position"); checkPositiveOrZero(count, "count"); this.position = position; this.count = count; this.f = f; }
/** * This constructor is needed to keep backward-compatibility. */ WriteBufferWaterMark(int low, int high, boolean validate) { if (validate) { checkPositiveOrZero(low, "low"); if (high < low) { throw new IllegalArgumentException( "write buffer's high water mark cannot be less than " + " low water mark (" + low + "): " + high); } } this.low = low; this.high = high; }
private static void validate(int initialCapacity, int maxCapacity) { checkPositiveOrZero(initialCapacity, "initialCapacity"); if (initialCapacity > maxCapacity) { throw new IllegalArgumentException(String.format( "initialCapacity: %d (expected: not greater than maxCapacity(%d)", initialCapacity, maxCapacity)); } }
static ByteBuffer newDirectBuffer(long address, int capacity) { ObjectUtil.checkPositiveOrZero(capacity, "capacity"); try { return (ByteBuffer) DIRECT_BUFFER_CONSTRUCTOR.newInstance(address, capacity); } catch (Throwable cause) { // Not expected to ever throw! if (cause instanceof Error) { throw (Error) cause; } throw new Error(cause); } }
private static String hexDump(byte[] array, int fromIndex, int length) { checkPositiveOrZero(length, "length"); if (length == 0) { return ""; } int endIndex = fromIndex + length; char[] buf = new char[length << 1]; int srcIdx = fromIndex; int dstIdx = 0; for (; srcIdx < endIndex; srcIdx ++, dstIdx += 2) { System.arraycopy( HEXDUMP_TABLE, (array[srcIdx] & 0xFF) << 1, buf, dstIdx, 2); } return new String(buf); }
/** * Throws an {@link IndexOutOfBoundsException} if the current * {@linkplain #readableBytes() readable bytes} of this buffer is less * than the specified value. */ protected final void checkReadableBytes(int minimumReadableBytes) { checkPositiveOrZero(minimumReadableBytes, "minimumReadableBytes"); checkReadableBytes0(minimumReadableBytes); }
@Override public ByteBuf ensureWritable(int minWritableBytes) { checkPositiveOrZero(minWritableBytes, "minWritableBytes"); ensureWritable0(minWritableBytes); return this; }
/** * Create a new instance * * @param unknownSize The size which is returned for unknown messages. */ public DefaultMessageSizeEstimator(int unknownSize) { checkPositiveOrZero(unknownSize, "unknownSize"); handle = new HandleImpl(unknownSize); }
private static String hexDump(ByteBuf buffer, int fromIndex, int length) { checkPositiveOrZero(length, "length"); if (length == 0) { return ""; } int endIndex = fromIndex + length; char[] buf = new char[length << 1]; int srcIdx = fromIndex; int dstIdx = 0; for (; srcIdx < endIndex; srcIdx ++, dstIdx += 2) { System.arraycopy( HEXDUMP_TABLE, buffer.getUnsignedByte(srcIdx) << 1, buf, dstIdx, 2); } return new String(buf); }
@Override public ChannelConfig setWriteBufferHighWaterMark(int writeBufferHighWaterMark) { checkPositiveOrZero(writeBufferHighWaterMark, "writeBufferHighWaterMark"); for (;;) { WriteBufferWaterMark waterMark = writeBufferWaterMark; if (writeBufferHighWaterMark < waterMark.low()) { throw new IllegalArgumentException( "writeBufferHighWaterMark cannot be less than " + "writeBufferLowWaterMark (" + waterMark.low() + "): " + writeBufferHighWaterMark); } if (WATERMARK_UPDATER.compareAndSet(this, waterMark, new WriteBufferWaterMark(waterMark.low(), writeBufferHighWaterMark, false))) { return this; } } }
@Override public ChannelConfig setWriteBufferLowWaterMark(int writeBufferLowWaterMark) { checkPositiveOrZero(writeBufferLowWaterMark, "writeBufferLowWaterMark"); for (;;) { WriteBufferWaterMark waterMark = writeBufferWaterMark; if (writeBufferLowWaterMark > waterMark.high()) { throw new IllegalArgumentException( "writeBufferLowWaterMark cannot be greater than " + "writeBufferHighWaterMark (" + waterMark.high() + "): " + writeBufferLowWaterMark); } if (WATERMARK_UPDATER.compareAndSet(this, waterMark, new WriteBufferWaterMark(writeBufferLowWaterMark, waterMark.high(), false))) { return this; } } }