whycxzp
2025-03-22 be8a251672810019d5874b846f4d47df06fde62d
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.whyc.hik.Commom;
 
 
 
import java.io.*;
 
public class CommonUtil {
 
    //SDK时间解析
    public static String parseTime(int time) {
        int year = (time >> 26) + 2000;
        int month = (time >> 22) & 15;
        int day = (time >> 17) & 31;
        int hour = (time >> 12) & 31;
        int min = (time >> 6) & 63;
        int second = (time >> 0) & 63;
        String sTime = year + "-" + month + "-" + day + "-" + hour + ":" + min + ":" + second;
//        System.out.println(sTime);
        return sTime;
 
 
    }
 
    //分辨率解析
    public static String parseResolution(int dwResolution) {
        int interlace = (((dwResolution) >> 28) & 0x1);
        int width = ((((dwResolution) >> 19) & 0x1ff) << 3);  //宽
        int hight = ((((dwResolution) >> 8) & 0x7ff) << 1); //高
        int fps = ((dwResolution) & 0xff);  //帧率
        String result = width + "*" + hight + "_" + fps;
        return result;
 
 
    }
 
    /**
     * 读取本地文件到数组中
     *
     * @param filename 本地文件
     * @return 返回读取到的数据到 byte数组
     * @throws IOException
     */
    public static byte[] toByteArray(String filename) throws IOException {
        File file = new File(filename);
        if (!file.exists()) {
            throw new FileNotFoundException(filename);
        }
        ByteArrayOutputStream bos = new ByteArrayOutputStream((int) file.length());
        BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
        try {
            byte[] buffer = new byte[1024];
            int len;
            while (-1 != (len = in.read(buffer, 0, buffer.length))) {
                bos.write(buffer, 0, len);
            }
            return bos.toByteArray();
        } catch (IOException e) {
            e.printStackTrace();
            throw e;
        } finally {
            bos.close();
            in.close();
        }
    }
 
 
}