Autopsy  4.19.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
MimeTypeSummary.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2020 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.datasourcesummary.datamodel;
20 
22 import java.sql.SQLException;
23 import java.util.Arrays;
24 import java.util.HashSet;
25 import java.util.List;
26 import java.util.Set;
27 import java.util.stream.Collectors;
31 import org.sleuthkit.datamodel.AbstractFile;
32 import org.sleuthkit.datamodel.DataSource;
33 import org.sleuthkit.datamodel.TskCoreException;
34 
38 public class MimeTypeSummary implements DefaultUpdateGovernor {
39 
41 
42  private static final Set<IngestManager.IngestJobEvent> INGEST_JOB_EVENTS = new HashSet<>(
44 
48  public MimeTypeSummary() {
50  }
51 
58  this.provider = provider;
59  }
60 
61  @Override
62  public boolean isRefreshRequired(ModuleContentEvent evt) {
63  return true;
64  }
65 
66  @Override
67  public boolean isRefreshRequired(AbstractFile file) {
68  return true;
69  }
70 
71  @Override
73  return (evt != null && INGEST_JOB_EVENTS.contains(evt));
74  }
75 
76  @Override
78  return INGEST_JOB_EVENTS;
79  }
80 
99  public Long getCountOfFilesForMimeTypes(DataSource currentDataSource, Set<String> setOfMimeTypes)
100  throws SleuthkitCaseProvider.SleuthkitCaseProviderException, TskCoreException, SQLException {
101 
102  return DataSourceInfoUtilities.getCountOfRegNonSlackFiles(
103  provider.get(),
104  currentDataSource,
105  "mime_type IN " + getSqlSet(setOfMimeTypes)
106  );
107  }
108 
125  public Long getCountOfFilesNotInMimeTypes(DataSource currentDataSource, Set<String> setOfMimeTypes)
126  throws SleuthkitCaseProvider.SleuthkitCaseProviderException, TskCoreException, SQLException {
127 
128  return DataSourceInfoUtilities.getCountOfRegNonSlackFiles(
129  provider.get(),
130  currentDataSource,
131  "mime_type NOT IN " + getSqlSet(setOfMimeTypes)
132  + " AND mime_type IS NOT NULL AND mime_type <> '' "
133  );
134  }
135 
147  public Long getCountOfAllRegularFiles(DataSource dataSource)
148  throws SleuthkitCaseProvider.SleuthkitCaseProviderException, TskCoreException, SQLException {
149 
150  return DataSourceInfoUtilities.getCountOfRegNonSlackFiles(provider.get(), dataSource, null);
151  }
152 
165  public Long getCountOfFilesWithNoMimeType(DataSource currentDataSource)
166  throws SleuthkitCaseProvider.SleuthkitCaseProviderException, TskCoreException, SQLException {
167 
168  return DataSourceInfoUtilities.getCountOfRegNonSlackFiles(
169  provider.get(),
170  currentDataSource,
171  "(mime_type IS NULL OR mime_type = '') "
172  );
173  }
174 
185  private String getSqlSet(Set<String> setValues) {
186  List<String> quotedValues = setValues
187  .stream()
188  .map(str -> String.format("'%s'", str.replace("'", "")))
189  .collect(Collectors.toList());
190 
191  String commaSeparatedQuoted = String.join(", ", quotedValues);
192  return String.format("(%s) ", commaSeparatedQuoted);
193  }
194 }
Long getCountOfFilesNotInMimeTypes(DataSource currentDataSource, Set< String > setOfMimeTypes)
static final Set< IngestManager.IngestJobEvent > INGEST_JOB_EVENTS
Long getCountOfFilesForMimeTypes(DataSource currentDataSource, Set< String > setOfMimeTypes)
boolean isRefreshRequired(IngestManager.IngestJobEvent evt)

Copyright © 2012-2021 Basis Technology. Generated on: Fri Aug 6 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.