public String toString() { if (isImmutable()) { if (_string == null) _string = new String(asArray(), 0, length()); return _string; } return new String(asArray(), 0, length()); }
public Buffer asNonVolatileBuffer() { if (!isVolatile()) return this; return duplicate(_access); }
public Buffer asImmutableBuffer() { if (isImmutable()) return this; return duplicate(IMMUTABLE); }
public int get(byte[] b, int offset, int length) { int gi = getIndex(); int l=length(); if (length>l) length=l; length = peek(gi, b, offset, length); setGetIndex(gi + length); return length; }
public void compact() { if (isReadOnly()) throw new IllegalStateException(__READONLY); int s = markIndex() >= 0 ? markIndex() : getIndex(); if (s > 0) { byte array[] = array(); int length = putIndex() - s; if (length > 0) { if (array != null) Portable.arraycopy(array(), s, array(), 0, length); else poke(0, peek(s, length)); } if (markIndex() > 0) setMarkIndex(markIndex() - s); setGetIndex(getIndex() - s); setPutIndex(putIndex() - s); } }
buf.append(super.hashCode()); buf.append(","); buf.append(this.array().hashCode()); buf.append(",m="); buf.append(markIndex()); buf.append(",g="); buf.append(getIndex()); buf.append(",p="); buf.append(putIndex()); buf.append(",c="); buf.append(capacity()); buf.append("]={"); if (markIndex() >= 0) for (int i = markIndex(); i < getIndex(); i++) char c = (char) peek(i); if (Character.isISOControl(c)) for (int i = getIndex(); i < putIndex(); i++) char c = (char) peek(i); if (Character.isISOControl(c)) if (putIndex() - i > 20) i = putIndex() - 20;
public int poke(int index, byte[] b, int offset, int length) { _hash=0; if (isReadOnly()) throw new IllegalStateException(__READONLY); if (index < 0) throw new IllegalArgumentException("index<0: " + index + "<0"); if (index + length > capacity()) { length=capacity()-index; if (length<0) throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity()); } byte[] dst_array = array(); if (dst_array != null) Portable.arraycopy(b, offset, dst_array, index, length); else { int s=offset; for (int i=0;i<length;i++) poke(index++,b[s++]); } return length; }
public Buffer asReadOnlyBuffer() { if (isReadOnly()) return this; return new View(this, markIndex(), getIndex(), putIndex(), READONLY); }
public boolean equals(Object obj) { if (obj==this) return true; // reject non buffers; if (obj == null || !(obj instanceof Buffer)) return false; Buffer b = (Buffer) obj; if (this instanceof Buffer.CaseInsensitve || b instanceof Buffer.CaseInsensitve) return equalsIgnoreCase(b); // reject different lengths if (b.length() != length()) return false; // reject AbstractBuffer with different hash value if (_hash != 0 && obj instanceof AbstractBuffer) { AbstractBuffer ab = (AbstractBuffer) obj; if (ab._hash != 0 && _hash != ab._hash) return false; } // Nothing for it but to do the hard grind. for (int i = length(); i-- > 0;) { byte b1 = peek(getIndex() + i); byte b2 = b.peek(b.getIndex() + i); if (b1 != b2) return false; } return true; }
public Buffer get(int length) { int gi = getIndex(); Buffer view = peek(gi, length); setGetIndex(gi + length); return view; }
public int skip(int n) { if (length() < n) n = length(); setGetIndex(getIndex() + n); return n; }
public Buffer sliceFromMark() { return sliceFromMark(getIndex() - markIndex() - 1); }
public Buffer peek(int index, int length) { if (_view == null) { _view = new View(this, -1, index, index + length, isReadOnly() ? READONLY : READWRITE); } else { _view.update(this.buffer()); _view.setMarkIndex(-1); _view.setGetIndex(0); _view.setPutIndex(index + length); _view.setGetIndex(index); } return _view; }
public boolean equals(Object arg0) { return this==arg0 || super.equals(arg0); }