public ByteArrayBuffer(int size) { this(new byte[size], 0, size, READWRITE); setPutIndex(0); }
public ByteArrayBuffer(String value,String encoding) throws UnsupportedEncodingException { super(READWRITE,NON_VOLATILE); _bytes = value.getBytes(encoding); setGetIndex(0); setPutIndex(_bytes.length); _access=IMMUTABLE; _string = value; }
public ByteArrayBuffer(byte[] bytes, int index, int length, int access, boolean isVolatile) { super(READWRITE, isVolatile); _bytes = bytes; setPutIndex(index + length); setGetIndex(index); _access = access; }
public ByteArrayBuffer(byte[] bytes, int index, int length, int access) { super(READWRITE, NON_VOLATILE); _bytes = bytes; setPutIndex(index + length); setGetIndex(index); _access = access; }
public ByteArrayBuffer(String value) { super(READWRITE,NON_VOLATILE); _bytes = Portable.getBytes(value); setGetIndex(0); setPutIndex(_bytes.length); _access=IMMUTABLE; _string = value; }
/** * */ public void reset() { _closed=false; _in.clear(); _out.clear(); if (_inBytes!=null) _in.setPutIndex(_inBytes.length); }
/** Wrap a byte array * @param b */ public void wrap(byte[] b) { if (isReadOnly()) throw new IllegalStateException(__READONLY); if (isImmutable()) throw new IllegalStateException(__IMMUTABLE); _bytes=b; setGetIndex(0); setPutIndex(b.length); }
/** Wrap a byte array. * @param b * @param off * @param len */ public void wrap(byte[] b, int off, int len) { if (isReadOnly()) throw new IllegalStateException(__READONLY); if (isImmutable()) throw new IllegalStateException(__IMMUTABLE); _bytes=b; clear(); setGetIndex(off); setPutIndex(off+len); }
public int readFrom(InputStream in,int max) throws IOException { if (max<0||max>space()) max=space(); int p = putIndex(); int len=0, total=0, available=max; while (total<max) { len=in.read(_bytes,p,available); if (len<0) break; else if (len>0) { p += len; total += len; available -= len; setPutIndex(p); } if (in.available()<=0) break; } if (len<0 && total==0) return -1; return total; } }