Hi.
Answering myself:
1) It possible to use BufferedOutput to speed-up the writing.
2) It possible to do bulk gets from the ByteBuffer().
Regards.
Is it possible to read a batch of data array, for a more efficient writing?
Regards.
2009/5/26 Timothy Wall <twal...@dev.java.net>
Write your own OutputStream which continually calls get() (which returns a
single byte and advances the buffer's internal position pointer) on the
returned ByteBuffer.
On May 26, 2009, at 8:02 AM, Stas Oskin wrote:
Hi.
Thanks for the explanation.
What would be the best way then to get the byte array() from Pointer
directly?
I'm looking to copy data from Pointer to OutputStream(), which accepts
only byte array(), and don't want to have any copy operations in the middle.
Thanks.
2009/5/26 Timothy Wall <twal...@dev.java.net>
Apparently the ByteBuffer produced by JNI's NewDirectByteBuffer does not
support an array view.
I wouldn't expect this function to be valid, since it's supposed to
return the array that backs the buffer. In the case of a direct buffer,
there is no backing array.
According to the javadoc, invoke "hasArray" before invoking "array" to
ensure the buffer has an accessible backing array (
http://java.sun.com/j2se/1.5.0/docs/api/java/nio/ByteBuffer.html#array()<http://java.sun.com/j2se/1.5.0/docs/api/java/nio/ByteBuffer.html#array%28%29>
).
On May 26, 2009, at 7:28 AM, Stas Oskin wrote:
Hi.
I'm trying to directly access memory located in pointer, but for some
reason I can only do it if I copy the memory via getByteArray().
Running the code below:
buf -> Pointer;
final byte[] ba = buf.getByteBuffer(0, size).array();
Produces:
Caused by: java.lang.UnsupportedOperationException
at java.nio.ByteBuffer.array(ByteBuffer.java:940)
Can someone advice how this can be solved?
Thanks in advance.