Github user aarondav commented on the pull request:
https://github.com/apache/spark/pull/397#issuecomment-40288679
Having a toByteBuffer method definitely seems reasonable to me, the only
issue is that ByteBuffer does not provide a good stream-compatible API. So it
would either still have to use write(bytes, offset, length), by getting these
parameters from the ByteBuffer (and being careful that .array() returns the
entire underlying array), or by using some API external to both ByteBuffer and
our fast output stream.
What if FastBufferedOutputStream has two methods:
```
def toByteBuffer: ByteBuffer
def toByteArraySegment: (Array[Byte], Int, Int)
```
where the latter returns the offset and index to be passed in to any stream
APIs.
In order to provide a lower level API, we often have to sacrifice some code
niceties, but this at least provides pretty good safety for the user to not
misuse it.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---