public List<ByteArrayOutput> split(final int maxSize) { final List<ByteArrayOutput> list = new ArrayList<ByteArrayOutput>(); int currentSize = 0; TBaseStreamNode node = null; while ((node = nodes.peek()) != null) { if (node.size() > maxSize) { if (list.isEmpty()) { // first node list.add(node); nodes.poll(); } break; } if (currentSize + node.size() > maxSize) { break; } currentSize += node.size(); list.add(node); nodes.poll(); } return list; }
public int size() { int size = 0; for (TBaseStreamNode node : nodes) { size += node.size(); } return size; }