Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DroneExtractor.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2020 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.modules.drones;
20 
21 import java.io.File;
22 import java.io.IOException;
23 import java.nio.file.Path;
24 import java.nio.file.Paths;
30 import org.sleuthkit.datamodel.AbstractFile;
31 import org.sleuthkit.datamodel.Content;
32 import org.sleuthkit.datamodel.SleuthkitCase;
33 
37 abstract class DroneExtractor {
38 
39  static private final String TEMP_FOLDER_NAME = "DroneExtractor"; //NON-NLS
40  private final Case currentCase;
41 
47  protected DroneExtractor() throws DroneIngestException {
48  try {
49  currentCase = Case.getCurrentCaseThrows();
50  } catch (NoCurrentCaseException ex) {
51  throw new DroneIngestException("Unable to create drone extractor, no open case.", ex); //NON-NLS
52  }
53  }
54 
55  abstract void process(Content dataSource, IngestJobContext context, DataSourceIngestModuleProgress progressBar) throws DroneIngestException;
56 
57  abstract String getName();
58 
64  final protected Case getCurrentCase() {
65  return currentCase;
66  }
67 
73  final protected SleuthkitCase getSleuthkitCase() {
74  return currentCase.getSleuthkitCase();
75  }
76 
86  protected Path getExtractorTempPath() {
87  Path path = Paths.get(currentCase.getTempDirectory(), TEMP_FOLDER_NAME, this.getClass().getCanonicalName());
88  File dir = path.toFile();
89  if (!dir.exists()) {
90  dir.mkdirs();
91  }
92 
93  return path;
94  }
95 
106  protected File getTemporaryFile(IngestJobContext context, AbstractFile file) throws DroneIngestException {
107  String tempFileName = file.getName() + file.getId() + file.getNameExtension();
108 
109  Path tempFilePath = Paths.get(getExtractorTempPath().toString(), tempFileName);
110 
111  try {
112  ContentUtils.writeToFile(file, tempFilePath.toFile(), context::dataSourceIngestIsCancelled);
113  } catch (IOException ex) {
114  throw new DroneIngestException(String.format("Unable to create temp file %s for abstract file %s objectID: %d", tempFilePath.toString(), file.getName(), file.getId()), ex); //NON-NLS
115  }
116 
117  return tempFilePath.toFile();
118  }
119 
120 }

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.