/** * Writes all data written up to the moment to out. * * @param out * @throws IOException */ public void writeTo(OutputStream out) throws IOException { ByteBuffer b = getFirstBuffer(); while (b != null) { out.write(b.getBytes(), 0, b.getUsedSize()); b = b.getNext(); } }
System.arraycopy(current.getBytes(), index, b, off, av); index += av; off += av;
System.arraycopy(current.getBytes(), index, b, off, av); index += av; off += av;
private byte[] getBufferBytes() { byte[] bs = new byte[buffer.getLast().getTotalSize()]; int pos = 0; ByteBuffer currentBuffer = buffer; while (currentBuffer != null) { System.arraycopy(currentBuffer.getBytes(), 0, bs, pos, currentBuffer.getUsedSize()); pos += currentBuffer.getUsedSize(); currentBuffer = currentBuffer.getNext(); } return bs; }
private byte[] getBufferBytes() { byte[] bs = new byte[buffer.getLast().getTotalSize()]; int pos = 0; ByteBuffer currentBuffer = buffer; while (currentBuffer != null) { System.arraycopy(currentBuffer.getBytes(), 0, bs, pos, currentBuffer.getUsedSize()); pos += currentBuffer.getUsedSize(); currentBuffer = currentBuffer.getNext(); } return bs; }
public byte[] toByteArray() { ByteBuffer b = getFirstBuffer(); if (b == null) { return new byte[0]; } ByteBuffer l = b; while (l.getNext() != null) { l = l.getNext(); } byte[] result = new byte[l.getTotalSize()]; int index = 0; while (b != null) { int s = b.getUsedSize(); System.arraycopy(b.getBytes(), 0, result, index, s); index += s; b = b.getNext(); } return result; }