-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCheckLogs.java
More file actions
714 lines (613 loc) · 22.7 KB
/
CheckLogs.java
File metadata and controls
714 lines (613 loc) · 22.7 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
package Jvakt;
/*
* 2023-11-25 V.58 Michael Ekdal New functions to add the logs into the DB
* 2023-10-25 V.57 Michael Ekdal If there is at least a must line the program is not aborted.
* 2023-09-18 V.56 Michael Ekdal Changed charset to default UTF8 before every new log file is checked.
* 2022-12-20 V.55 Michael Ekdal Made sure the jvtype is used as a default when updating Jvakt status
* 2022-06-23 V.54 Michael Ekdal Added getVersion() to get at consistent version throughout all classes.
*/
import java.net.InetAddress;
import java.io.*;
import java.util.*;
import java.text.*;
//import java.nio.charset.StandardCharsets;
//import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.apache.commons.codec.binary.Hex;
public class CheckLogs {
static String state = "a";
static String t_sys;
static String t_id;
static String t_ip;
static String t_desc;
static String t_desc_prev="";
static String id;
static BufferedReader in;
static String aFile;
static String jvhost = "localhost";
static String jvport = "1956";
static String jvtype = "R";
static int port ;
static String database = null;
static String dbuser = "console";
static String dbpassword = "";
static String dbhost = "localhost";
static String dbport = "5433";
static InetAddress inet;
static String version = "CheckLogs ";
static String agent = null;
static boolean swSlut = false;
static String charset = "UTF8";
static String config = null;
static File configF;
static FileInputStream fis;
static boolean swJvakt = false;
static boolean swLogs = false;
static Boolean swUTF8BOM = false;
static Boolean swUTF16BEBOM = false;
static Boolean swUTF16LEBOM = false;
static Boolean swCharset = false;
static int currI;
static int line;
static DirFilter df;
static File dir = null;
static String suf = null;
// static String pos = ".";
static String pos = null;
static File[] listf;
static String[] etab;
static String[] tokay;
static String[] tmust;
static String[] etabSplit;
static String[] tokaySplit;
static String[] tmustSplit;
static int ecount = 0;
static int tcount = 0;
static int mcount = 0;
static LogsRowInsert lri= new LogsRowInsert();
static BufferedReader inokay;
public static void main(String[] args) throws IOException {
// int j = 0;
version += getVersion()+".58";
int fileErrors = 0;
int errors = 0;
int position=0;
int posprev = 0;
String strprev = null;
String nyttnamn;
String tdat;
// String c;
String s;
// String prev_s = "";
boolean swWarn;
boolean swMust = true;
boolean swDummy = false;
File newnamn;
File oldnamn;
// String sys = ".";
// String res = ".";
// String typ = ".";
PrintStream ut;
boolean swRename = false;
boolean swPsav = false;
boolean swCsav = false;
System.out.println("--- "+version + " by Michael Ekdal Sweden.\n");
// reads command line arguments
for ( int i = 0; i < args.length; i++) {
if (args[i].equalsIgnoreCase("-dir")) dir = new File(args[++i]);
if (args[i].equalsIgnoreCase("-suf")) suf = args[++i];
if (args[i].equalsIgnoreCase("-pos")) pos = args[++i];
if (args[i].equalsIgnoreCase("-id")) id = args[++i];
if (args[i].equalsIgnoreCase("-ren")) swRename=true;
if (args[i].equalsIgnoreCase("-psav")) swPsav=true;
if (args[i].equalsIgnoreCase("-csav")) swCsav=true;
if (args[i].equalsIgnoreCase("-logs")) swLogs=true;
if (args[i].equalsIgnoreCase("-jvakt")) swJvakt=true;
if (args[i].equalsIgnoreCase("-jvtype")) jvtype = args[++i];
if (args[i].equalsIgnoreCase("-config")) config = args[++i];
if (args[i].equalsIgnoreCase("-charset")) {
charset = args[++i];
System.out.println("-- Will use charset "+charset);
swCharset = true;
}
}
if (args.length < 1) {
System.out.println("\nThe parameters and their meaning are:\n"+
"\n-dir \tThe directory to scan, like \"-dir c:\\Temp\". Charset UTF8 is assumed. "+
"\n-suf \tThe suffix of the files you want to include in the scan, like \"-suf .log\" "+
"\n-pos \tAn optional string that must be contained in the file names. Optional." +
"\n-csav \tSaves the position of the scanned fil in the -config directory. Optional." +
"\n-psav \tSaves the position of the scanned fil in the logfiles directory. Optional." +
"\n-ren \tThe scanned files be renamed. Optional." +
"\n\n--- the following switches is needed if Jvakt is to be used. Optional. ---" +
"\n-logs \tA switch to enable importing the checked logfile to the Jvakt database. Default is no import." +
"\n-jvakt \tA switch to enable report to Jvakt. Default is no connection to Jvakt." +
"\n-jvtype \tThe type of the Jvakt report. Optional. The default is \"R\"" +
"\n-id \tUsed as identifier in the Jvakt monitoring system." +
"\n-config \tThe directory where to find the Jvakt.properties file. like \"-config c:\\Temp\". Optional. Default is the current directory." +
"\n-charset \tDefault is UTF8. It could be UTF-16, UTF-32, ASCII, ISO8859_1...");
System.out.println("\n\n--- One or more of following files must be present in the current directory or the -config directory ---\n"+
"\nCheckLogs.csv \tOne file replacing the three following files."+
"\n \tLines starting with E; replaces the srch file."+
"\n \tLines starting with O; replaces the okay file."+
"\n \tLines starting with M; replaces the must file.\n"+
"\nCheckLogs.srch \t(deprecated) Strings considered errors if found in the log file. e.g. ORA-"+
"\nCheckLogs.okay \t(deprecated) Strings considered okay even when triggered by the CheckLogs.srch file. e.g. ORA-01013. May be empty." +
"\nCheckLogs.must \t(deprecated) Strings mandatory to be found in the log file. May be empty.\n"+
"\n\nErrorlevel is set the number of errors found, else 0."
);
System.exit(4);
}
if (swJvakt || swLogs) {
if (config == null ) configF = new File("Jvakt.properties");
else configF = new File(config,"Jvakt.properties");
System.out.println("---- Jvakt.CheckLogs: "+new Date()+" Version: "+version);
System.out.println("-config file: "+configF);
getProps();
}
Date today;
String pattern = new String("yyyy-MM-dd_HH-mm-ss");
SimpleDateFormat formatter;
formatter = new SimpleDateFormat(pattern);
today = new Date();
tdat = formatter.format(today);
getSetup();
getCsv();
if (mcount == 0 ) swMust = false;
// if (ecount == 0 && !swMust && !swLogs ) {
// System.out.println("***** CheckLogs is aborting! ** No error strings imported! *****");
// System.exit(12);
// }
if (swCsav && config == null ) {
System.out.println("***** CheckLogs is aborting! ** No -config provided! *****");
System.exit(12);
}
if (suf != null && pos != null) df = new DirFilter(suf, pos);
else if (suf != null) df = new DirFilter(suf);
else if (pos != null) df = new DirFilter(null, pos);
if (suf != null || pos != null) listf = dir.listFiles(df);
else listf = dir.listFiles();
System.out.println(tdat+"-- Number of files to scan: "+ listf.length);
for (int i = 0; i < listf.length; i++) {
if (listf[i].isDirectory()) continue;
System.out.println("\n"+tdat+"-- Checking: "+listf[i]);
if (swDummy) {
getSetup();
getCsv();
swDummy = false;
}
if (!swCharset) {
currI = i;
checkFileForBOM();
}
// System.out.println("\n -- ecount: "+ecount);
oldnamn = new File(listf[i].toString());
aFile = oldnamn.getName();
if (mcount > 0 ) swMust = true;
if (swPsav || swCsav) {
fis = new FileInputStream(oldnamn);
// in = new BufferedReader( new FileReader(oldnamn) );
try{ // read last position if present.
if (swPsav) inokay = new BufferedReader(new FileReader(listf[i]+".position"));
else inokay = new BufferedReader(new FileReader(configF+"/"+aFile+".position"));
if ((s = inokay.readLine())!= null) posprev = Integer.parseInt(s);
else posprev=0;
if ((s = inokay.readLine())!= null) strprev = s;
else strprev=null;
inokay.close();
} catch (Exception e) {
posprev = 0;
strprev=null;
}
System.out.println(tdat+"-- posprev: "+ posprev);
}
else if (swRename) { // Create new file name if the file is supposed to be renamed.
posprev = 0;
strprev = null;
nyttnamn = listf[i] + "." + tdat + ".sav";
newnamn = new File(nyttnamn);
System.out.println(tdat+"-- New name: "+ nyttnamn);
if (!oldnamn.renameTo(newnamn)) {
System.out.println(tdat+"-- Rename failed. Tries "+ oldnamn +" instead...");
aFile = oldnamn.getName();
fis = new FileInputStream(oldnamn);
// in = new BufferedReader(new FileReader(oldnamn));
}
else {
aFile = newnamn.getName();
fis = new FileInputStream(nyttnamn);
// in = new BufferedReader(new FileReader(nyttnamn));
}
}
else { // open the original file name.
fis = new FileInputStream(oldnamn);
// in = new BufferedReader( new FileReader(oldnamn) );
}
// InputStreamReader isr = new InputStreamReader(fis, "UTF8");
InputStreamReader isr = new InputStreamReader(fis, charset);
in = new BufferedReader(isr);
position = 0;
// lri.open(id2.trim(), agent, new java.sql.Timestamp((new Date(System.currentTimeMillis())).getTime()),"Jvakt","Jvakt","xz","localhost","5432");
if (swLogs) {
String id2 = id+"-"+listf[i].getName();
System.out.println(tdat+"-- Saving the log in the Jvakt DB: "+id2);
lri.open(id2.trim(), agent, new java.sql.Timestamp((new Date(System.currentTimeMillis())).getTime()),database,dbuser,dbpassword,dbhost,dbport);
}
line=0;
fileErrors=0;
while ((s = in.readLine()) != null) {
if (swPsav || swCsav) {
position++;
if ( position == 1 && !s.equals(strprev)) { posprev = 0; } // If it's a new logfile start from the beginning
if ( position == 1 ) { strprev = s; } // Store first row
if ( position <= posprev ) continue; // read next line if scanned previously.
}
if (s.length() > 2048) s = s.substring(0, 2048);
s=s.trim();
if (swLogs) {
line++;
lri.RowIns(s);
}
// check if any scan string is present in the line.
swWarn = false;
for ( int k = 0; k < ecount ; k++) {
// System.out.println("etab[k] " +etab[k]);
if (etab[k].contains("-*dummy-entry*-")) break;
etabSplit = etab[k].split("&");
// System.out.println("etabSplit.length " +etabSplit.length);
int eTabWarn= 0;
for ( int j = 0; j < etabSplit.length ; j++) {
// System.out.println("etabSplit[j] "+j+" "+etabSplit[j]+ " s "+s);
if (s.toUpperCase().indexOf(etabSplit[j]) >= 0) {
eTabWarn++;
}
}
// System.out.println("swWarn " +swWarn+" eTabWarn " +eTabWarn+" etabSplit.length " +etabSplit.length);
if (eTabWarn == etabSplit.length) {
etab[k] = "-*dummy-entry*-"; // only warn on first hit
swDummy = true;
swWarn = true;
}
}
// reset warning flag if hit is okay.
for ( int k = 0; k < tcount ; k++) {
tokaySplit = tokay[k].split("&");
int tokayWarn= 0;
for ( int j = 0; j < tokaySplit.length ; j++) {
if (s.toUpperCase().indexOf(tokaySplit[j]) >= 0) {
tokayWarn++;
}
}
if (tokayWarn == tokaySplit.length) {
swWarn = false;
}
}
// System.out.println("Mcount : "+mcount);
// raise warning if string are missing.
for ( int k = 0; k < mcount ; k++) {
// System.out.println("Must-check : "+s+" "+tmust[k]);
tmustSplit = tmust[k].split("&");
int tmustWarn= 0;
// System.out.println("tmustSplit.length " +tmustSplit.length+" tmustWarn:"+tmustWarn);
for ( int j = 0; j < tmustSplit.length ; j++) {
if (s.toUpperCase().indexOf(tmustSplit[j]) >= 0) tmustWarn++;
}
if (tmustWarn == tmustSplit.length) {
swMust = false;
}
}
// System.out.println(" swWarn = "+swWarn);
if (!swWarn) continue;
// c = null;
// if (s.length() > 256) s = s.substring(0, 255);
// if (s.compareTo(prev_s) == 0) continue;
// prev_s = s;
errors++;
fileErrors++;
t_desc = s;
t_desc =aFile+": "+t_desc;
if (t_desc.compareTo(t_desc_prev) !=0) { // Lessen number of duplicate messages in Jvakt
sendSTS(swWarn);
t_desc_prev = t_desc;
}
else {
System.out.println(" Message ignored: "+t_desc);
}
}
in.close();
if (swPsav || swCsav) {
if ( position < posprev ) { position=0; System.out.println("Re-seting position!"); } // store position in file
// ut = new PrintStream(new FileOutputStream(new String(listf[i]+".position"), false));
if (swPsav) ut = new PrintStream(new FileOutputStream(new String(listf[i]+".position"), false));
else ut = new PrintStream(new FileOutputStream(new String(configF+"/"+aFile+".position"), false));
ut.println(position);
ut.println(strprev);
ut.close();
}
if (swMust ) {
errors++;
fileErrors++;
swWarn=true;
t_desc = "Mandatory text strings are missing from the log file "+aFile+"!";
sendSTS(swWarn);
}
if (swLogs) {
if (line>0) lri.RowIns("<CheckLogs status> errors="+fileErrors);
lri.close();
System.out.println("-- Number of errors found in the file: "+ fileErrors);
}
}
swSlut = true;
if (errors == 0 ) {
swWarn=false;
if (listf.length == 0 ) {
if (swMust) {
errors++;
swWarn=true;
t_desc = " No logfiles found to scan! and missing must hits!";
}
else t_desc = " No logfiles found to scan!";
} else t_desc = "No errors found";
sendSTS(swWarn);
// System.out.println("# 02");
}
else {
swWarn=true;
t_desc = errors + " errors found in the log file(s).";
sendSTS(swWarn);
// System.out.println("# 03");
}
System.out.println("-- Number of total errors found: "+ errors);
if (errors == 0) System.exit(0);
else System.exit(errors);
}
// sends status to the server
static protected void sendSTS( boolean STS) throws IOException {
if (!swSlut) {
if (jvtype.startsWith("I")) {
if (t_desc.length() > 200) t_desc = t_desc.substring(0, 200);
t_desc =aFile+": "+t_desc;
}
// t_desc =t_desc+" : "+aFile;
}
if (swJvakt) {
System.out.println("--- " + id + " -- " + t_desc);
System.out.println("--- Connecting to "+jvhost+":"+jvport);
Message jmsg = new Message();
SendMsg jm = new SendMsg(jvhost, port);
System.out.println(jm.open());
jmsg.setId(id);
jmsg.setType(jvtype);
if (!STS) {
jmsg.setRptsts("OK");
}
else {
if (jvtype.startsWith("I")) jmsg.setRptsts("INFO");
else jmsg.setRptsts("ERR");
}
if (swSlut) {
if (!STS) jmsg.setRptsts("OK");
else {
if (jvtype.startsWith("I")) {
if (t_desc.length() > 200) t_desc = t_desc.substring(0, 200);
t_desc =aFile+": "+t_desc;
}
}
} else {
jmsg.setId(id+"_info");
if (!STS) {
jmsg.setRptsts("INFO");
}
else {
jmsg.setRptsts("ERR");
}
jmsg.setType("I");
}
jmsg.setBody(t_desc);
jmsg.setAgent(agent);
if (jm.sendMsg(jmsg)) System.out.println("--- Rpt Delivered -- " + id + " -- " + t_desc);
else System.out.println("--- Rpt Failed ---");
jm.close();
}
else {
System.out.println("--- " + t_desc);
}
}
static void getProps() {
Properties prop = new Properties();
InputStream input = null;
try {
input = new FileInputStream(configF);
prop.load(input);
// get the property value and print it out
if (swJvakt) {
jvport = prop.getProperty("jvport");
jvhost = prop.getProperty("jvhost");
port = Integer.parseInt(jvport);
}
if (swLogs) {
// get the property value and print it out
database = prop.getProperty("database");
dbuser = prop.getProperty("dbuser");
dbpassword = prop.getProperty("dbpassword");
if (dbpassword.startsWith("==y")) {
byte[] decodedBytes = Base64.getDecoder().decode(dbpassword.substring(3));
String decodedString = new String(decodedBytes);
dbpassword=decodedString;
}
dbhost = prop.getProperty("dbhost");
dbport = prop.getProperty("dbport");
if (database == null) {
System.out.println("database is miossing from Jvakt.properties. Logs are not imported to the Jvakt DB");
swLogs = false;
}
}
System.out.println("getProps jvport: " + jvport + " jvhost: "+jvhost + " dbhost: "+dbhost+ " dbport: "+dbport) ;
} catch (IOException ex) {
ex.printStackTrace();
}
try {
inet = InetAddress.getLocalHost();
System.out.println("-- Inet: "+inet);
agent = inet.toString();
}
catch (Exception e) { System.out.println(e); }
}
static void getCsv() throws IOException {
String s;
String[] tab = new String[1000];
File dircsv = new File(".");
if (config != null ) dircsv = new File(config);
String sufcsv = ".csv";
String poscsv = "CheckLogs";
DirFilter dfcsv = new DirFilter(sufcsv, poscsv);
File[] listfcsv = dircsv.listFiles(dfcsv);
System.out.println("-- Number of csv files found:"+ listfcsv.length);
for (int i = 0; i < listfcsv.length; i++) {
System.out.println("-- Importing: "+listfcsv[i]+"\n");
BufferedReader in = new BufferedReader(new FileReader(listfcsv[i]));
while ((s = in.readLine()) != null) {
if (s.length() == 0) continue;
if (s.startsWith("#")) continue;
// System.out.println("-- Row: "+s);
// splittar rad från fil
tab = s.split(";" , 2);
if (tab[0].startsWith("E")) etab[ecount++] = tab[1].toUpperCase();
if (tab[0].startsWith("O")) tokay[tcount++] = tab[1].toUpperCase();
if (tab[0].startsWith("M")) tmust[mcount++] = tab[1].toUpperCase();
}
in.close();
}
}
static void getSetup() {
String s;
// Importing error strings to search for.
ecount = 0;
etab = new String[1000];
try {
if (config != null ) {
configF = new File(config);
inokay = new BufferedReader(new FileReader(configF.toString()+"/CheckLogs.srch"));
s = configF.toString()+"/CheckLogs.srch";
}
else {
inokay = new BufferedReader(new FileReader("CheckLogs.srch"));
s = "CheckLogs.srch";
}
System.out.println("--- Importing strings considered error... File: "+s);
while((s = inokay.readLine())!= null) {
if (s.length() == 0) continue;
if (s.startsWith("#")) continue;
etab[ecount++] = s.toUpperCase();
// System.out.println( etab[ecount - 1]);
}
inokay.close();
} catch (Exception e) {
System.out.println("\n-- Not found: CheckLogs.srch");
}
// Importing strings approved despite hits.
tcount = 0;
tokay = new String[1000];
try {
if (config != null ) {
inokay = new BufferedReader(new FileReader(configF.toString()+"/CheckLogs.okay"));
s = configF.toString()+"/CheckLogs.okay";
}
else {
inokay = new BufferedReader(new FileReader("CheckLogs.okay"));
s = "CheckLogs.okay";
}
System.out.println("--- Importing strings considered okay... File: "+s);
while((s = inokay.readLine())!= null) {
if (s.length() == 0) continue;
if (s.startsWith("#")) continue;
tokay[tcount++] = s.toUpperCase();
// System.out.println( tokay[tcount - 1]);
}
inokay.close();
} catch (Exception e) {
System.out.println("-- Not found: CheckLogs.okay");
}
// Importing strings mandatory present to make the check to be okay.
mcount = 0;
tmust = new String[100];
try {
if (config != null ) {
inokay = new BufferedReader(new FileReader(configF.toString()+"/CheckLogs.must"));
s = configF.toString()+"/CheckLogs.must";
}
else {
inokay = new BufferedReader(new FileReader("CheckLogs.must"));
s = "CheckLogs.must";
}
System.out.println("--- Importing mandatory strings... File: "+s);
while((s = inokay.readLine())!= null) {
if (s.length() == 0) continue;
if (s.startsWith("#")) continue;
tmust[mcount++] = s.toUpperCase();
// System.out.println( tmust[mcount - 1]);
}
inokay.close();
} catch (Exception e) {
System.out.println("-- Not found: CheckLogs.must");
}
}
static void checkFileForBOM() {
charset = "UTF8";
swUTF8BOM = false;
swUTF16BEBOM = false;
swUTF16LEBOM = false;
byte[] bom = new byte[3];
Path path = Paths.get(listf[currI].getPath());
try {
InputStream is = new FileInputStream(path.toFile());
is.read(bom);
String content = new String(Hex.encodeHex(bom));
System.out.println("Content of first three bytes (BOM) "+content);
if ("00".equalsIgnoreCase(content.substring(0, 2))) {
System.out.println("** Found out the input file probably is UCS-2 BE without BOM. Trying -charset UTF-16");
swUTF16BEBOM = true;
charset = "UTF-16";
}
if ("feff".equalsIgnoreCase(content.substring(0, 4))) {
System.out.println("** Found the input file to be UCS-2 BE BOM. Using -charset UTF-16");
swUTF16BEBOM = true;
charset = "UTF-16";
}
if ("00".equalsIgnoreCase(content.substring(2, 4))) {
System.out.println("** Found out the input file probably is UCS-2 LE without BOM. Trying -charset UTF-16");
swUTF16LEBOM = true;
charset = "UTF-16";
}
if ("fffe".equalsIgnoreCase(content.substring(0, 4))) {
System.out.println("** Found the input file to be UCS-2 LE BOM. Using -charset UTF-16");
swUTF16LEBOM = true;
charset = "UTF-16";
}
if ("efbbbf".equalsIgnoreCase(content.substring(0, 6))) {
System.out.println("** Found the input file to be UCS8 BOM. Using -charset UTF8");
swUTF8BOM = true;
charset = "UTF8";
}
is.close();
} catch (FileNotFoundException fnfe) {
System.out.println("File not found "+configF.getPath()+"\n"+fnfe);
}
catch (IOException ioe) {
System.out.println("IO error "+configF.getPath()+"\n"+ioe);
}
}
static private String getVersion() {
String version = "0";
try {
Class<?> c1 = Class.forName("Jvakt.Version",false,ClassLoader.getSystemClassLoader());
Version ver = new Version();
version = ver.getVersion();
}
catch (java.lang.ClassNotFoundException ex) {
version = "?";
}
return version;
}
}