Autopsy  4.0
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 public class FileTypeIdIngestModule implements FileIngestModule {
38 
39  private static final Logger logger = Logger.getLogger(FileTypeIdIngestModule.class.getName());
40  private long jobId;
41  private static final HashMap<Long, IngestJobTotals> totalsForIngestJobs = new HashMap<>();
44 
54  @Deprecated
55  public static boolean isMimeTypeDetectable(String mimeType) {
56  try {
57  return new FileTypeDetector().isDetectable(mimeType);
59  logger.log(Level.SEVERE, "Failed to create file type detector", ex); //NON-NLS
60  return false;
61  }
62  }
63 
69  }
70 
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(NbBundle.getMessage(this.getClass(), "FileTypeIdIngestModule.startUp.fileTypeDetectorInitializationException.msg"), ex);
82  }
83  }
84 
88  @Override
89  public ProcessResult process(AbstractFile file) {
90 
96  try {
97  long startTime = System.currentTimeMillis();
98  fileTypeDetector.getFileType(file);
99  addToTotals(jobId, (System.currentTimeMillis() - startTime));
100  return ProcessResult.OK;
101  } catch (Exception e) {
102  logger.log(Level.WARNING, String.format("Error while attempting to determine file type of file %d", file.getId()), e); //NON-NLS
103  return ProcessResult.ERROR;
104  }
105  }
106 
110  @Override
111  public void shutDown() {
116  if (refCounter.decrementAndGet(jobId) == 0) {
117  IngestJobTotals jobTotals;
118  synchronized (this) {
119  jobTotals = totalsForIngestJobs.remove(jobId);
120  }
121  if (jobTotals != null) {
122  StringBuilder detailsSb = new StringBuilder();
123  detailsSb.append("<table border='0' cellpadding='4' width='280'>"); //NON-NLS
124  detailsSb.append("<tr><td>").append(FileTypeIdModuleFactory.getModuleName()).append("</td></tr>"); //NON-NLS
125  detailsSb.append("<tr><td>") //NON-NLS
126  .append(NbBundle.getMessage(this.getClass(), "FileTypeIdIngestModule.complete.totalProcTime"))
127  .append("</td><td>").append(jobTotals.matchTime).append("</td></tr>\n"); //NON-NLS
128  detailsSb.append("<tr><td>") //NON-NLS
129  .append(NbBundle.getMessage(this.getClass(), "FileTypeIdIngestModule.complete.totalFiles"))
130  .append("</td><td>").append(jobTotals.numFiles).append("</td></tr>\n"); //NON-NLS
131  detailsSb.append("</table>"); //NON-NLS
133  NbBundle.getMessage(this.getClass(),
134  "FileTypeIdIngestModule.complete.srvMsg.text"),
135  detailsSb.toString()));
136  }
137  }
138  }
139 
147  private static synchronized void addToTotals(long jobId, long matchTimeInc) {
148  IngestJobTotals ingestJobTotals = totalsForIngestJobs.get(jobId);
149  if (ingestJobTotals == null) {
150  ingestJobTotals = new IngestJobTotals();
151  totalsForIngestJobs.put(jobId, ingestJobTotals);
152  }
153 
154  ingestJobTotals.matchTime += matchTimeInc;
155  ingestJobTotals.numFiles++;
156  totalsForIngestJobs.put(jobId, ingestJobTotals);
157  }
158 
159  private static class IngestJobTotals {
160 
161  long matchTime = 0;
162  long numFiles = 0;
163  }
164 
165 }
static final HashMap< Long, IngestJobTotals > totalsForIngestJobs
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:166
static synchronized void addToTotals(long jobId, long matchTimeInc)
static synchronized IngestServices getInstance()

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