Administrator
2023-02-10 7e3cbc66e2eb9c7314f09da24cf6a66b2aa72cb6
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.fgkj.bres;
 
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
 
 
//FBS9600 内阻数据集
public class RESDataInfo implements FileDataParseInfo_Interface{
    
    public RESDataHead resDataHead;                    //内阻数据头
    public List<RESData> resDatas;                    //内阻数据集
    
    public int parse_result = PARSE_RESULT_NULL;
    public int file_type = FILE_TYPE_RES;        //文件类型
    
    public RESDataInfo() {
        resDataHead = new RESDataHead();            //内阻数据头
        resDatas = new ArrayList<>();                //内阻数据集
    }
    
    public void readFileData(String filePath)
    {
        
        FileInputStream fis = null;
        try {
            File f = new File(filePath);
            if(!filePath.endsWith(".BRES") && !filePath.endsWith(".bres")) {
                System.out.println("文件格式错误");
                parse_result = PARSE_RESULT_FILETYPEERR;
                return;
            }
            if(!f.exists()) {
                parse_result = PARSE_RESULT_NOTFOUNDFILE;
                System.out.println("文件不存在..........");
                return;
            }
            fis = new FileInputStream(f);
            byte[] buf = new byte[4];
            if(fis.read(buf, 0, buf.length) == RESDataHead.BYTE_LEN)
            {
                if(this.resDataHead.setHeadData(buf)) {
                    parse_result = PARSE_RESULT_SUCCESS;
                }else {
                    parse_result = PARSE_RESULT_FILEERROR;
                }
                while(true)
                {                    
                    if(resDataHead.checkDataHead(fis))
                    {
                        byte[] databuf = new byte[RESData.DATABYTE_LEN];
                        if(fis.read(databuf) == databuf.length)
                        {
                            RESData resData = new RESData();
                            if(resData.setData(databuf)) {
                                System.out.println(resData);
                                resDatas.add(resData);
                            }
                        }
                    }
                    if(fis.available() <1) {
                        //System.out.println("解析完成");
                        break;
                        
                    }
                }
            }else {
                parse_result = PARSE_RESULT_FILEERROR;
            }
                
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(null != fis)
            {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    
    
    public static void main(String[] args) {
        RESDataInfo info = new RESDataInfo();
        info.readFileData("D:\\桌面文件备份\\公司各种设备资料\\FBS存储文件解析/resdata.bres");
    }
 
}