Sleuth Kit Java Bindings (JNI)  4.6.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 
126  @Override
127  public long getContentSize(SleuthkitCase sleuthkitCase) throws TskCoreException {
128  return getContentSize(sleuthkitCase, objectId);
129  }
130 
146  static long getContentSize(SleuthkitCase sleuthkitCase, long dataSourceObjId) throws TskCoreException {
147  SleuthkitCase.CaseDbConnection connection;
148  Statement statement = null;
149  ResultSet resultSet = null;
150  long contentSize = 0;
151 
152  connection = sleuthkitCase.getConnection();
153 
154  try {
155  statement = connection.createStatement();
156  resultSet = connection.executeQuery(statement, "SELECT SUM (size) FROM tsk_files WHERE tsk_files.data_source_obj_id = " + dataSourceObjId);
157  if (resultSet.next()) {
158  contentSize = resultSet.getLong("sum");
159  }
160  } catch (SQLException ex) {
161  throw new TskCoreException(String.format("There was a problem while querying the database for size data for object ID %d.", dataSourceObjId), ex);
162  } finally {
163  closeResultSet(resultSet);
164  closeStatement(statement);
165  connection.close();
166  }
167 
168  return contentSize;
169  }
170 
176  private static void closeResultSet(ResultSet resultSet) {
177  if (resultSet != null) {
178  try {
179  resultSet.close();
180  } catch (SQLException ex) {
181  LOGGER.log(Level.SEVERE, "Error closing ResultSet", ex); //NON-NLS
182  }
183  }
184  }
185 
191  private static void closeStatement(Statement statement) {
192  if (statement != null) {
193  try {
194  statement.close();
195  } catch (SQLException ex) {
196  LOGGER.log(Level.SEVERE, "Error closing Statement", ex); //NON-NLS
197  }
198  }
199  }
200 }
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-2018 Brian Carrier. (carrier -at- sleuthkit -dot- org)
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.