String fileName;
long fileSize;
String result;
String[] fields;
FileManager fileManager = Case.getCurrentCase().getServices().getFileManager();
// create and initialize the list to put into the database
List<CarvedFileContainer> carvedFileContainer = new ArrayList<>();
// create and initialize a line
String line = in.readLine();
// loop until an empty line is read
reachedEndOfFile:
while (!line.isEmpty()) {
while (!line.contains("<fileobject>")) //NON-NLS
{
if (line.equals("</dfxml>")) //NON-NLS
{ // We have found the end. Break out of both loops and move on to processing.
line = "";
break reachedEndOfFile;
}
line = in.readLine();
}
List<TskFileRange> ranges = new ArrayList<>();
// read filename line
line = in.readLine();
fileName = getValue("filename", line); //NON-NLS
Path p = Paths.get(fileName);
if (p.startsWith(basePath)) {
fileName = p.getFileName().toString();
}
line = in.readLine(); /// read filesize line
fileSize = Long.parseLong(getValue("filesize", line)); //NON-NLS
in.readLine(); /// eat a line and move on to the next
line = in.readLine(); /// now get next valid line
while (line.contains("<byte_run")) //NON-NLS
{
result = line.replaceAll("[\t ]*<byte_run offset='", ""); //NON-NLS
result = result.replaceAll("'[\t ]*img_offset='", " "); //NON-NLS
result = result.replaceAll("'[\t ]*len='", " "); //NON-NLS
result = result.replaceAll("'/>[\t ]*", ""); //NON-NLS
fields = result.split(" "); /// offset, image offset, length //NON-NLS
ranges.add((new TskFileRange(af.convertToImgOffset(Long.parseLong(fields[1])), Long.parseLong(fields[2]), ranges.size())));
// read the next line
line = in.readLine();
}
carvedFileContainer.add(new CarvedFileContainer(fileName, fileSize, id, ranges));
}
return fileManager.addCarvedFiles(carvedFileContainer);
}
catch (IOException | NumberFormatException | TskCoreException ex) {
logger.log(Level.SEVERE, "Error parsing PhotoRec output and inserting it into the database: {0}", ex); //NON_NLS
}