/** * {@inheritDoc} */ @Override public final boolean hasRemaining() { return limit() > position(); }
/** * {@inheritDoc} */ @Override public final int remaining() { return limit() - position(); }
/** * {@inheritDoc} */ @Override public final IoBuffer getSlice(int length) { if (length < 0) { throw new IllegalArgumentException("length: " + length); } int pos = position(); int limit = limit(); int nextPos = pos + length; if (limit < nextPos) { throw new IndexOutOfBoundsException("position + length (" + nextPos + ") is greater " + "than limit (" + limit + ")."); } limit(pos + length); IoBuffer slice = slice(); position(nextPos); limit(limit); return slice; }
/** * {@inheritDoc} */ @Override public final IoBuffer getSlice(int length) { if (length < 0) { throw new IllegalArgumentException("length: " + length); } int pos = position(); int limit = limit(); int nextPos = pos + length; if (limit < nextPos) { throw new IndexOutOfBoundsException("position + length (" + nextPos + ") is greater " + "than limit (" + limit + ")."); } limit(pos + length); IoBuffer slice = slice(); position(nextPos); limit(limit); return slice; }
/** * {@inheritDoc} */ @Override public final IoBuffer getSlice(int length) { if (length < 0) { throw new IllegalArgumentException("length: " + length); } int pos = position(); int limit = limit(); int nextPos = pos + length; if (limit < nextPos) { throw new IndexOutOfBoundsException("position + length (" + nextPos + ") is greater " + "than limit (" + limit + ")."); } limit(pos + length); IoBuffer slice = slice(); position(nextPos); limit(limit); return slice; }
/** * {@inheritDoc} */ @Override public int hashCode() { int h = 1; int p = position(); for (int i = limit() - 1; i >= p; i--) { h = 31 * h + get(i); } return h; }
/** * {@inheritDoc} */ @Override public int hashCode() { int h = 1; int p = position(); for (int i = limit() - 1; i >= p; i--) { h = 31 * h + get(i); } return h; }
/** * {@inheritDoc} */ @Override public String toString() { StringBuilder buf = new StringBuilder(); if (isDirect()) { buf.append("DirectBuffer"); } else { buf.append("HeapBuffer"); } buf.append("[pos="); buf.append(position()); buf.append(" lim="); buf.append(limit()); buf.append(" cap="); buf.append(capacity()); buf.append(": "); buf.append(getHexDump(16)); buf.append(']'); return buf.toString(); }
/** * {@inheritDoc} */ @Override public int hashCode() { int h = 1; int p = position(); for (int i = limit() - 1; i >= p; i--) { h = 31 * h + get(i); } return h; }
/** * {@inheritDoc} */ @Override public String toString() { StringBuilder buf = new StringBuilder(); if (isDirect()) { buf.append("DirectBuffer"); } else { buf.append("HeapBuffer"); } buf.append("[pos="); buf.append(position()); buf.append(" lim="); buf.append(limit()); buf.append(" cap="); buf.append(capacity()); buf.append(": "); buf.append(getHexDump(16)); buf.append(']'); return buf.toString(); }
/** * {@inheritDoc} */ @Override public String toString() { StringBuilder buf = new StringBuilder(); if (isDirect()) { buf.append("DirectBuffer"); } else { buf.append("HeapBuffer"); } buf.append("[pos="); buf.append(position()); buf.append(" lim="); buf.append(limit()); buf.append(" cap="); buf.append(capacity()); buf.append(": "); buf.append(getHexDump(16)); buf.append(']'); return buf.toString(); }
/** * {@inheritDoc} */ @Override public final IoBuffer getSlice(int index, int length) { if (length < 0) { throw new IllegalArgumentException("length: " + length); } int pos = position(); int limit = limit(); if (index > limit) { throw new IllegalArgumentException("index: " + index); } int endIndex = index + length; if (endIndex > limit) { throw new IndexOutOfBoundsException("index + length (" + endIndex + ") is greater " + "than limit (" + limit + ")."); } clear(); limit(endIndex); position(index); IoBuffer slice = slice(); limit(limit); position(pos); return slice; }
/** * {@inheritDoc} */ @Override public final IoBuffer getSlice(int index, int length) { if (length < 0) { throw new IllegalArgumentException("length: " + length); } int limit = limit(); if (index > limit) { throw new IllegalArgumentException("index: " + index); } int endIndex = index + length; if (capacity() < endIndex) { throw new IndexOutOfBoundsException("index + length (" + endIndex + ") is greater " + "than capacity (" + capacity() + ")."); } clear(); position(index); limit(endIndex); IoBuffer slice = slice(); position(index); limit(limit); return slice; }
private IoBuffer expand(int pos, int expectedRemaining, boolean autoExpand) { if (!recapacityAllowed) { throw new IllegalStateException("Derived buffers and their parent can't be expanded."); } int end = pos + expectedRemaining; int newCapacity; if (autoExpand) { newCapacity = IoBuffer.normalizeCapacity(end); } else { newCapacity = end; } if (newCapacity > capacity()) { // The buffer needs expansion. capacity(newCapacity); } if (end > limit()) { // We call limit() directly to prevent StackOverflowError buf().limit(end); } return this; }
private IoBuffer expand(int pos, int expectedRemaining, boolean autoExpand) { if (!recapacityAllowed) { throw new IllegalStateException( "Derived buffers and their parent can't be expanded."); } int end = pos + expectedRemaining; int newCapacity; if (autoExpand) { newCapacity = IoBuffer.normalizeCapacity(end); } else { newCapacity = end; } if (newCapacity > capacity()) { // The buffer needs expansion. capacity(newCapacity); } if (end > limit()) { // We call limit() directly to prevent StackOverflowError buf().limit(end); } return this; }
private IoBuffer expand(int pos, int expectedRemaining, boolean autoExpand) { if (!recapacityAllowed) { throw new IllegalStateException("Derived buffers and their parent can't be expanded."); } int end = pos + expectedRemaining; int newCapacity; if (autoExpand) { newCapacity = IoBuffer.normalizeCapacity(end); } else { newCapacity = end; } if (newCapacity > capacity()) { // The buffer needs expansion. capacity(newCapacity); } if (end > limit()) { // We call limit() directly to prevent StackOverflowError buf().limit(end); } return this; }
/** * {@inheritDoc} */ @Override public int indexOf(byte b) { if (hasArray()) { int arrayOffset = arrayOffset(); int beginPos = arrayOffset + position(); int limit = arrayOffset + limit(); byte[] array = array(); for (int i = beginPos; i < limit; i++) { if (array[i] == b) { return i - arrayOffset; } } } else { int beginPos = position(); int limit = limit(); for (int i = beginPos; i < limit; i++) { if (get(i) == b) { return i; } } } return -1; }
/** * {@inheritDoc} */ @Override public boolean equals(Object o) { if (!(o instanceof IoBuffer)) { return false; } IoBuffer that = (IoBuffer) o; if (this.remaining() != that.remaining()) { return false; } int p = this.position(); for (int i = this.limit() - 1, j = that.limit() - 1; i >= p; i--, j--) { byte v1 = this.get(i); byte v2 = that.get(j); if (v1 != v2) { return false; } } return true; }
/** * {@inheritDoc} */ @Override public boolean equals(Object o) { if (!(o instanceof IoBuffer)) { return false; } IoBuffer that = (IoBuffer) o; if (this.remaining() != that.remaining()) { return false; } int p = this.position(); for (int i = this.limit() - 1, j = that.limit() - 1; i >= p; i--, j--) { byte v1 = this.get(i); byte v2 = that.get(j); if (v1 != v2) { return false; } } return true; }
/** * {@inheritDoc} */ @Override public boolean equals(Object o) { if (!(o instanceof IoBuffer)) { return false; } IoBuffer that = (IoBuffer) o; if (this.remaining() != that.remaining()) { return false; } int p = this.position(); for (int i = this.limit() - 1, j = that.limit() - 1; i >= p; i--, j--) { byte v1 = this.get(i); byte v2 = that.get(j); if (v1 != v2) { return false; } } return true; }