Wouldn't it be possible to use DataInputStream's readFully method to copy this into a byte array and then wrap that with a byte buffer?

That said, I think it might make sense to take this to the "next logical conclusion" and allow an arbitrary InputStream. I think the way to do that would be to write the data to a ByteArrayOutputStream and then convert it to a byte array at the end.