19 package org.sleuthkit.autopsy.modules.drones;
 
   22 import java.io.FileNotFoundException;
 
   23 import java.io.IOException;
 
   24 import src.Files.ConvertDat;
 
   25 import src.Files.CsvWriter;
 
   26 import src.Files.DatFile;
 
   27 import src.Files.DJIAssistantFile;
 
   28 import src.Files.Exception.FileEnd;
 
   29 import src.Files.Exception.NotDatFile;
 
   35 final class DATDumper {
 
   54     void dumpDATFile(String datFilePath, String outputFilePath, 
boolean overWriteExisting) 
throws DroneIngestException {
 
   56         validateOutputFile(outputFilePath, overWriteExisting);
 
   57         if (!isDATFile(datFilePath)) {
 
   61         DatFile datFile = null;
 
   62         try (CsvWriter writer = 
new CsvWriter(outputFilePath)) {
 
   64             datFile = DatFile.createDatFile(datFilePath);
 
   71             ConvertDat convertDat = datFile.createConVertDat();
 
   76             convertDat.sampleRate = 1;
 
   80             if (datFile.gpsLockTick != -1) {
 
   81                 convertDat.tickRangeLower = datFile.gpsLockTick;
 
   84             if (datFile.lastMotorStopTick != -1) {
 
   85                 convertDat.tickRangeUpper = datFile.lastMotorStopTick;
 
   88             convertDat.setCsvWriter(writer);
 
   89             convertDat.createRecordParsers();
 
   94             convertDat.analyze(
true);
 
   96         } 
catch (IOException | NotDatFile | FileEnd ex) {
 
   97             throw new DroneIngestException(String.format(
"Failed to dump DAT file to csv.  DAT = %s, CSV = %s", datFilePath, outputFilePath), ex); 
 
   99             if (datFile != null) {
 
  116     private void validateOutputFile(String outputFileName, 
boolean overWriteExisting) 
throws DroneIngestException {
 
  117         File csvFile = 
new File(outputFileName);
 
  119         if (csvFile.exists()) {
 
  120             if (overWriteExisting) {
 
  123                 throw new DroneIngestException(String.format(
"Unable to dump DAT file. overWriteExsiting is false and DAT output csv file exists: %s", outputFileName)); 
 
  137         File datFile = 
new File(datFilePath);
 
  139         if (!datFile.exists()) {
 
  140             throw new DroneIngestException(String.format(
"Unable to dump DAT file DAT file does not exist: %s", datFilePath)); 
 
  144             return DatFile.isDatFile(datFilePath) || DJIAssistantFile.isDJIDat(datFile);
 
  145         } 
catch (FileNotFoundException ex) {
 
  146             throw new DroneIngestException(String.format(
"Unable to dump DAT file. File not found %s", datFilePath), ex);