My code below only parses through the data file once. I'm trying to get it to parse through the whole file. Every time it finds a marker, parse the data and append it to the output file. Currently it successfully parses the data once and then stops. Can't figure out how to keep it looping until eof. The data is 4 byte aligned and is in a input binary file.
private static void startParse(File inFile) throws IOException {
boolean markerFound = false;
for (int offset = 0; !markerFound && offset < 4; offset++){
DataInputStream dis = new DataInputStream(new FileInputStream(inFile));
for (int i = 0; i < offset; i++){
dis.read();
}
try {
int integer;
long l;
while((l = (integer = dis.readInt())) != MARKER) {
//Don't do anything
}
markerFound = true;
for (int i = 0; i < 11; i++){
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();
}
// ***************** output data ********************
if (checksumCheck(checksum) && fecfCheck(fecf)){
FileOutputStream output = new FileOutputStream("ParsedData", true);
try{
output.write(data);
}
finally{
output.close();
}
}
}
catch (EOFException eof) {
}
dis.close();
}
}