Sleuth Kit Java Bindings (JNI)  4.8.0
Java bindings for using The Sleuth Kit
LocalFilesDataSource.java
Go to the documentation of this file.
1 /*
2  * Sleuth Kit Data Model
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.datamodel;
20 
21 import java.sql.ResultSet;
22 import java.sql.SQLException;
23 import java.sql.Statement;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
26 
37 public class LocalFilesDataSource extends VirtualDirectory implements DataSource {
38 
39  private final long objectId;
40  private final String deviceId;
41  private final String timezone;
42 
43  private static final Logger LOGGER = Logger.getLogger(LocalFilesDataSource.class.getName());
44 
69  public LocalFilesDataSource(SleuthkitCase db, long objId, long dataSourceObjectId, String deviceId, String name, TskData.TSK_FS_NAME_TYPE_ENUM dirType, TskData.TSK_FS_META_TYPE_ENUM metaType, TskData.TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags, String timezone, String md5Hash, TskData.FileKnown knownState, String parentPath) {
70  super(db, objId, dataSourceObjectId, name, dirType, metaType, dirFlag, metaFlags, md5Hash, knownState, parentPath);
71  this.objectId = objId;
72  this.deviceId = deviceId;
73  this.timezone = timezone;
74  }
75 
84  @Deprecated
86  return this;
87  }
88 
96  @Override
97  public String getDeviceId() {
98  return deviceId;
99  }
100 
106  @Override
107  public String getTimeZone() {
108  return timezone;
109  }
110 
118  @Override
119  public void setDisplayName(String newName) throws TskCoreException {
120  this.getSleuthkitCase().setFileName(newName, objectId);
121  }
122 
138  @Override
139  public long getContentSize(SleuthkitCase sleuthkitCase) throws TskCoreException {
140  return getContentSize(sleuthkitCase, objectId);
141  }
142 
158  static long getContentSize(SleuthkitCase sleuthkitCase, long dataSourceObjId) throws TskCoreException {
159  SleuthkitCase.CaseDbConnection connection;
160  Statement statement = null;
161  ResultSet resultSet = null;
162  long contentSize = 0;
163 
164  connection = sleuthkitCase.getConnection();
165 
166  try {
167  statement = connection.createStatement();
168  resultSet = connection.executeQuery(statement, "SELECT SUM (size) FROM tsk_files WHERE tsk_files.data_source_obj_id = " + dataSourceObjId);
169  if (resultSet.next()) {
170  contentSize = resultSet.getLong("sum");
171  }
172  } catch (SQLException ex) {
173  throw new TskCoreException(String.format("There was a problem while querying the database for size data for object ID %d.", dataSourceObjId), ex);
174  } finally {
175  closeResultSet(resultSet);
176  closeStatement(statement);
177  connection.close();
178  }
179 
180  return contentSize;
181  }
182 
190  @Override
191  public void setAcquisitionDetails(String details) throws TskCoreException {
192  getSleuthkitCase().setAcquisitionDetails(this, details);
193  }
194 
202  @Override
203  public String getAcquisitionDetails() throws TskCoreException {
204  return getSleuthkitCase().getAcquisitionDetails(this);
205  }
206 
212  private static void closeResultSet(ResultSet resultSet) {
213  if (resultSet != null) {
214  try {
215  resultSet.close();
216  } catch (SQLException ex) {
217  LOGGER.log(Level.SEVERE, "Error closing ResultSet", ex); //NON-NLS
218  }
219  }
220  }
221 
227  private static void closeStatement(Statement statement) {
228  if (statement != null) {
229  try {
230  statement.close();
231  } catch (SQLException ex) {
232  LOGGER.log(Level.SEVERE, "Error closing Statement", ex); //NON-NLS
233  }
234  }
235  }
236 }
final TSK_FS_NAME_TYPE_ENUM dirType
final TSK_FS_NAME_FLAG_ENUM dirFlag
final Set< TSK_FS_META_FLAG_ENUM > metaFlags
final TSK_FS_META_TYPE_ENUM metaType
LocalFilesDataSource(SleuthkitCase db, long objId, long dataSourceObjectId, String deviceId, String name, TskData.TSK_FS_NAME_TYPE_ENUM dirType, TskData.TSK_FS_META_TYPE_ENUM metaType, TskData.TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags, String timezone, String md5Hash, TskData.FileKnown knownState, String parentPath)
long getContentSize(SleuthkitCase sleuthkitCase)

Copyright © 2011-2020 Brian Carrier. (carrier -at- sleuthkit -dot- org)
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.