Skip to content
Snippets Groups Projects
Commit b02243da authored by Greg DiCristofaro's avatar Greg DiCristofaro
Browse files

updates

parent 74d2123d
No related branches found
No related tags found
No related merge requests found
...@@ -119,9 +119,9 @@ public abstract class AbstractFile extends AbstractContent { ...@@ -119,9 +119,9 @@ public abstract class AbstractFile extends AbstractContent {
private volatile String uniquePath; private volatile String uniquePath;
private volatile FileSystem parentFileSystem; private volatile FileSystem parentFileSystem;
private boolean tryContentStream; private boolean tryContentProviderStream;
private Object contentStreamLock = new Object(); private Object contentProviderStreamLock = new Object();
private SoftReference<ContentStream> contentStreamRef = null; private SoftReference<ContentProviderStream> contentProviderStreamRef = null;
/** /**
* Initializes common fields used by AbstactFile implementations (objects in * Initializes common fields used by AbstactFile implementations (objects in
...@@ -234,8 +234,8 @@ public abstract class AbstractFile extends AbstractContent { ...@@ -234,8 +234,8 @@ public abstract class AbstractFile extends AbstractContent {
this.osAccountObjId = osAccountObjectId; this.osAccountObjId = osAccountObjectId;
this.collected = collected; this.collected = collected;
// any item that is marked as YES_REPO and there is a custom content provider for the db will attempt to use the content provider to provide data // any item that is marked as YES_REPO and there is a custom content provider for the db will attempt to use the content provider to provide data
// this will be flipped to false if there is no content stream from the content provider for this file // this will be flipped to false if there is no content provider stream from the content provider for this file
this.tryContentStream = collected == CollectedStatus.YES_REPO && db.getContentProvider() != null; this.tryContentProviderStream = collected == CollectedStatus.YES_REPO && db.getContentProvider() != null;
if (Objects.nonNull(fileAttributes) && !fileAttributes.isEmpty()) { if (Objects.nonNull(fileAttributes) && !fileAttributes.isEmpty()) {
this.fileAttributesCache.addAll(fileAttributes); this.fileAttributesCache.addAll(fileAttributes);
loadedAttributesCacheFromDb = true; loadedAttributesCacheFromDb = true;
...@@ -1074,52 +1074,52 @@ short getMetaFlagsAsInt() { ...@@ -1074,52 +1074,52 @@ short getMetaFlagsAsInt() {
private boolean hasContentStream() { private boolean hasContentProviderStream() {
ContentStream contentStream = null; ContentProviderStream contentProviderStream = null;
try { try {
contentStream = getContentStream(); contentProviderStream = getContentProviderStream();
} catch (TskCoreException ex) { } catch (TskCoreException ex) {
LOGGER.log(Level.WARNING, "An error occurred while loading content stream for file with id: " + getId(), ex); LOGGER.log(Level.WARNING, "An error occurred while loading content provider stream for file with id: " + getId(), ex);
} }
return contentStream != null; return contentProviderStream != null;
} }
/** /**
* Attempts to load the content stream for this file. If none exists, returns null. * Attempts to load the content provider stream for this file. If none exists, returns null.
* @return The content stream for this file or null if none exists. * @return The content stream for this file or null if none exists.
* @throws TskCoreException * @throws TskCoreException
*/ */
private ContentStream getContentStream() throws TskCoreException { private ContentProviderStream getContentProviderStream() throws TskCoreException {
ContentStream contentStream = null; ContentProviderStream contentProviderStream = null;
if (tryContentStream) { if (tryContentProviderStream) {
try { try {
synchronized (contentStreamLock) { synchronized (contentProviderStreamLock) {
// try to get soft reference content stream // try to get soft reference content provider stream
contentStream = contentStreamRef == null ? null : contentStreamRef.get(); contentProviderStream = contentProviderStreamRef == null ? null : contentProviderStreamRef.get();
// load if not cached and then cache if present // load if not cached and then cache if present
if (contentStream == null) { if (contentProviderStream == null) {
contentStream = getSleuthkitCase().getContentProvider().getContentStream(this).orElse(null); contentProviderStream = getSleuthkitCase().getContentProvider().getContentStream(this).orElse(null);
if (contentStream != null) { if (contentProviderStream != null) {
this.contentStreamRef = new SoftReference<>(contentStream); this.contentProviderStreamRef = new SoftReference<>(contentProviderStream);
} }
} }
} }
} finally { } finally {
if (contentStream == null) { if (contentProviderStream == null) {
// don't try to load the content stream again if it fails to load (either through exception or not existing) // don't try to load the content provider stream again if it fails to load (either through exception or not existing)
tryContentStream = false; tryContentProviderStream = false;
} }
} }
} }
return contentStream; return contentProviderStream;
} }
@Override @Override
public final int read(byte[] buf, long offset, long len) throws TskCoreException { public final int read(byte[] buf, long offset, long len) throws TskCoreException {
// try to use content stream if present // try to use content provider stream if present
ContentStream contentStream = getContentStream(); ContentProviderStream contentProviderStream = getContentProviderStream();
if (contentStream != null) { if (contentProviderStream != null) {
return contentStream.read(buf, offset, len); return contentProviderStream.read(buf, offset, len);
} }
//if localPath is set, use local, otherwise, use readCustom() supplied by derived class //if localPath is set, use local, otherwise, use readCustom() supplied by derived class
...@@ -1295,7 +1295,7 @@ final void setEncodingType(TskData.EncodingType encodingType) { ...@@ -1295,7 +1295,7 @@ final void setEncodingType(TskData.EncodingType encodingType) {
* @return true if the file exists, false otherwise * @return true if the file exists, false otherwise
*/ */
public boolean exists() { public boolean exists() {
if (hasContentStream()) { if (hasContentProviderStream()) {
return true; return true;
} }
...@@ -1320,7 +1320,7 @@ public boolean exists() { ...@@ -1320,7 +1320,7 @@ public boolean exists() {
* @return true if the file is readable * @return true if the file is readable
*/ */
public boolean canRead() { public boolean canRead() {
if (hasContentStream()) { if (hasContentProviderStream()) {
return true; return true;
} }
......
...@@ -18,12 +18,11 @@ ...@@ -18,12 +18,11 @@
*/ */
package org.sleuthkit.datamodel; package org.sleuthkit.datamodel;
import java.util.Optional;
/** /**
* Custom provider for content bytes. * Custom provider for content bytes.
*/ */
public interface ContentStream extends AutoCloseable { @SuppressWarnings("try")
public interface ContentProviderStream extends AutoCloseable {
/** /**
* Reads data that this content object is associated with (file contents, * Reads data that this content object is associated with (file contents,
...@@ -39,21 +38,4 @@ public interface ContentStream extends AutoCloseable { ...@@ -39,21 +38,4 @@ public interface ContentStream extends AutoCloseable {
* tsk core * tsk core
*/ */
public int read(byte[] buf, long offset, long len) throws TskCoreException; public int read(byte[] buf, long offset, long len) throws TskCoreException;
/**
* Custom provider for bytes of an abstract file.
*/
public interface ContentProvider {
/**
* Provides a content stream for a content object or empty if this
* provider has none to provide.
*
* @param content The content.
*
* @return The content stream or empty if no stream can be provided
* for this content.
*/
Optional<ContentStream> getContentStream(Content content) throws TskCoreException;
}
} }
...@@ -94,7 +94,6 @@ ...@@ -94,7 +94,6 @@
import org.sqlite.SQLiteConfig; import org.sqlite.SQLiteConfig;
import org.sqlite.SQLiteDataSource; import org.sqlite.SQLiteDataSource;
import org.sqlite.SQLiteJDBCLoader; import org.sqlite.SQLiteJDBCLoader;
import org.sleuthkit.datamodel.ContentStream.ContentProvider;
   
/** /**
* Represents the case database with methods that provide abstractions for * Represents the case database with methods that provide abstractions for
...@@ -205,7 +204,7 @@ public class SleuthkitCase { ...@@ -205,7 +204,7 @@ public class SleuthkitCase {
private final Cache<Long, Boolean> isRootDirectoryCache private final Cache<Long, Boolean> isRootDirectoryCache
= CacheBuilder.newBuilder().maximumSize(200000).expireAfterAccess(5, TimeUnit.MINUTES).build(); = CacheBuilder.newBuilder().maximumSize(200000).expireAfterAccess(5, TimeUnit.MINUTES).build();
// custom provider for file bytes (can be null) // custom provider for file bytes (can be null)
private final ContentProvider contentProvider; private final ContentStreamProvider contentProvider;
/* /*
* First parameter is used to specify the SparseBitSet to use, as object IDs * First parameter is used to specify the SparseBitSet to use, as object IDs
...@@ -339,7 +338,7 @@ public static void tryConnect(CaseDbConnectionInfo info) throws TskCoreException ...@@ -339,7 +338,7 @@ public static void tryConnect(CaseDbConnectionInfo info) throws TskCoreException
* *
* @throws Exception * @throws Exception
*/ */
private SleuthkitCase(String dbPath, SleuthkitJNI.CaseDbHandle caseHandle, DbType dbType, ContentProvider contentProvider) throws Exception { private SleuthkitCase(String dbPath, SleuthkitJNI.CaseDbHandle caseHandle, DbType dbType, ContentStreamProvider contentProvider) throws Exception {
Class.forName("org.sqlite.JDBC"); Class.forName("org.sqlite.JDBC");
this.dbPath = dbPath; this.dbPath = dbPath;
this.dbType = dbType; this.dbType = dbType;
...@@ -372,7 +371,7 @@ private SleuthkitCase(String dbPath, SleuthkitJNI.CaseDbHandle caseHandle, DbTyp ...@@ -372,7 +371,7 @@ private SleuthkitCase(String dbPath, SleuthkitJNI.CaseDbHandle caseHandle, DbTyp
* *
* @throws Exception * @throws Exception
*/ */
private SleuthkitCase(String host, int port, String dbName, String userName, String password, SleuthkitJNI.CaseDbHandle caseHandle, String caseDirPath, DbType dbType, ContentProvider contentProvider) throws Exception { private SleuthkitCase(String host, int port, String dbName, String userName, String password, SleuthkitJNI.CaseDbHandle caseHandle, String caseDirPath, DbType dbType, ContentStreamProvider contentProvider) throws Exception {
this.dbPath = ""; this.dbPath = "";
this.databaseName = dbName; this.databaseName = dbName;
this.dbType = dbType; this.dbType = dbType;
...@@ -421,7 +420,7 @@ private void init() throws Exception { ...@@ -421,7 +420,7 @@ private void init() throws Exception {
* @return The custom content provider for this case if one exists. * @return The custom content provider for this case if one exists.
* Otherwise, returns null. * Otherwise, returns null.
*/ */
ContentProvider getContentProvider() { ContentStreamProvider getContentProvider() {
return this.contentProvider; return this.contentProvider;
} }
   
...@@ -3002,7 +3001,7 @@ public static SleuthkitCase openCase(String dbPath) throws TskCoreException { ...@@ -3002,7 +3001,7 @@ public static SleuthkitCase openCase(String dbPath) throws TskCoreException {
* @throws org.sleuthkit.datamodel.TskCoreException * @throws org.sleuthkit.datamodel.TskCoreException
*/ */
@Beta @Beta
public static SleuthkitCase openCase(String dbPath, ContentProvider provider) throws TskCoreException { public static SleuthkitCase openCase(String dbPath, ContentStreamProvider provider) throws TskCoreException {
try { try {
final SleuthkitJNI.CaseDbHandle caseHandle = SleuthkitJNI.openCaseDb(dbPath); final SleuthkitJNI.CaseDbHandle caseHandle = SleuthkitJNI.openCaseDb(dbPath);
return new SleuthkitCase(dbPath, caseHandle, DbType.SQLITE, provider); return new SleuthkitCase(dbPath, caseHandle, DbType.SQLITE, provider);
...@@ -3042,7 +3041,7 @@ public static SleuthkitCase openCase(String databaseName, CaseDbConnectionInfo i ...@@ -3042,7 +3041,7 @@ public static SleuthkitCase openCase(String databaseName, CaseDbConnectionInfo i
* @throws TskCoreException If there is a problem opening the database. * @throws TskCoreException If there is a problem opening the database.
*/ */
@Beta @Beta
public static SleuthkitCase openCase(String databaseName, CaseDbConnectionInfo info, String caseDir, ContentProvider contentProvider) throws TskCoreException { public static SleuthkitCase openCase(String databaseName, CaseDbConnectionInfo info, String caseDir, ContentStreamProvider contentProvider) throws TskCoreException {
try { try {
/* /*
* The flow of this method involves trying to open case and if * The flow of this method involves trying to open case and if
...@@ -3094,7 +3093,7 @@ public static SleuthkitCase newCase(String dbPath) throws TskCoreException { ...@@ -3094,7 +3093,7 @@ public static SleuthkitCase newCase(String dbPath) throws TskCoreException {
* @throws org.sleuthkit.datamodel.TskCoreException * @throws org.sleuthkit.datamodel.TskCoreException
*/ */
@Beta @Beta
public static SleuthkitCase newCase(String dbPath, ContentProvider contentProvider) throws TskCoreException { public static SleuthkitCase newCase(String dbPath, ContentStreamProvider contentProvider) throws TskCoreException {
try { try {
CaseDatabaseFactory factory = new CaseDatabaseFactory(dbPath); CaseDatabaseFactory factory = new CaseDatabaseFactory(dbPath);
factory.createCaseDatabase(); factory.createCaseDatabase();
...@@ -3143,7 +3142,7 @@ public static SleuthkitCase newCase(String caseName, CaseDbConnectionInfo info, ...@@ -3143,7 +3142,7 @@ public static SleuthkitCase newCase(String caseName, CaseDbConnectionInfo info,
* @throws org.sleuthkit.datamodel.TskCoreException * @throws org.sleuthkit.datamodel.TskCoreException
*/ */
@Beta @Beta
public static SleuthkitCase newCase(String caseName, CaseDbConnectionInfo info, String caseDirPath, ContentProvider contentProvider) throws TskCoreException { public static SleuthkitCase newCase(String caseName, CaseDbConnectionInfo info, String caseDirPath, ContentStreamProvider contentProvider) throws TskCoreException {
String databaseName = createCaseDataBaseName(caseName); String databaseName = createCaseDataBaseName(caseName);
try { try {
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment