I'm looking forward to parsing a LAS file (Log ASCII Standard), this type of file has different parts with different syntax's, example here:
"file.las"
~V
VERS . 3.00 : Comments
DLM . COMMA
~Curve
RHOB.M
~Data
1000.5, 35.2
1001.0, 40.6
Here's what I'm currently doing to parse my file, I'm using different for loop for each Syntax.
BufferedReader file = new BufferedReader(new FileReader(path));
System.out.print("Searching ~V");
for (String line = file.readLine(); line != null; line = file.readLine()) {
if(line.contains("~V")){
System.out.println("Success");
break;
}else{
//Do Nothing
}
}
System.out.print("Searching VERS");
for (String line = file.readLine(); line != null; line = file.readLine()) {
line = line.trim();
if(line.startsWith("VERS.")){
line = line.replaceAll(" ", "");
String lineWithoutComment = line.split(":")[0];
lasFileVO.setVersion(lineWithoutComment);
break;
}else{
//Do Nothing
}
}
if(lasFileVO.getVersion.startWith("3.0")){
System.out.print("Searching DLM");
//For loop
}
The parsing is working, and I find it very easy to understand for the other developers (which is a good thing).
Is there a better way to parse a file, containing different parts with different syntax, then my series of For Loops?
EDIT:
I already saw the while loop way, but I don't see how I could implement that:
while ( (line = bufRead.readLine()) != null)
{
}
... with a file with different syntaxes at different places without adding a tons of conditions. With a list of for loop, I don't need to check a lot of condition for each line.