6 messages in net.java.dev.jna.usersRe: [jna-users] UnsupportedOperationE...
FromSent OnAttachments
Stas OskinMay 26, 2009 4:28 am 
Timothy WallMay 26, 2009 4:42 am 
Stas OskinMay 26, 2009 5:02 am 
Timothy WallMay 26, 2009 5:17 am 
Stas OskinMay 26, 2009 5:28 am 
Stas OskinMay 27, 2009 4:18 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] UnsupportedOperationException when trying to get byte array fom ByteBufferActions...
From:Stas Oskin (stas@gmail.com)
Date:May 26, 2009 5:02:19 am
List:net.java.dev.jna.users

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.