- I have a GB file of binary data.
- In this file are many sections of data.
- Each section of data is wrapped in crap that I don't want.
- In the crap that I don't want there are constant indicator markers that tell me when the data is coming up.
- I read a number of bytes, read the crap that I don't want in order to find a section of data, then parse only the data to an output file.
So far I have accomplished this. Except it only parses once, one section, then stops. The program is still running and the output file only has one section of parsed data in it. So it is hung up. I need the program to continue from its last section, looking for the next marker and then parse the next section and continue to do so until eof. Here is my code:
private static void startParse(File inFile) throws IOException{
boolean endOfFile = false;
DataInputStream dis = new DataInputStream(new FileInputStream(inFile));
while (!endOfFile){
try {
int integer;
long l;
while((l = (integer = dis.readInt())) != MARKER) {
//Don't do anything
}
for (int i = 0; i < 11; i++){
dis.read();
}
// ***************** checksum value *****************
byte[] checksum = new byte[2];
checksum[0] = (byte) dis.read();
checksum[1] = (byte) dis.read();
// ********************** data **********************
byte[] data = new byte[1016];
for(int i = 0; i < 1016; i++){
data[i] = (byte) dis.read();
}
for (int i = 0; i < 4; i++){
dis.read();
}
// ********************** fecf **********************
byte[] fecf = new byte[2];
fecf[0] = (byte) dis.read();
fecf[1] = (byte) dis.read();
// ***************** output data ********************
if (checksumCheck(checksum) && fecfCheck(fecf)){
FileOutputStream output = new FileOutputStream("ParsedData", true);
try{
output.write(data);
}
finally{
output.close();
}
}
else {
FileOutputStream output = new FileOutputStream("ParsedData", true);
try{
output.write(36606); //TODO: Change value to bad data flag.
}
finally{
output.close();
}
}
}
catch (EOFException eof) {
System.out.println("catch");
endOfFile = true;
}
}
dis.close();
}