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(); }
buf.append(super.hashCode()); buf.append(","); buf.append(this.array().hashCode()); buf.append(",m="); buf.append(markIndex());
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 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 byte[] asArray() { byte[] bytes = new byte[length()]; byte[] array = array(); if (array != null) Portable.arraycopy(array, getIndex(), bytes, 0, bytes.length); else peek(getIndex(), bytes, 0, length()); return bytes; }
byte[] dst_array = array(); if (src_array != null && dst_array != null) Portable.arraycopy(src_array, src.getIndex(), dst_array, index, length);