Can't you read directly into `buffer.toByteArray()` ?