Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
TikaFileTypeDetector.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2014 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.SortedSet;
22 import org.apache.tika.Tika;
23 import org.apache.tika.mime.MediaType;
24 import org.apache.tika.mime.MimeTypes;
25 
30 
35 @Deprecated
36 public class TikaFileTypeDetector {
37 
38  private static final Tika tikaInst = new Tika(); //calling detect() with this should be thread-safe
39  private final int BUFFER_SIZE = 64 * 1024; //how many bytes to pass in
40  private final byte buffer[] = new byte[BUFFER_SIZE];
41 
51  @Deprecated
52  public synchronized String detectAndSave(AbstractFile abstractFile) throws TskCoreException {
53  String mimeType = detect(abstractFile);
54  if (mimeType != null) {
55  // add artifact
56  BlackboardArtifact getInfoArt = abstractFile.getGenInfoArtifact();
58  getInfoArt.addAttribute(batt);
59 
60  // we don't fire the event because we just updated TSK_GEN_INFO, which isn't displayed in the tree and is vague.
61  }
62  return mimeType;
63  }
64 
72  @Deprecated
73  public synchronized String detect(AbstractFile abstractFile) {
74  try {
75  byte buf[];
76  int len = abstractFile.read(buffer, 0, BUFFER_SIZE);
77  if (len < BUFFER_SIZE) {
78  buf = new byte[len];
79  System.arraycopy(buffer, 0, buf, 0, len);
80  } else {
81  buf = buffer;
82  }
83 
84  String mimetype = tikaInst.detect(buf, abstractFile.getName());
85  // Remove tika's name out of the general types like msoffice and ooxml
86  return mimetype.replace("tika-", ""); //NON-NLS
87  } catch (Exception ex) {
88  //do nothing
89  }
90  return null;
91  }
92 
102  @Deprecated
103  public boolean isMimeTypeDetectable(String mimeType) {
104  boolean ret = false;
105 
106  SortedSet<MediaType> m = MimeTypes.getDefaultMimeTypes().getMediaTypeRegistry().getTypes();
107  String[] split = mimeType.split("/");
108 
109  if (split.length == 2) {
110  String type = split[0];
111  String subtype = split[1];
112  MediaType mediaType = new MediaType(type, subtype);
113  ret = m.contains(mediaType);
114  }
115 
116  return ret;
117  }
118 }
void addAttribute(BlackboardAttribute attr)
synchronized String detectAndSave(AbstractFile abstractFile)
final int read(byte[] buf, long offset, long len)
synchronized String detect(AbstractFile abstractFile)

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.