whycxzp
2023-08-16 618fd4fe93cb0901011c59f05a4a68376b378fe2
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
package com.whyc.constant;
 
import java.io.FileInputStream;
 
public class ParseUtil {
 
    
    /**
     *     检查数据的数据类型
     * @param fis
     * @return
     */
    public static int checkFBSDataType(FileInputStream fis) {
        boolean file_end = false;
        byte[] tag = new byte[1];
        int data_type = -1;
        try {
            fis.mark(2060);
            int count = 0;
            while(true)
            {
                count++;
                int n = 0;
                for(n=0; n<4; n++)
                {
                    if(1 != fis.read(tag, 0, 1))
                    {
                        file_end = true;
                        break;
                    }
                    if((ConstantDefined.DATA_TYPE_DIS != (tag[0]&0xFF)) && (ConstantDefined.DATA_TYPE_CHR != (tag[0]&0xFF)) && (ConstantDefined.DATA_TYPE_RULE != (tag[0]&0xFF)))
                    {
                        break;
                    }else {
                        int tmp_tag = tag[0]&0xFF;
                        System.out.println(tmp_tag+"==="+n);
                        if(n > 0 && (data_type != tmp_tag)) {
                            //筛选数据中只出现一个FD的情况
                            break;
                        }
                        data_type = tag[0]&0xFF;                        
                    }
                }
                
                if(n >= 4)
                {
                    //提前解析完成
                    break;
                }
                if(true == file_end)
                {
                    //读取完成
                    break;
                }
                System.out.println("=======count:" + count);
            }
            fis.reset();
            //判断是否支持mark标记
            if(fis.markSupported())
            {
                System.out.println("@@@@@@@@@@@@");
                //重置数据流的位置避免重新读取文件
            }
        
        } catch (Exception e) {
            e.printStackTrace();
            data_type = -1;
        }        
        return data_type;
    }
    
}