Source:
private void addExtractedFiles(File src, Path resultsPath, List<Content> newDataSources) throws TskCoreException, UnsupportedEncodingException, IOException { SleuthkitCase skCase = Case.getCurrentCase().getSleuthkitCase(); SleuthkitCase.CaseDbTransaction trans = null; try { trans = skCase.beginTransaction(); LocalFilesDataSource localFilesDataSource = skCase.addLocalFilesDataSource(deviceId, this.src.getName(), timeZone, trans); LocalFileImporter fileImporter = new LocalFileImporter(skCase, trans); try (BufferedReader br = new BufferedReader(new InputStreamReader( new FileInputStream(resultsPath.toFile()), "UTF8"))) { String line; br.readLine(); int lineNumber = 2; while ((line = br.readLine()) != null) { String[] fields = line.split("\t", -1); if (fields.length != 14) { throw new IOException(Bundle.AddLogicalImageTask_notEnoughFields(lineNumber, fields.length, 14)); } String vhdFilename = fields[0]; String filename = fields[7]; String parentPath = fields[8]; String extractedFilePath = fields[9]; String crtime = fields[10]; String mtime = fields[11]; String atime = fields[12]; String ctime = fields[13]; parentPath = ROOT_STR + "/" + vhdFilename + "/" + parentPath; fileImporter.addLocalFile( Paths.get(src.toString(), extractedFilePath).toFile(), filename, parentPath, Long.parseLong(ctime), Long.parseLong(crtime), Long.parseLong(atime), Long.parseLong(mtime), localFilesDataSource); lineNumber++; } trans.commit(); newDataSources.add(localFilesDataSource); } } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Error adding local files", ex); if (null != trans) { try { trans.rollback(); } catch (TskCoreException ex2) { LOGGER.log(Level.SEVERE, String.format("Failed to rollback transaction after exception: %s", ex.getMessage()), ex2); } } } }

Target:
private void addExtractedFiles(File src, Path resultsPath, List<Content> newDataSources) throws TskCoreException, IOException { SleuthkitCase skCase = Case.getCurrentCase().getSleuthkitCase(); SleuthkitCase.CaseDbTransaction trans = null; try { trans = skCase.beginTransaction(); LocalFilesDataSource localFilesDataSource = skCase.addLocalFilesDataSource(deviceId, this.src.getName(), timeZone, trans); LocalFileImporter fileImporter = new LocalFileImporter(skCase, trans); try (BufferedReader br = new BufferedReader(new InputStreamReader( new FileInputStream(resultsPath.toFile()), "UTF8"))) { String line; br.readLine(); int lineNumber = 2; while ((line = br.readLine()) != null) { if (cancelled) { rollbackTransaction(trans); return; } String[] fields = line.split("\t", -1); if (fields.length != 14) { rollbackTransaction(trans); throw new IOException(Bundle.AddLogicalImageTask_notEnoughFields(lineNumber, fields.length, 14)); } String vhdFilename = fields[0]; String filename = fields[7]; String parentPath = fields[8]; String extractedFilePath = fields[9]; String crtime = fields[10]; String mtime = fields[11]; String atime = fields[12]; String ctime = fields[13]; parentPath = ROOT_STR + "/" + vhdFilename + "/" + parentPath; fileImporter.addLocalFile( Paths.get(src.toString(), extractedFilePath).toFile(), filename, parentPath, Long.parseLong(ctime), Long.parseLong(crtime), Long.parseLong(atime), Long.parseLong(mtime), localFilesDataSource); lineNumber++; } } trans.commit(); newDataSources.add(localFilesDataSource); } catch (NumberFormatException | TskCoreException ex) { LOGGER.log(Level.SEVERE, "Error adding extracted files", ex); rollbackTransaction(trans); throw new TskCoreException("Error adding extracted files", ex); } }