From 662a297ad3149ad8875fdd46e772c53ebe2479e7 Mon Sep 17 00:00:00 2001 From: "U-BASIS\\dsmyda" Date: Wed, 12 Dec 2018 09:52:25 -0500 Subject: [PATCH 1/2] Changed function names for SQLiteTableReader --- .../autopsy/contentviewers/SQLiteViewer.java | 8 +- .../autopsy/coreutils/SQLiteTableReader.java | 96 +++++++++---------- .../textextractors/SqliteTextExtractor.java | 4 +- 3 files changed, 54 insertions(+), 54 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/contentviewers/SQLiteViewer.java b/Core/src/org/sleuthkit/autopsy/contentviewers/SQLiteViewer.java index f2db7c2532..104c70ef6b 100755 --- a/Core/src/org/sleuthkit/autopsy/contentviewers/SQLiteViewer.java +++ b/Core/src/org/sleuthkit/autopsy/contentviewers/SQLiteViewer.java @@ -457,10 +457,10 @@ class SQLiteViewer extends javax.swing.JPanel implements FileTypeViewer { */ private void initReader() { viewReader = new SQLiteTableReader.Builder(sqliteDbFile) - .onColumnNames((columnName) -> { + .forAllColumnNames((columnName) -> { currentTableHeader.add(columnName); }) - .forAll(getForAllStrategy()).build(); + .forAllTableValues(getForAllStrategy()).build(); } /** @@ -510,8 +510,8 @@ class SQLiteViewer extends javax.swing.JPanel implements FileTypeViewer { String tableName = (String) this.tablesDropdownList.getSelectedItem(); try (FileOutputStream out = new FileOutputStream(csvFile, false)) { try (SQLiteTableReader sqliteStream = new SQLiteTableReader.Builder(sqliteDbFile) - .onColumnNames(getColumnNameCSVStrategy(out)) - .forAll(getForAllCSVStrategy(out)).build()) { + .forAllColumnNames(getColumnNameCSVStrategy(out)) + .forAllTableValues(getForAllCSVStrategy(out)).build()) { totalColumnCount = sqliteStream.getColumnCount(tableName); sqliteStream.read(tableName); } diff --git a/Core/src/org/sleuthkit/autopsy/coreutils/SQLiteTableReader.java b/Core/src/org/sleuthkit/autopsy/coreutils/SQLiteTableReader.java index 2be988c7ed..b1ecea17c7 100755 --- a/Core/src/org/sleuthkit/autopsy/coreutils/SQLiteTableReader.java +++ b/Core/src/org/sleuthkit/autopsy/coreutils/SQLiteTableReader.java @@ -44,19 +44,19 @@ import org.sleuthkit.datamodel.TskCoreException; /** * Reads row by row through SQLite tables and performs user-defined actions on * the row values. Table values are processed by data type. Users configure - * these actions for certain data types in the Builder. Example usage: - * - * SQLiteTableReader reader = new SQLiteTableReader.Builder(file) - * .onInteger((i) - * -> { System.out.println(i); }) - * .build(); - * - * reader.read(tableName); - * - * or - * - * SQLiteTableReader reader = new SQLiteTableReader.Builder(file) - * .onInteger(new Consumer() { + these actions for certain data types in the Builder. Example usage: + + SQLiteTableReader reader = new SQLiteTableReader.Builder(file) + .forAllIntegerValues((i) + -> { System.out.println(i); }) + .build(); + + reader.read(tableName); + + or + + SQLiteTableReader reader = new SQLiteTableReader.Builder(file) + .forAllIntegerValues(new Consumer() { * (atSymbol)Override public void accept(Integer i) { * System.out.println(i); * } @@ -76,13 +76,13 @@ public class SQLiteTableReader implements AutoCloseable { private final AbstractFile file; - private Consumer onColumnNameAction; - private Consumer onStringAction; - private Consumer onLongAction; - private Consumer onIntegerAction; - private Consumer onFloatAction; - private Consumer onBlobAction; - private Consumer forAllAction; + private Consumer forAllColumnNamesConsumer; + private Consumer forAllStringValuesConsumer; + private Consumer forAllLongValuesConsumer; + private Consumer forAllIntegerValuesConsumer; + private Consumer forAllFloatValuesConsumer; + private Consumer forAllBlobValuesConsumer; + private Consumer forAllTableValuesConsumer; static Consumer doNothing() { return NOOP -> {}; @@ -96,13 +96,13 @@ public class SQLiteTableReader implements AutoCloseable { public Builder(AbstractFile file) { this.file = file; - this.onColumnNameAction = Builder.doNothing(); - this.onStringAction = Builder.doNothing(); - this.onLongAction = Builder.doNothing(); - this.onIntegerAction = Builder.doNothing(); - this.onFloatAction = Builder.doNothing(); - this.onBlobAction = Builder.doNothing(); - this.forAllAction = Builder.doNothing(); + this.forAllColumnNamesConsumer = Builder.doNothing(); + this.forAllStringValuesConsumer = Builder.doNothing(); + this.forAllLongValuesConsumer = Builder.doNothing(); + this.forAllIntegerValuesConsumer = Builder.doNothing(); + this.forAllFloatValuesConsumer = Builder.doNothing(); + this.forAllBlobValuesConsumer = Builder.doNothing(); + this.forAllTableValuesConsumer = Builder.doNothing(); } /** @@ -113,8 +113,8 @@ public class SQLiteTableReader implements AutoCloseable { * * @return Builder reference */ - public Builder onColumnNames(Consumer action) { - this.onColumnNameAction = action; + public Builder forAllColumnNames(Consumer action) { + this.forAllColumnNamesConsumer = action; return this; } @@ -126,8 +126,8 @@ public class SQLiteTableReader implements AutoCloseable { * * @return Builder reference */ - public Builder onString(Consumer action) { - this.onStringAction = action; + public Builder forAllStringValues(Consumer action) { + this.forAllStringValuesConsumer = action; return this; } @@ -139,8 +139,8 @@ public class SQLiteTableReader implements AutoCloseable { * * @return Builder reference */ - public Builder onInteger(Consumer action) { - this.onIntegerAction = action; + public Builder forAllIntegerValues(Consumer action) { + this.forAllIntegerValuesConsumer = action; return this; } @@ -152,8 +152,8 @@ public class SQLiteTableReader implements AutoCloseable { * * @return Builder reference */ - public Builder onFloat(Consumer action) { - this.onFloatAction = action; + public Builder forAllFloatValues(Consumer action) { + this.forAllFloatValuesConsumer = action; return this; } @@ -165,8 +165,8 @@ public class SQLiteTableReader implements AutoCloseable { * * @return Builder reference */ - public Builder onLong(Consumer action) { - this.onLongAction = action; + public Builder forAllLongVaues(Consumer action) { + this.forAllLongValuesConsumer = action; return this; } @@ -178,8 +178,8 @@ public class SQLiteTableReader implements AutoCloseable { * * @return Builder reference */ - public Builder onBlob(Consumer action) { - this.onBlobAction = action; + public Builder forAllBlobValues(Consumer action) { + this.forAllBlobValuesConsumer = action; return this; } @@ -192,8 +192,8 @@ public class SQLiteTableReader implements AutoCloseable { * * @return Builder reference */ - public Builder forAll(Consumer action) { - this.forAllAction = action; + public Builder forAllTableValues(Consumer action) { + this.forAllTableValuesConsumer = action; return this; } @@ -366,7 +366,7 @@ public class SQLiteTableReader implements AutoCloseable { if (condition.getAsBoolean()) { return; } - builder.onColumnNameAction.accept(currentMetadata + builder.forAllColumnNamesConsumer.accept(currentMetadata .getColumnName(++columnNameIndex)); } @@ -379,18 +379,18 @@ public class SQLiteTableReader implements AutoCloseable { Object item = queryResults.getObject(++currRowColumnIndex); if (item instanceof String) { - builder.onStringAction.accept((String) item); + builder.forAllStringValuesConsumer.accept((String) item); } else if (item instanceof Integer) { - builder.onIntegerAction.accept((Integer) item); + builder.forAllIntegerValuesConsumer.accept((Integer) item); } else if (item instanceof Double) { - builder.onFloatAction.accept((Double) item); + builder.forAllFloatValuesConsumer.accept((Double) item); } else if (item instanceof Long) { - builder.onLongAction.accept((Long) item); + builder.forAllLongValuesConsumer.accept((Long) item); } else if (item instanceof byte[]) { - builder.onBlobAction.accept((byte[]) item); + builder.forAllBlobValuesConsumer.accept((byte[]) item); } - builder.forAllAction.accept(item); + builder.forAllTableValuesConsumer.accept(item); } unfinishedRow = false; //Wrap column index back around if we've reached the end of the row diff --git a/Core/src/org/sleuthkit/autopsy/textextractors/SqliteTextExtractor.java b/Core/src/org/sleuthkit/autopsy/textextractors/SqliteTextExtractor.java index ea204d5e30..4f027ddb6a 100755 --- a/Core/src/org/sleuthkit/autopsy/textextractors/SqliteTextExtractor.java +++ b/Core/src/org/sleuthkit/autopsy/textextractors/SqliteTextExtractor.java @@ -105,8 +105,8 @@ final class SqliteTextExtractor extends TextExtractor { public SQLiteStreamReader(AbstractFile file) { this.file = file; reader = new SQLiteTableReader.Builder(file) - .onColumnNames(getColumnNameStrategy()) - .forAll(getForAllTableValuesStrategy()).build(); + .forAllColumnNames(getColumnNameStrategy()) + .forAllTableValues(getForAllTableValuesStrategy()).build(); } /** From 26e8b6f1340ca061158222df538d7794a1432916 Mon Sep 17 00:00:00 2001 From: "U-BASIS\\dsmyda" Date: Wed, 12 Dec 2018 13:22:14 -0500 Subject: [PATCH 2/2] Fixed the header message --- .../autopsy/coreutils/SQLiteTableReader.java | 30 +++++-------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/coreutils/SQLiteTableReader.java b/Core/src/org/sleuthkit/autopsy/coreutils/SQLiteTableReader.java index b1ecea17c7..2d2b64522a 100755 --- a/Core/src/org/sleuthkit/autopsy/coreutils/SQLiteTableReader.java +++ b/Core/src/org/sleuthkit/autopsy/coreutils/SQLiteTableReader.java @@ -42,30 +42,14 @@ import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TskCoreException; /** - * Reads row by row through SQLite tables and performs user-defined actions on - * the row values. Table values are processed by data type. Users configure - these actions for certain data types in the Builder. Example usage: - - SQLiteTableReader reader = new SQLiteTableReader.Builder(file) - .forAllIntegerValues((i) - -> { System.out.println(i); }) - .build(); - - reader.read(tableName); - - or - - SQLiteTableReader reader = new SQLiteTableReader.Builder(file) - .forAllIntegerValues(new Consumer() { - * (atSymbol)Override public void accept(Integer i) { - * System.out.println(i); - * } - * }).build(); + * Reads through SQLite tables row by row. Functions performed on the + * data must be declared up front to the Builder. For example: * - * reader.reader(tableName); - * - * Invocation of read(String tableName) reads row by row. When an Integer is - * encountered, its value will be passed to the Consumer that was defined above. + * tableReader = new SQLiteTableReader.Builder(file).forAllColumnNames(System.out::println); + * tableReader.read("Sample Table X"); + * + * By declaring the functions up front, the SQLiteTableReader instance can stream the + * table contents in the most memory efficient manner. */ public class SQLiteTableReader implements AutoCloseable {