当前位置:
文档之家› java解析FSN文件.doc
java解析FSN文件.doc
//System.out.println("counter =* size"+counter * size);
//System.out.println("fsnHeadLengh="+fsnHeadLengh);
//如果fsn文件的长度合一致
if(counter * size +fsnHeadLengh== fsnbytes.length) {
imgbytes=null;//及时释放图片字节数组对象,释放内}else{
//map.put("ImageSno", null); body.setImageBytes(null);
}
noException=true;
if(noException){//当没有异常时记录解析数据
list.add(body);
body.setDateStr(DateBuf.toString());
body.setTimeStr( TimeBuf.toString());
body.setDateStr(DateBuf.toString());
body.setTimeStr( TimeBuf.toString());
body.setDateTime( body.getDateStr() +" "+ body.getTimeStr());
ArrayList<FsnBody> list =newArrayList<FsnBody>();
longValutaSum=0;
for(inti = 0; i < counter; i++) {
FsnBody body =newFsnBody();
booleannoException=false;//处理过程中没有异常
String TimeStr=hh + ":" + mm+ ":" +ss;
body.setDateStr(DateStr); body.setTimeStr( TimeStr);
//*/
//*
StringBuffer DateBuf=newStringBuffer();
StringBuffer TimeBuf=newStringBuffer();
StringDateStr=StrUtil.numAddZero(String.valueOf((y+1980)),4)+
"-" + StrUtil.numAddZero(String.valueOf(m),2) + "-"+
StrUtil.numAddZero(String.valueOf(d),2);
//设置日期时间
intdata =parseInt(fsnBytes);
inttime = parseInt(fsnBytes);
//System.out.println("data="+data);
//System.out.println("time="+time);
/*if(time<0){
time=-time; }*/
DateBuf.append( y + 1980); DateBuf.append("-");
DateBuf.append( FsnTools.numAddZero(m,2));
DateBuf.append("-");
DateBuf.append( FsnTools.numAddZero(d,2) );
对象,不能将此数据放入map,一是数据量大时内存溢出,二是效率大打折
byte[] imgbytes=FsnTools.byteCopy(fsnbytes, thisPosSart+fsnPerBodyNoImg, size-fsnPerBodyNoImg);
body.setImageBytes(imgbytes);//图片字节数组数据
byte[] fsnbytes =FsnTools.toByteArray(this.fsnFilePath);
this.fm.setSize(fsnbytes.length);
System.out.println("File Lengh: "+fsnbytes.length);
//读取头文件
setHead(fsnbytes);
if (code < 13 && code > 0) {
errorCode += code +",";
}
}
if ("1".equals(map.get("TfFlag")))
errorCode =errorCode.substring(0,
stIndexOf(","));
else
publicfinalstaticintfsnPerBodyImg=1644;//fsn文件体每条记录,包括
图像信息的字节长度
publicintfilePos=0;//fsn文件字节流当前指针位置
publicFsnModelfm;//本实例解析的FsnMedel对象
publicStringfsnFilePath;//FSN文件的存储完整路径,包括文件名
packageaction;
importjava.util.ArrayList;
importtools.FsnTools;
importbean.FsnBody;
importbean.FsnModel;
publicclassFsnReaderAction {
publicfinalstaticintintstep=2;//Uint16字节长度
fsnPerBodyNoImg;
//System.out.println("this.fm.getHeadString()[2]
="+this.fm.getHeadString()[2] );
//System.out.println("counter="+counter);
//System.out.println("size="+size);
body.setRecordNum(i+1);//此条fsn记录在fsn文件中的顺序
ValutaSum +=body.getValuta();
if(size!=fsnPerBodyNoImg){
testSnoImg(fsnbytes);//校验图片数据合法性,如果不合
法,将抛出异
//map.put("ImageSno",imageSno);//图片BufferedImage
//每条fsn信息均从i * size + 32(头的长度)处起始intthisPosSart=i * size +fsnHeadLengh;
//此处处理非常重要,在读取图片文件前一定要做处理因为图片字节流长度固定,644位,getSnoExpImg方法只读到图片信息中有数据部分对应的字节流,后
面的都是空值,将不再读取
}else{
if(this.fm.isPermitException()){//当有异常时,如果
fsn配置文件允许记录异常,则记录,否则不记录
list.add(body); }
} }
this.fm.setBodys(list);
}
}catch(Exception e){
this.fm.setAnalysisExcepted(true);
位图像meta
longmutiall = 4 * width * num;
if(mutiall >fsnPerBodyImg- 108){
thrownewException("图像数据读取失败,图像长度大于图像缓冲器长度");
}
//int i = 0;
//while ( i < width * num) {
if(num<=0||height<=0||width<=0){
thrownewException("图片数据读取失败,长宽和字符数均不能小于等于0");
}
//冠字号码个数不能多于12 if(num>12){
thrownewException("图片数据读取失败,冠字号码个数不能多"); }
//图片大小不能多于图片缓冲区的总大小,减去108位,包括100位其他字段和8
//冠字号码的个数
intnum = parseInt(fsnBytes);
//每个冠字号码的图像宽
intheight = parseInt(fsnBytes);
intwidth = parseInt(fsnBytes);
intReserve2 = parseInt(fsnBytes);
//图片三维不能小于0
//某条图片数据读完以后,filePos不一定会移至这个图片数据对应的结尾位置,要在读取下一条数据时,强制将filePos指向下一条图片信息对应字节流起
始位置
if(filePos<thisPosSart){
filePos=thisPosSart;
}
body = getSnoExpImg(fsnbytes);
longcounter =this.fm.getCounter();//冠字号信息条数//