Autopsy  4.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-2017 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 
27 
32 @Deprecated
33 public class TikaFileTypeDetector {
34 
35  private static final Tika tikaInst = new Tika(); //calling detect() with this should be thread-safe
36  private final int BUFFER_SIZE = 64 * 1024; //how many bytes to pass in
37  private final byte buffer[] = new byte[BUFFER_SIZE];
38 
39 
49  @Deprecated
50  public synchronized String detect(AbstractFile abstractFile) {
51  try {
52  byte buf[];
53  int len = abstractFile.read(buffer, 0, BUFFER_SIZE);
54  if (len < BUFFER_SIZE) {
55  buf = new byte[len];
56  System.arraycopy(buffer, 0, buf, 0, len);
57  } else {
58  buf = buffer;
59  }
60 
61  String mimetype = tikaInst.detect(buf, abstractFile.getName());
62  // Remove tika's name out of the general types like msoffice and ooxml
63  return mimetype.replace("tika-", ""); //NON-NLS
64  } catch (Exception ex) {
65  //do nothing
66  }
67  return null;
68  }
69 
80  @Deprecated
81  public boolean isMimeTypeDetectable(String mimeType) {
82  boolean ret = false;
83 
84  SortedSet<MediaType> m = MimeTypes.getDefaultMimeTypes().getMediaTypeRegistry().getTypes();
85  String[] split = mimeType.split("/");
86 
87  if (split.length == 2) {
88  String type = split[0];
89  String subtype = split[1];
90  MediaType mediaType = new MediaType(type, subtype);
91  ret = m.contains(mediaType);
92  }
93 
94  return ret;
95  }
96 }
final int read(byte[] buf, long offset, long len)
synchronized String detect(AbstractFile abstractFile)

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