Reputation: 197
I have
ByteBuffer buf = ByteBuffer.allocateDirect(500);
Then I use buf.put(byte)
a couple of times, say 20.
I save it to sql blob via the underlying array, i.e. by calling buf.array()
. However, the length of buf.array()
is 500. How to get an array (byte[]) of length 20 that can be passed to other (read-only) functions? (without copying, of course.)
Upvotes: 1
Views: 3799
Reputation: 136042
try this
ByteBuffer buf = ByteBuffer.allocate(500);
buf.putInt(1);
...
...
byte[] a = new byte[buf.position()];
buf.rewind();
buf.get(a);
Upvotes: 4