I have to mix c++ code with java. The java part allocates a java.nio.ByteBuffer and the c++ part gets it's address via env->GetDirectBufferAddress(buffer) as a jbyte* and fills in data.
ByteOrder is ok. Data can be retrieved in java via buffer.get() .getLong() etc.
However, the method buffer.array() fails and hasArray() returns false. If I use buffer.allocate(size) instead of .allocateDirect(size) the method array() works well, but my c++ code gets a DirectBufferAddress of NULL and fails.
My question: how can I best combine both worlds, with least copying of data? Or, how to easiest fill a java byte[] with native c++ data ?