Code example for ByteBuffer

Methods: array, capacity, position, remaining

0
		buffer.put(b, len, off);
	} 
 
	@Override 
	public void write(int b) {
		if (buffer.remaining() < 1) {
			expand(); 
		} 
		buffer.put((byte) b);
	} 
	 
	public long getSize() { 
		return buffer.position();
	} 
	 
	public ByteBuffer getRawBuffer() {
		return buffer;
	} 
	 
	private void expand() { 
		ByteBuffer replacement = ByteBuffer.allocate(buffer.capacity() * 2);
		replacement.put(buffer.array());
		replacement.position(buffer.position());
		buffer = replacement;
	} 
}