public Buffer slice() { return peek(getIndex(), length()); }
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 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; }