| | |
| | | package com.whyc.res; |
| | | |
| | | import com.whyc.util.StaticInf; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Data; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | |
| | | |
| | | |
| | | //FBS9600 内阻数据集 |
| | | @Data |
| | | @AllArgsConstructor |
| | | public class RESDataInfo { |
| | | |
| | | public RESDataHead resDataHead; //内阻数据头 |
| | | public List<RESData> resDatas; //内阻数据集 |
| | | |
| | | public int parse_result = PARSE_RESULT_NULL; |
| | | |
| | | public static final int PARSE_RESULT_NULL = 0; //未知 |
| | | public static final int PARSE_RESULT_SUCCESS = 1; //解析成功 |
| | | public static final int PARSE_RESULT_NOTFOUNDFILE = 2; //文件未找到 |
| | | public static final int PARSE_RESULT_FILETYPEERR = 3; //文件格式错误 |
| | | public static final int PARSE_RESULT_FILEERROR = 4; //文件异常 |
| | | public RESDataHead resDataHead; //内阻数据头 |
| | | public List<RESData> resDatas; //内阻数据集 |
| | | |
| | | public int parse_result; |
| | | public int file_type = StaticInf.FILE_TYPE_RES; //文件类型 |
| | | |
| | | public RESDataInfo() { |
| | | resDataHead = new RESDataHead(); //内阻数据头 |
| | | resDatas = new ArrayList<>(); //内阻数据集 |
| | | resDatas = new ArrayList<>(); //内阻数据集 |
| | | } |
| | | |
| | | public void readResFile(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.readResFile("D:\\桌面文件备份\\公司各种设备资料\\FBS存储文件解析/resdata.bres"); |
| | | //info.readFileData("D:\\桌面文件备份\\公司各种设备资料\\FBS存储文件解析/resdata.bres"); |
| | | } |
| | | |
| | | |
| | | } |