I might be mixing up versions here, but I believe, without actually flushing the buffer lengths always remain zero unless you write enough data to trigger the automatic flushing behavior. Try adding a call to flush in your unit test before checking the size to confirm.