12

I am working in Android. I need to convert byte[] to Buffer type. In Android, I have seen a type Buffered that I needed to use in particular functions. But, I my data source is type byte[].

Richard Povinelli
  • 1,419
  • 1
  • 14
  • 28
user1074474
  • 441
  • 3
  • 7
  • 17

1 Answers1

33

Take a look at ByteBuffer.wrap:

byte[] bytes = ...;
Buffer buf = ByteBuffer.wrap(bytes);

There's also a ByteBuffer.wrap(byte[] array, int start, int byteCount) if you only want to wrap part of an array.

Brendan Long
  • 53,280
  • 21
  • 146
  • 188