wjc
2023-06-28 989b4cf5a84e898e9682f8d9723a8ba1ff20c23b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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;
    }
 
}