Created
August 28, 2009 12:45
-
-
Save dizzi/176971 to your computer and use it in GitHub Desktop.
test1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package cz.ing; | |
import java.io.BufferedReader; | |
import java.io.FileReader; | |
import java.util.ArrayList; | |
public class Peck { | |
static String screenStart = "CHARGE CODE INQUIRY"; | |
static String inputData = "3,18,22;3,41,45;4,20,22;4,42,48"; | |
static String inputFile = "c:\\dizzi\\prj\\keyfiles\\chrgcapt.txt"; | |
static boolean debug = false; | |
public static void main(String[] args) throws Exception { | |
if(args.length<3){ | |
System.out.println("Wrong parameters count! \n" + | |
"Usage:\n" + | |
"java -jar Peck <Input file> <Input fields> <First line string> [debug] \n" + | |
"\n" + | |
"Input file - file containing text\n" + | |
"ie: c:\\foo\\bar.txt\n" + | |
"Input fields - fields in format line,start,end;line2,start,end\n" + | |
"ie: '3,18,22;3,41,45;4,20,22;4,42,48'\n" + | |
"First line string - input fields' lines are counted from line containing this\n" + | |
"ie: 'CHARGE CODE INQUIRY'\n" + | |
"Debug - optional parameter, | is inserted between fields\n" + | |
"ie: debug"); | |
return; | |
} | |
Peck peck = new Peck(); | |
BufferedReader datain = new BufferedReader(new FileReader(args[0])); | |
ArrayList<Field> fields = peck.prepareData(args[1]); | |
screenStart = args[2]; | |
if(args.length>3) | |
debug = true; | |
peck.hard(datain, fields, debug); | |
} | |
void hard(BufferedReader datain, ArrayList<Field> fields, boolean debug) throws Exception{ | |
String line = ""; | |
int screenCounter=0; | |
String output = ""; | |
while (null != (line = datain.readLine())) { | |
if (line.contains(screenStart)){ | |
screenCounter = 1; | |
if(!output.equals("")) | |
System.out.println(output); | |
output = ""; | |
} | |
output += getData(line, screenCounter, fields, debug); | |
screenCounter++; | |
} | |
} | |
ArrayList<Field> prepareData(String inputData){ | |
ArrayList<Field> al = new ArrayList<Field>(); | |
String[] fields = inputData.split(";"); | |
for(String field : fields){ | |
al.add(new Field(field)); | |
} | |
return al; | |
} | |
String getData(String line,int lineNum ,ArrayList<Field> fields, boolean debug){ | |
String out=""; | |
for(Field f : fields){ | |
if(f.line==lineNum){ | |
out += line.substring(f.start, f.end); | |
if(debug) | |
out+="|"; | |
} | |
} | |
return out; | |
} | |
class Field { | |
public int start; | |
public int end; | |
public int line; | |
public String name; | |
Field(String definition){ | |
String[] def = definition.split(","); | |
line = Integer.parseInt(def[0]); | |
start = Integer.parseInt(def[1]); | |
end = Integer.parseInt(def[2]); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment