Home » Android » java – Convert byte[] to Buffer type

java – Convert byte[] to Buffer type

Posted by: admin May 14, 2020 Leave a comment


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[].

How to&Answers:

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.