mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-15 09:17:42 +00:00
more cleanup; deprecated method that takes Content and replaced with one that takes AbstractFile
This commit is contained in:
parent
a20dd52877
commit
de996bf16b
@ -74,11 +74,13 @@ public class ImageUtils {
|
|||||||
//initialized lazily
|
//initialized lazily
|
||||||
private static FileTypeDetector fileTypeDetector;
|
private static FileTypeDetector fileTypeDetector;
|
||||||
|
|
||||||
private static final List<String> SUPP_EXTENSIONS;
|
private static final List<String> SUPPORTED_EXTENSIONS;
|
||||||
private static final TreeSet<String> SUPP_MIME_TYPES;
|
private static final TreeSet<String> SUPPORTED_MIME_TYPES;
|
||||||
|
|
||||||
/** thread that saves generated thumbnails to disk for use later */
|
/** thread that saves generated thumbnails to disk for use later */
|
||||||
private static final Executor imageSaver = Executors.newSingleThreadExecutor(new BasicThreadFactory.Builder().namingPattern("icon saver-%d").build());
|
private static final Executor imageSaver
|
||||||
|
= Executors.newSingleThreadExecutor(new BasicThreadFactory.Builder()
|
||||||
|
.namingPattern("icon saver-%d").build());
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ImageIO.scanForPlugins();
|
ImageIO.scanForPlugins();
|
||||||
@ -89,26 +91,35 @@ public class ImageUtils {
|
|||||||
}
|
}
|
||||||
DEFAULT_ICON = defaultIcon;
|
DEFAULT_ICON = defaultIcon;
|
||||||
|
|
||||||
SUPP_EXTENSIONS = Arrays.asList(ImageIO.getReaderFileSuffixes());
|
SUPPORTED_EXTENSIONS = Arrays.asList(ImageIO.getReaderFileSuffixes());
|
||||||
|
|
||||||
SUPP_MIME_TYPES = new TreeSet<>(Arrays.asList(ImageIO.getReaderMIMETypes()));
|
SUPPORTED_MIME_TYPES = new TreeSet<>(Arrays.asList(ImageIO.getReaderMIMETypes()));
|
||||||
SUPP_MIME_TYPES.addAll(Arrays.asList("image/x-rgb", "image/x-ms-bmp", "application/x-123"));
|
|
||||||
SUPP_MIME_TYPES.removeIf("application/octet-stream"::equals);
|
/* special cases and variants that we support, but don't get registered
|
||||||
|
* with ImageIO automatically */
|
||||||
|
SUPPORTED_MIME_TYPES.addAll(Arrays.asList(
|
||||||
|
"image/x-rgb",
|
||||||
|
"image/x-ms-bmp",
|
||||||
|
"application/x-123"));
|
||||||
|
|
||||||
|
//this is rarely usefull
|
||||||
|
SUPPORTED_MIME_TYPES.removeIf("application/octet-stream"::equals);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImageUtils() {
|
private ImageUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getSupportedExtensions() {
|
public static List<String> getSupportedExtensions() {
|
||||||
return Collections.unmodifiableList(SUPP_EXTENSIONS);
|
return Collections.unmodifiableList(SUPPORTED_EXTENSIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SortedSet<String> getSupportedMimeTypes() {
|
public static SortedSet<String> getSupportedMimeTypes() {
|
||||||
return Collections.unmodifiableSortedSet(SUPP_MIME_TYPES);
|
return Collections.unmodifiableSortedSet(SUPPORTED_MIME_TYPES);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the default Icon, which is the icon for a file.
|
* Get the default Icon, which is the icon for a file. Used when we can not
|
||||||
|
* generate content based thumbnail.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -116,13 +127,28 @@ public class ImageUtils {
|
|||||||
return DEFAULT_ICON;
|
return DEFAULT_ICON;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can a thumbnail be generated for the file?
|
||||||
|
*
|
||||||
|
* @param file
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static boolean thumbnailSupported(AbstractFile file) {
|
||||||
|
return thumbnailSupported((Content) file);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can a thumbnail be generated for the content?
|
* Can a thumbnail be generated for the content?
|
||||||
*
|
*
|
||||||
* @param content
|
* @param content
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
|
*
|
||||||
|
* @deprecated use {@link #thumbnailSupported(org.sleuthkit.datamodel.AbstractFile) instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static boolean thumbnailSupported(Content content) {
|
public static boolean thumbnailSupported(Content content) {
|
||||||
if (content instanceof AbstractFile == false) {
|
if (content instanceof AbstractFile == false) {
|
||||||
return false;
|
return false;
|
||||||
@ -136,13 +162,13 @@ public class ImageUtils {
|
|||||||
try {
|
try {
|
||||||
String mimeType = getFileTypeDetector().getFileType(file);
|
String mimeType = getFileTypeDetector().getFileType(file);
|
||||||
if (Objects.nonNull(mimeType)) {
|
if (Objects.nonNull(mimeType)) {
|
||||||
return SUPP_MIME_TYPES.contains(mimeType)
|
return SUPPORTED_MIME_TYPES.contains(mimeType)
|
||||||
|| (mimeType.equalsIgnoreCase("audio/x-aiff") && "iff".equalsIgnoreCase(file.getNameExtension()));
|
|| (mimeType.equalsIgnoreCase("audio/x-aiff") && "iff".equalsIgnoreCase(file.getNameExtension()));
|
||||||
}
|
}
|
||||||
} catch (FileTypeDetector.FileTypeDetectorInitException | TskCoreException ex) {
|
} catch (FileTypeDetector.FileTypeDetectorInitException | TskCoreException ex) {
|
||||||
LOGGER.log(Level.WARNING, "Failed to look up mimetype for " + file.getName() + " using FileTypeDetector. Fallingback on AbstractFile.isMimeType", ex);
|
LOGGER.log(Level.WARNING, "Failed to look up mimetype for " + file.getName() + " using FileTypeDetector. Fallingback on AbstractFile.isMimeType", ex);
|
||||||
if (!SUPP_MIME_TYPES.isEmpty()) {
|
if (!SUPPORTED_MIME_TYPES.isEmpty()) {
|
||||||
AbstractFile.MimeMatchEnum mimeMatch = file.isMimeType(SUPP_MIME_TYPES);
|
AbstractFile.MimeMatchEnum mimeMatch = file.isMimeType(SUPPORTED_MIME_TYPES);
|
||||||
if (mimeMatch == AbstractFile.MimeMatchEnum.TRUE) {
|
if (mimeMatch == AbstractFile.MimeMatchEnum.TRUE) {
|
||||||
return true;
|
return true;
|
||||||
} else if (mimeMatch == AbstractFile.MimeMatchEnum.FALSE) {
|
} else if (mimeMatch == AbstractFile.MimeMatchEnum.FALSE) {
|
||||||
@ -153,7 +179,7 @@ public class ImageUtils {
|
|||||||
|
|
||||||
// if we have an extension, check it
|
// if we have an extension, check it
|
||||||
final String extension = file.getNameExtension();
|
final String extension = file.getNameExtension();
|
||||||
if (StringUtils.isNotBlank(extension) && SUPP_EXTENSIONS.contains(extension)) {
|
if (StringUtils.isNotBlank(extension) && SUPPORTED_EXTENSIONS.contains(extension)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user