/*
* DecryptFileParser.java
*
* Created on 18 de junio de 2007, 17:34
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package gps.garmin.img;
import gps.garmin.img.structure.Header;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
/**
*
* @author aranzuglia
*/
public class DecryptFileParser extends FileParser {
private File resultFile;
protected void finalize() throws Throwable {
}
public DecryptFileParser(File imgFile, File resultFile) throws ParseException {
super(imgFile);
try {
this.resultFile = resultFile;
if (!resultFile.exists()) {
resultFile.createNewFile();
}
} catch (IOException e) {
e.printStackTrace();
throw new ParseException(e.getMessage());
}
}
public void parse() throws ParseException {
try {
parseXorByte(new Header());
if (isXorEd) {
int xorByte = currentByte;
BufferedOutputStream out =
new BufferedOutputStream(new FileOutputStream(resultFile));
out.write(currentByte);
for (int i = 0; i < imgFile.length() - 1; i++) {
nextByte();
out.write(currentByte ^ xorByte);
}
out.flush();
out.close();
}
} catch (IOException e) {
e.printStackTrace();
throw new ParseException(e.getMessage());
}
}
}