diff --git a/bindings/java/src/org/sleuthkit/datamodel/AbstractFile.java b/bindings/java/src/org/sleuthkit/datamodel/AbstractFile.java index fd4a02f4fbdaf7f8688753812d754078b146fe58..57ac9872c0a05af8af40d288391295a079cef31a 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/AbstractFile.java +++ b/bindings/java/src/org/sleuthkit/datamodel/AbstractFile.java @@ -22,13 +22,13 @@ import java.io.IOException; import java.io.RandomAccessFile; import java.text.MessageFormat; -import java.util.ResourceBundle; import java.util.ArrayList; import java.util.List; +import java.util.ResourceBundle; import java.util.Set; +import java.util.TreeSet; import java.util.logging.Level; import java.util.logging.Logger; - import org.sleuthkit.datamodel.TskData.FileKnown; import org.sleuthkit.datamodel.TskData.TSK_FS_META_FLAG_ENUM; import org.sleuthkit.datamodel.TskData.TSK_FS_META_TYPE_ENUM; @@ -75,7 +75,7 @@ public abstract class AbstractFile extends AbstractContent { */ protected String md5Hash; private static final Logger logger = Logger.getLogger(AbstractFile.class.getName()); - private static ResourceBundle bundle = ResourceBundle.getBundle("org.sleuthkit.datamodel.Bundle"); + private static final ResourceBundle bundle = ResourceBundle.getBundle("org.sleuthkit.datamodel.Bundle"); /** * Initializes common fields used by AbstactFile implementations (objects in @@ -88,6 +88,7 @@ public abstract class AbstractFile extends AbstractContent { * @param name name field of the file * @param fileType type of the file * @param metaAddr + * @param metaSeq * @param dirType * @param metaType * @param dirFlag @@ -442,7 +443,7 @@ public TskData.FileKnown getKnown() { * @return filename extension in lowercase (not including the period) or empty string if there is no extension */ public String getNameExtension() { - String ext = ""; + String ext; int i = getName().lastIndexOf("."); // > 0 because we assume it's not an extension if period is the first character if ((i > 0) && ((i + 1) < getName().length())) { @@ -597,6 +598,7 @@ public static String createNonUniquePath(String uniquePath) { /** * @return a list of AbstractFiles that are the children of this Directory. * Only returns children of type TskData.TSK_DB_FILES_TYPE_ENUM.FS. + * @throws org.sleuthkit.datamodel.TskCoreException */ public List<AbstractFile> listFiles() throws TskCoreException { // first, get all children @@ -949,4 +951,40 @@ public static long timeToEpoch(String time) { return epoch; } -} + + + /** + * Possible return values for comparing a file to a list of mime types + */ + public enum MimeMatchEnum { + + UNDEFINED, /// file does not have a defined mime time in blackboard + TRUE, /// file has a defined mime type and it is one of the given ones + FALSE /// file has a defined mime type and it is not one of the given ones. + } + + /** + * Determines if this file's type is one of the ones passed in. Uses the + * blackboard attribute for file type. + * + * @param mimeTypes Set of file types to compare against + * @return + */ + public MimeMatchEnum isMimeType(TreeSet<String> mimeTypes) { + try { + List<BlackboardAttribute> attrs = getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_FILE_TYPE_SIG); + if (attrs.isEmpty()) { + return MimeMatchEnum.UNDEFINED; + } + + for (BlackboardAttribute batt : attrs) { + if (mimeTypes.contains(batt.getValueString())) { + return MimeMatchEnum.TRUE; + } + } + return MimeMatchEnum.FALSE; + } catch (TskCoreException ex) { + return MimeMatchEnum.UNDEFINED; + } + } +} \ No newline at end of file diff --git a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java index 9207e2f8bfc3c1ccd89b29e9d8fbe644b24e2620..4e594b42df033e4a6c4116d042b7fc14b80fede8 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java +++ b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java @@ -3271,13 +3271,15 @@ public List<Long> findAllFileIdsWhere(String sqlWhereClause) throws TskCoreExcep } /** - * Find and return list of files matching the specific Where clause + * Find and return list of files matching the specific Where clause. + * Use findAllFilesWhere instead. It returns a more generic data type * * @param sqlWhereClause a SQL where clause appropriate for the desired * files (do not begin the WHERE clause with the word WHERE!) * @return a list of FsContent each of which satisfy the given WHERE clause * @throws TskCoreException */ + @Deprecated // use findAllFilesWhere instead public List<FsContent> findFilesWhere(String sqlWhereClause) throws TskCoreException { CaseDbConnection connection = connections.getConnection(); acquireSharedLock();