-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormataExtratoBradescoMD5.java
131 lines (90 loc) · 4.18 KB
/
FormataExtratoBradescoMD5.java
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import java.io.*;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class FormataExtratoBradescoMD5 {
/**
* @param args
*/
public static void main(String[] args) {
// The name of the file to open.
String fileName = null;
// This will reference one line at a time
String line = null;
String[] campos = null;
String data = null;
String descricao = null;
String codigo = null;
String credito = null;
String debito = null;
String descricaoAnterior = null;
String saldo = null;
int numRegistro=0;
try {
if( args.length >= 1)
// The name of the file to open.
fileName = args[0];
else fileName = "";
// FileReader reads text files in the default encoding.
FileReader fileReader =
new FileReader(fileName);
// Always wrap FileReader in BufferedReader.
BufferedReader bufferedReader =
new BufferedReader(fileReader);
if((line = bufferedReader.readLine()) != null ){
do{
campos = line.split(";");
if(campos.length != 2){
data = campos[0];
descricao = campos[1];
codigo = campos[2];
credito = campos[3];
//saldo = campos[5];
debito = "0";
}
if( campos.length > 4 )
debito = campos[4];
if((line = bufferedReader.readLine()) != null ){
campos = line.split(";");
if( campos.length == 2 ){
descricao = descricao.concat(" " + campos[1]);
line = bufferedReader.readLine();
}
}
String registroCompletoCSV = data + ";" + descricao + ";" + codigo + ";" + credito + ";" + debito + ";" + ";";
System.out.print(registroCompletoCSV);
String registroConcatenado = data + descricao + codigo + credito + debito;
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(registroConcatenado.getBytes());
byte[] digest = md.digest();
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < digest.length; i++) {
hexString.append(Integer.toHexString(0xFF & digest[i]));
}
System.out.println(hexString.toString() + ";");
numRegistro++;
} while( line != null);
//System.out.println("\n\n numero de registros: " + numRegistro);
} //end if
// Always close files.
bufferedReader.close();
}
catch(FileNotFoundException ex) {
System.out.println(
"Não foi possível abrir o arquivo '" +
fileName + "'");
System.out.println(
"uso: java FormataExtratoBradesco extrato.csv"
);
}
catch(IOException ex) {
System.out.println(
"Error reading file '"
+ fileName + "'");
// Or we could just do this:
// ex.printStackTrace();
}
catch(NoSuchAlgorithmException ex){
System.out.println("erro algoritmo");
}
}//main
}//class