/**
*
*/
package com.icitic.iccard.dp.test;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* 运算规则和0x1f做与运算来确定是取得几个字节 用第一个字节和后面0x1f取值
若和0x1f与操作后,还等于0x1f则取两个字节,取2个字节(4位)即可 ,数据都是16进制文件,取前(两位)做为一个字节
template.dat的文件如下:
X00401|827C00|8701|9F360000|9F080020|9F5680|9F130000|9F4D0B0A|9F4F9A039F21039F02069F03069F1A025F2A029F4E149C019F3602|8C9F02069F03069F1A0295055F2A029A039C019F37049F21039F4E14|8D8A029F02069F03069F1A0295055F2A029A039C019F37049F21039F4E14|9F2700|9F0E0010980000|9F0FD86804F800|9F0DD86004A800|9F1007800103000000010A01|5F280156|5F2Dzh|9F510156|4FA000000333010101|50PBOC DEBIT|9F07FF00|8E000000000000000002031F00|9F499F3704|9F52C000| |5F300220| |X0035F24,5A,5F34,9F07,8E,9F0D,9F0E,9F0F,5F28,82|9F63|9F4A82&X00402|9F389F7A019F02065F2A02|8E00000000000000005E031F00|9F0E0010800000|9F0FD8683CF800|9F0DD8603CA800&X00403|827C00|9F389F66049F02069F03069F1A0295055F2A029A039C019F3704|9F6881400000|9F6C0000|9F1007800103000000010A01|
* @author sandy
*
*/
public class FetchDPDataTag {
//private static final String _FILENAME = "text.dat";
/**
* text.dat(发卡行数据)文件的内容如下:
* X00401|5A6217661199000000814|5F3400|9F5300|9F54000000000000|9F5C000000000000|9F5800|9F5900|9F1400|9F2300|5F20|9F0B|9F61|9F6200|5F24161231|5F25110321| |9F1F|57A2A2AC4DF6D286F91ED9A6961628D77093400DF06DA2A9CA8F01517F6690D849FB348F4B564D40C5&X00402|9F79000000000000|9F77000000100000|9F74ECC001|9F78000000100000|9F6D000000000000&X00403|9F6B000000999999|9F5D000000000001
*/
private static final String _TEMPLATEFILENAME = "template.dat";
private static final String _SEPARATOR = "\\|";
/**
* @param args
*/
public static void main(String[] args) {
start();
}
private static void start() {
InputStream is = FetchDPDataTag.class.getClassLoader().getResourceAsStream(
_TEMPLATEFILENAME);
Scanner scanner = new Scanner(is, "utf-8");
List<String> differents = new ArrayList<String>();
List<String> sames = new ArrayList<String>();
while (scanner.hasNextLine()) {
parse(scanner, differents, sames);
}
}
private static void parse(Scanner scanner, List<String> differents,
List<String> sames) {
String line = scanner.nextLine();
String[] tagsAndValues = line.split(_SEPARATOR);
for (String tagAndValus : tagsAndValues) {
if (tagAndValus.trim()!=null&&tagAndValus.trim().length()!=0) {
boolean b = tagAndValus.startsWith("X00");
if (!b) {
String he2 = tagAndValus.substring(0, 2);
int i = Integer.parseInt(he2, 16);
if ((i & 0x1f) == 0x1f) {
String key = tagAndValus.substring(0, 4);
distribute(differents, sames, key);
System.out.println("2个字节key===" + key);
} else {
String key = tagAndValus.substring(0, 2);
distribute(differents, sames, key);
System.out.println("1个字节key===" + key);
}
}
}
}
printrepeatTag(sames);
print_unrepeatTag(differents);
}
/**
* 打印不重复的tag
* @param differents
*/
private static void print_unrepeatTag(List<String> differents) {
for (String diff : differents) {
// System.out.println("不重复的tag==========="+diff);
System.out.println(diff);
}
}
/**
* 打印重复的tag
* @param sames
*/
private static void printrepeatTag(List<String> sames) {
for (String sametag : sames) {
System.out.println("重复的tag============="+sametag);
}
}
/**
* 分发数据
* @param differents
* @param sames
* @param key
*/
private static void distribute(List<String> differents, List<String> sames,
String key) {
if(differents.contains(key)){
sames.add(key);
}else{
differents.add(key);
}
}
}