public Buffer sliceFromMark() { return sliceFromMark(getIndex() - markIndex() - 1); }
public Buffer get(int length) { int gi = getIndex(); Buffer view = peek(gi, length); setGetIndex(gi + length); return view; }
public Buffer slice() { return peek(getIndex(), length()); }
public int hashCode() { if (_hash == 0 || _hashGet!=_get || _hashPut!=_put) { for (int i = putIndex(); i-- > getIndex();) { byte b = peek(i); if ('a' <= b && b <= 'z') b = (byte) (b - 'a' + 'A'); _hash = 31 * _hash + b; } if (_hash == 0) _hash = -1; _hashGet=_get; _hashPut=_put; } return _hash; }
public void writeTo(OutputStream out) throws IOException { byte array[] = array(); if (array!=null) { out.write(array,getIndex(),length()); } else { // System.err.println(this.getClass()+" OUCH!!!! Abstract writeTo: ? "+getIndex()+"-"+putIndex()); // TODO perhaps in buffer? for (int i=_get;i<_put;i++) out.write(peek(i)); } clear(); }
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 int skip(int n) { if (length() < n) n = length(); setGetIndex(getIndex() + n); return n; }
public Buffer asReadOnlyBuffer() { if (isReadOnly()) return this; return new View(this, markIndex(), getIndex(), putIndex(), READONLY); }
public Buffer asMutableBuffer() { if (!isImmutable()) return this; Buffer b=this.buffer(); if (b.isReadOnly()) { return duplicate(READWRITE); } return new View(b, markIndex(), getIndex(), putIndex(), _access); }
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); } }
public boolean equalsIgnoreCase(Buffer b) { if (b==this) return true; // reject different lengths if (b.length() != length()) return false; // reject AbstractBuffer with different hash value if (_hash != 0 && b instanceof AbstractBuffer) { AbstractBuffer ab = (AbstractBuffer) b; 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) { if ('a' <= b1 && b1 <= 'z') b1 = (byte) (b1 - 'a' + 'A'); if ('a' <= b2 && b2 <= 'z') b2 = (byte) (b2 - 'a' + 'A'); if (b1 != b2) return false; } } return true; }
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; }