/** * Creates instance with required initial capacity. * * @param initialSize */ public FastBufferOutputStream(int initialSize) { this(new ByteBuffer(initialSize)); }
public void create() { buffer = new ByteBuffer(128); }
public void create() throws IOException { buffer = new ByteBuffer(256); }
public void create() { buffer = new ByteBuffer(128); }
public void create() throws IOException { buffer = new ByteBuffer(256); }
/** * Transforms this instance to instance of ByteBuffer (a link of chain of byte arrays). * * @param encoding * @return link of chain of byte arrays * @throws UnsupportedEncodingException */ public ByteBuffer toByteBuffer(String encoding) throws UnsupportedEncodingException { byte[] bs = new String(chars, 0, usedSize).getBytes(encoding); return new ByteBuffer(bs); }
/** * Transforms this instance to instance of ByteBuffer (a link of chain of byte arrays). * * @return link of chain of byte arrays */ public ByteBuffer toByteBuffer() { byte[] bs = new String(chars, 0, usedSize).getBytes(); return new ByteBuffer(bs); }
/** * Appends segment of a byte array to array if there are unfilled positions in it. Otherwize creates next link in the chain, * and appends data to it. * * @param bs * @param off * @param len * @return instance of ByteBuffer to which byte array was appended. */ public ByteBuffer append(byte[] bs, int off, int len) { if (next != null) { return next.append(bs, off, len); } if (len + usedSize <= cacheSize) { System.arraycopy(bs, off, bytes, usedSize, len); usedSize += len; return this; } int av = cacheSize - usedSize; if (av > 0) { System.arraycopy(bs, off, bytes, usedSize, av); usedSize += av; off += av; len -= av; } next = new ByteBuffer(cacheSize * 2); next.prev = this; return next.append(bs, off, len); }
/** * Appends byte to array if there are unfilled positions in it. Otherwize creates next link in the chain, and appends the * byte to it. * * @param c * @return instance of ByteBuffer to which byte was appended. */ public ByteBuffer append(byte c) { if (next != null) { return next.append(c); } if (usedSize < cacheSize) { bytes[usedSize] = c; usedSize++; return this; } else { next = new ByteBuffer(cacheSize * 2); next.prev = this; return next.append(c); } }