Used multiple chunk to compose a buffer. ie: public static class Chunk { public byte[] mArray; public int mLength;
public Chunk(int length) { mArray = new byte[length]; mLength = 0; } }
class ByteArrayBuilder { private LinkedList mChunks;
public ByteArrayBuilder() { mChunks = new LinkedList(); }
public synchronized void append(byte[] array, int offset, int length) { while (length > 0) { Chunk c = null; if (mChunks.isEmpty()) { c = new Chunk(length); mChunks.addLast(c); } else { c = mChunks.getLast(); if (c.mLength == c.mArray.length) { c = new Chunk(length); mChunks.addLast(c); } }