package com.hdl.sdk.link.core.utils;
|
|
import java.nio.ByteBuffer;
|
|
/**
|
* Created by hxb on 2022/8/3.
|
*
|
*/
|
public class ByteBufferUtils {
|
|
/**
|
* 获取ByteBuffer指定位置数据
|
*
|
* @param byteBuffer 源对象
|
* @param length 指定长度
|
* @return 根据长度生成的数组
|
*/
|
public static byte[] copyBytes(ByteBuffer byteBuffer, int length) {
|
return copyBytes(byteBuffer,0,length);
|
}
|
|
/**
|
* 复制指定位置的数据
|
* @param byteBuffer
|
* @param index
|
* @param length
|
* @return
|
*/
|
public static byte[] copyBytes(ByteBuffer byteBuffer, int index,int length) {
|
byte[] bytes = new byte[length];
|
for (int i = 0; i < bytes.length; i++) {
|
bytes[i] = byteBuffer.get(index + i);
|
}
|
return bytes;
|
}
|
|
}
|