package com.whyc.service;
|
|
import com.whyc.res.RESData;
|
import com.whyc.res.RESDataHead;
|
import com.whyc.res.RESDataInfo;
|
import com.whyc.util.StaticInf;
|
import org.apache.catalina.connector.Response;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.io.File;
|
import java.io.FileInputStream;
|
import java.io.IOException;
|
|
@Service
|
public class RESDataInfoService {
|
//解析res内阻数据
|
public static RESDataInfo readFileData(String filePath)
|
{
|
RESDataInfo resDataInfo=new RESDataInfo();
|
int parse_result = StaticInf.PARSE_RESULT_NULL;
|
FileInputStream fis = null;
|
try {
|
File f = new File(filePath);
|
if(!filePath.endsWith(".BRES") && !filePath.endsWith(".bres")) {
|
parse_result = StaticInf.PARSE_RESULT_FILETYPEERR;
|
}
|
if(!f.exists()) {
|
parse_result = StaticInf.PARSE_RESULT_NOTFOUNDFILE;
|
}
|
fis = new FileInputStream(f);
|
byte[] buf = new byte[4];
|
if(fis.read(buf, 0, buf.length) == RESDataHead.BYTE_LEN)
|
{
|
if(resDataInfo.resDataHead.setHeadData(buf)) {
|
parse_result = StaticInf.PARSE_RESULT_SUCCESS;
|
}else {
|
parse_result = StaticInf.PARSE_RESULT_FILEERROR;
|
}
|
while(true)
|
{
|
if(resDataInfo.resDataHead.checkDataHead(fis))
|
{
|
RESData resData = new RESData();
|
byte[] checkbuf = new byte[RESData.DATA_CHECK_BYTE_LEN];
|
if(fis.read(checkbuf) == checkbuf.length){
|
if(resData.readResMonCount(checkbuf)){
|
int Data_LEN = 3 * resData.getBattSum() * 2 + 2;
|
//System.err.println("Data_LEN"+Data_LEN);
|
byte[] databuf = new byte[Data_LEN];
|
if(fis.read(databuf) == databuf.length)
|
{
|
//RESData resData = new RESData();
|
if(resData.setData(databuf)) {
|
resDataInfo.resDatas.add(resData);
|
}
|
}
|
}
|
}
|
|
|
}
|
if(fis.available() <1) {
|
break;
|
|
}
|
}
|
}else {
|
parse_result = StaticInf.PARSE_RESULT_FILEERROR;
|
}
|
|
} catch (IOException e) {
|
e.printStackTrace();
|
} finally {
|
if(null != fis)
|
{
|
try {
|
fis.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
resDataInfo.setParse_result(parse_result);
|
return resDataInfo;
|
}
|
|
public static void main(String[] args) {
|
//String fileUrl="E:\\fileTest\\fbxtest\\resdata.bres";
|
//String fileUrl="D:\\test\\resdata.bres";
|
//String fileUrl="D:\\test\\resdata(1).bres";
|
String fileUrl="D:\\test\\resdata(2).bres";
|
RESDataInfo info = readFileData(fileUrl);
|
System.out.println(info);
|
}
|
}
|