Autopsy  4.4
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;
29 import org.sleuthkit.datamodel.AbstractFile;
32 
37 @NbBundle.Messages({
38  "CannotRunFileTypeDetection=Unable to run file type detection."
39 })
40 public class FileTypeIdIngestModule implements FileIngestModule {
41 
42  private static final Logger logger = Logger.getLogger(FileTypeIdIngestModule.class.getName());
43  private long jobId;
44  private static final HashMap<Long, IngestJobTotals> totalsForIngestJobs = new HashMap<>();
45  private static final IngestModuleReferenceCounter refCounter = new IngestModuleReferenceCounter();
47 
57  @Deprecated
58  public static boolean isMimeTypeDetectable(String mimeType) {
59  try {
60  return new FileTypeDetector().isDetectable(mimeType);
62  logger.log(Level.SEVERE, "Failed to create file type detector", ex); //NON-NLS
63  return false;
64  }
65  }
66 
72  }
73 
74  @Override
75  public void startUp(IngestJobContext context) throws IngestModuleException {
76  jobId = context.getJobId();
77  refCounter.incrementAndGet(jobId);
78  try {
79  fileTypeDetector = new FileTypeDetector();
81  throw new IngestModuleException(Bundle.CannotRunFileTypeDetection(), ex);
82  }
83  }
84 
85  @Override
86  public ProcessResult process(AbstractFile file) {
92  try {
93  long startTime = System.currentTimeMillis();
94  fileTypeDetector.getFileType(file);
95  addToTotals(jobId, (System.currentTimeMillis() - startTime));
96  return ProcessResult.OK;
97  } catch (Exception e) {
98  logger.log(Level.WARNING, String.format("Error while attempting to determine file type of file %d", file.getId()), e); //NON-NLS
99  return ProcessResult.ERROR;
100  }
101  }
102 
103  @Override
104  public void shutDown() {
109  if (refCounter.decrementAndGet(jobId) == 0) {
110  IngestJobTotals jobTotals;
111  synchronized (this) {
112  jobTotals = totalsForIngestJobs.remove(jobId);
113  }
114  if (jobTotals != null) {
115  StringBuilder detailsSb = new StringBuilder();
116  detailsSb.append("<table border='0' cellpadding='4' width='280'>"); //NON-NLS
117  detailsSb.append("<tr><td>").append(FileTypeIdModuleFactory.getModuleName()).append("</td></tr>"); //NON-NLS
118  detailsSb.append("<tr><td>") //NON-NLS
119  .append(NbBundle.getMessage(this.getClass(), "FileTypeIdIngestModule.complete.totalProcTime"))
120  .append("</td><td>").append(jobTotals.matchTime).append("</td></tr>\n"); //NON-NLS
121  detailsSb.append("<tr><td>") //NON-NLS
122  .append(NbBundle.getMessage(this.getClass(), "FileTypeIdIngestModule.complete.totalFiles"))
123  .append("</td><td>").append(jobTotals.numFiles).append("</td></tr>\n"); //NON-NLS
124  detailsSb.append("</table>"); //NON-NLS
126  NbBundle.getMessage(this.getClass(),
127  "FileTypeIdIngestModule.complete.srvMsg.text"),
128  detailsSb.toString()));
129  }
130  }
131  }
132 
140  private static synchronized void addToTotals(long jobId, long matchTimeInc) {
141  IngestJobTotals ingestJobTotals = totalsForIngestJobs.get(jobId);
142  if (ingestJobTotals == null) {
143  ingestJobTotals = new IngestJobTotals();
144  totalsForIngestJobs.put(jobId, ingestJobTotals);
145  }
146 
147  ingestJobTotals.matchTime += matchTimeInc;
148  ingestJobTotals.numFiles++;
149  totalsForIngestJobs.put(jobId, ingestJobTotals);
150  }
151 
152  private static class IngestJobTotals {
153 
154  long matchTime = 0;
155  long numFiles = 0;
156  }
157 
158 }
static IngestMessage createMessage(MessageType messageType, String source, String subject, String detailsHtml)
void postMessage(final IngestMessage message)
synchronized static Logger getLogger(String name)
Definition: Logger.java:161
static synchronized void addToTotals(long jobId, long matchTimeInc)
static synchronized IngestServices getInstance()

Copyright © 2012-2016 Basis Technology. Generated on: Tue Jun 13 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.