Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
FileTypeUtils.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2018-2019 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.coreutils;
20 
21 import com.google.common.collect.ImmutableSet;
22 import java.util.Arrays;
23 import static java.util.Arrays.asList;
24 import java.util.Collection;
25 import java.util.Collections;
26 import javax.imageio.ImageIO;
27 import static org.apache.commons.collections4.ListUtils.removeAll;
28 import org.apache.commons.lang.StringUtils;
29 import org.openide.util.NbBundle;
30 
34 public final class FileTypeUtils {
35 
36  private static final ImmutableSet<String> IMAGE_MIME_TYPES
37  = new ImmutableSet.Builder<String>()
38  .addAll(removeAll(
39  asList(
40  // remove any empty mime types provided by ImageIO.getReaderMIMETypes()
41  // This prevents mime types added by SPI implementations from causing errors
42  // (i.e. 'jai-imageio' utilized with IcePDF)
43  Arrays.stream(ImageIO.getReaderMIMETypes())
44  .filter((mimeType) -> StringUtils.isNotBlank(mimeType))
45  .toArray(String[]::new)),
46  asList("application/octet-stream"))) //this claims to be supported, but is not really an image.
47  .add("image/bmp", //NON-NLS
48  "image/gif", //NON-NLS
49  "image/jpeg", //NON-NLS
50  "image/png", //NON-NLS
51  "image/tiff", //NON-NLS
52  "image/vnd.adobe.photoshop", //NON-NLS
53  "image/x-raw-nikon", //NON-NLS
54  "image/x-ms-bmp", //NON-NLS
55  "image/x-icon", //NON-NLS
56  "image/webp", //NON-NLS
57  "image/vnd.microsoft.icon", //NON-NLS
58  "image/x-rgb", //NON-NLS
59  "image/x-ms-bmp", //NON-NLS
60  "image/x-xbitmap", //NON-NLS
61  "image/x-portable-graymap", //NON-NLS
62  "image/x-portable-bitmap" //NON-NLS
63  ).build();
64  private static final ImmutableSet<String> AUDIO_MIME_TYPES
65  = new ImmutableSet.Builder<String>()
66  .add("audio/midi", //NON-NLS
67  "audio/mpeg", //NON-NLS
68  "audio/webm", //NON-NLS
69  "audio/ogg", //NON-NLS
70  "audio/wav", //NON-NLS
71  "audio/vnd.wave", //NON-NLS
72  "audio/x-ms-wma"//NON-NLS
73  ).build();
74  private static final ImmutableSet<String> VIDEO_MIME_TYPES
75  = new ImmutableSet.Builder<String>()
76  .add("video/webm", //NON-NLS
77  "video/3gpp", //NON-NLS
78  "video/3gpp2", //NON-NLS
79  "video/ogg", //NON-NLS
80  "video/mpeg", //NON-NLS
81  "video/mp4", //NON-NLS
82  "video/quicktime", //NON-NLS
83  "video/x-msvideo", //NON-NLS
84  "video/x-flv", //NON-NLS
85  "video/x-m4v", //NON-NLS
86  "video/x-ms-wmv"//NON-NLS
87  ).build();
88  private static final ImmutableSet<String> DOCUMENT_MIME_TYPES
89  = new ImmutableSet.Builder<String>()
90  .add("text/plain", //NON-NLS
91  "text/css", //NON-NLS
92  "text/html", //NON-NLS
93  "text/csv", //NON-NLS
94  "text/xml", //NON-NLS
95  "text/x-log", //NON-NLS
96  "application/rtf", //NON-NLS
97  "application/pdf", //NON-NLS
98  "application/json", //NON-NLS
99  "application/javascript", //NON-NLS
100  "application/xml", //NON-NLS
101  "application/xhtml+xml", //NON-NLS
102  "application/x-msoffice", //NON-NLS
103  "application/x-ooxml", //NON-NLS
104  "application/msword", //NON-NLS
105  "application/msword2", //NON-NLS
106  "application/vnd.wordperfect", //NON-NLS
107  "application/vnd.openxmlformats-officedocument.wordprocessingml.document", //NON-NLS
108  "application/vnd.ms-powerpoint", //NON-NLS
109  "application/vnd.openxmlformats-officedocument.presentationml.presentation", //NON-NLS
110  "application/vnd.ms-excel", //NON-NLS
111  "application/vnd.ms-excel.sheet.4", //NON-NLS
112  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", //NON-NLS
113  "application/vnd.oasis.opendocument.presentation", //NON-NLS
114  "application/vnd.oasis.opendocument.spreadsheet", //NON-NLS
115  "application/vnd.oasis.opendocument.text" //NON-NLS
116  ).build();
117  private static final ImmutableSet<String> EXECUTABLE_MIME_TYPES
118  = new ImmutableSet.Builder<String>()
119  .add("application/x-bat",//NON-NLS
120  "application/x-dosexec",//NON-NLS
121  "application/vnd.microsoft.portable-executable",//NON-NLS
122  "application/x-msdownload",//NON-NLS
123  "application/exe",//NON-NLS
124  "application/x-exe",//NON-NLS
125  "application/dos-exe",//NON-NLS
126  "vms/exe",//NON-NLS
127  "application/x-winexe",//NON-NLS
128  "application/msdos-windows",//NON-NLS
129  "application/x-msdos-program"//NON-NLS
130  ).build();
131  private static final ImmutableSet<String> MULTI_MEDIA_MIME_TYPES
132  = new ImmutableSet.Builder<String>()
133  .addAll(IMAGE_MIME_TYPES)
134  .addAll(AUDIO_MIME_TYPES)
135  .addAll(VIDEO_MIME_TYPES)
136  .build();
137  private static final ImmutableSet<String> VISUAL_MEDIA_MIME_TYPES
138  = new ImmutableSet.Builder<String>()
139  .addAll(IMAGE_MIME_TYPES)
140  .addAll(VIDEO_MIME_TYPES)
141  .add("application/vnd.ms-asf", //NON-NLS
142  "application/vnd.rn-realmedia", //NON-NLS
143  "application/x-shockwave-flash" //NON-NLS
144  ).build();
145 
146  private FileTypeUtils() {
147 
148  }
149 
153  @NbBundle.Messages({
154  "FileTypeCategory.Audio.displayName=Audio",
155  "FileTypeCategory.Video.displayName=Video",
156  "FileTypeCategory.Image.displayName=Image",
157  "FileTypeCategory.Media.displayName=Media",
158  "FileTypeCategory.Visual.displayName=Visual",
159  "FileTypeCategory.Documents.displayName=Documents",
160  "FileTypeCategory.Executables.displayName=Executables"})
161  public enum FileTypeCategory {
162 
163  IMAGE(Bundle.FileTypeCategory_Image_displayName(),
165  Collections.emptyList()),
166  VIDEO(Bundle.FileTypeCategory_Video_displayName(),
168  Collections.emptyList()),
169  AUDIO(Bundle.FileTypeCategory_Audio_displayName(),
171  Collections.emptyList()),
175  VISUAL(Bundle.FileTypeCategory_Visual_displayName(),
177  Collections.emptyList()),
181  MEDIA(Bundle.FileTypeCategory_Media_displayName(),
183  Collections.emptyList()),
184  EXECUTABLE(Bundle.FileTypeCategory_Executables_displayName(),
186  Collections.emptyList()),
190  DOCUMENTS(Bundle.FileTypeCategory_Documents_displayName(),
192  Collections.emptyList());
193 
194  private final String displayName;
195  private final ImmutableSet<String> mediaTypes;
196  private final ImmutableSet<String> extensions;
197 
198  private FileTypeCategory(String displayName, Collection<String> mediaTypes, Collection<String> extensions) {
199  this.displayName = displayName;
200  this.mediaTypes = ImmutableSet.copyOf(mediaTypes);
201  this.extensions = ImmutableSet.copyOf(extensions);
202  }
203 
204  public String getDisplayName() {
205  return displayName;
206  }
207 
208  public ImmutableSet<String> getMediaTypes() {
209  return mediaTypes;
210 
211  }
212 
213  public ImmutableSet<String> getExtensions() {
214  throw new UnsupportedOperationException("This method is not implemented yet."); //just to be explicit.
215  }
216  }
217 }
static final ImmutableSet< String > VIDEO_MIME_TYPES
FileTypeCategory(String displayName, Collection< String > mediaTypes, Collection< String > extensions)
static final ImmutableSet< String > IMAGE_MIME_TYPES
static final ImmutableSet< String > DOCUMENT_MIME_TYPES
static final ImmutableSet< String > AUDIO_MIME_TYPES
static final ImmutableSet< String > VISUAL_MEDIA_MIME_TYPES
static final ImmutableSet< String > EXECUTABLE_MIME_TYPES
static final ImmutableSet< String > MULTI_MEDIA_MIME_TYPES

Copyright © 2012-2022 Basis Technology. Generated on: Thu Sep 29 2022
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.