Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
FileTypeIdIngestModule.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-2015 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.filetypeid;
20 
21 import java.util.HashMap;
22 import java.util.logging.Level;
23 import org.openide.util.NbBundle;
33 
38 public class FileTypeIdIngestModule implements FileIngestModule {
39 
40  private static final Logger logger = Logger.getLogger(FileTypeIdIngestModule.class.getName());
42  private long jobId;
43  private static final HashMap<Long, IngestJobTotals> totalsForIngestJobs = new HashMap<>();
46 
55  @Deprecated
56  public static boolean isMimeTypeDetectable(String mimeType) {
57  try {
58  return new FileTypeDetector().isDetectable(mimeType);
60  logger.log(Level.SEVERE, "Failed to create file type detector", ex); //NON-NLS
61  return false;
62  }
63  }
64 
72  this.settings = settings;
73  }
74 
78  @Override
79  public void startUp(IngestJobContext context) throws IngestModuleException {
80  jobId = context.getJobId();
81  refCounter.incrementAndGet(jobId);
82  try {
83  fileTypeDetector = new FileTypeDetector();
85  throw new IngestModuleException(NbBundle.getMessage(this.getClass(), "FileTypeIdIngestModule.startUp.fileTypeDetectorInitializationException.msg"));
86  }
87  }
88 
92  @Override
94 
98  if (settings.skipKnownFiles() && (file.getKnown() == FileKnown.KNOWN)) {
99  return ProcessResult.OK;
100  }
101 
107  try {
108  long startTime = System.currentTimeMillis();
109  fileTypeDetector.getFileType(file);
110  addToTotals(jobId, (System.currentTimeMillis() - startTime));
111  return ProcessResult.OK;
112  } catch (Exception e) {
113  logger.log(Level.WARNING, String.format("Error while attempting to determine file type of file %d", file.getId()), e); //NON-NLS
114  return ProcessResult.ERROR;
115  }
116  }
117 
121  @Override
122  public void shutDown() {
127  if (refCounter.decrementAndGet(jobId) == 0) {
128  IngestJobTotals jobTotals;
129  synchronized (this) {
130  jobTotals = totalsForIngestJobs.remove(jobId);
131  }
132  if (jobTotals != null) {
133  StringBuilder detailsSb = new StringBuilder();
134  detailsSb.append("<table border='0' cellpadding='4' width='280'>"); //NON-NLS
135  detailsSb.append("<tr><td>").append(FileTypeIdModuleFactory.getModuleName()).append("</td></tr>"); //NON-NLS
136  detailsSb.append("<tr><td>") //NON-NLS
137  .append(NbBundle.getMessage(this.getClass(), "FileTypeIdIngestModule.complete.totalProcTime"))
138  .append("</td><td>").append(jobTotals.matchTime).append("</td></tr>\n"); //NON-NLS
139  detailsSb.append("<tr><td>") //NON-NLS
140  .append(NbBundle.getMessage(this.getClass(), "FileTypeIdIngestModule.complete.totalFiles"))
141  .append("</td><td>").append(jobTotals.numFiles).append("</td></tr>\n"); //NON-NLS
142  detailsSb.append("</table>"); //NON-NLS
144  NbBundle.getMessage(this.getClass(),
145  "FileTypeIdIngestModule.complete.srvMsg.text"),
146  detailsSb.toString()));
147  }
148  }
149  }
150 
158  private static synchronized void addToTotals(long jobId, long matchTimeInc) {
159  IngestJobTotals ingestJobTotals = totalsForIngestJobs.get(jobId);
160  if (ingestJobTotals == null) {
161  ingestJobTotals = new IngestJobTotals();
162  totalsForIngestJobs.put(jobId, ingestJobTotals);
163  }
164 
165  ingestJobTotals.matchTime += matchTimeInc;
166  ingestJobTotals.numFiles++;
167  totalsForIngestJobs.put(jobId, ingestJobTotals);
168  }
169 
170  private static class IngestJobTotals {
171 
172  long matchTime = 0;
173  long numFiles = 0;
174  }
175 
176 }
static final HashMap< Long, IngestJobTotals > totalsForIngestJobs
static IngestMessage createMessage(MessageType messageType, String source, String subject, String detailsHtml)
void postMessage(final IngestMessage message)
static synchronized void addToTotals(long jobId, long matchTimeInc)
static Logger getLogger(String name)
Definition: Logger.java:131
static synchronized IngestServices getInstance()

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.