mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-12 16:06:15 +00:00
Merge pull request #4360 from dannysmyda/4436-Rename-Sqlite-Function-Names
4436 - New SqliteTableReader function names
This commit is contained in:
commit
e97e55ed89
@ -457,10 +457,10 @@ class SQLiteViewer extends javax.swing.JPanel implements FileTypeViewer {
|
|||||||
*/
|
*/
|
||||||
private void initReader() {
|
private void initReader() {
|
||||||
viewReader = new SQLiteTableReader.Builder(sqliteDbFile)
|
viewReader = new SQLiteTableReader.Builder(sqliteDbFile)
|
||||||
.onColumnNames((columnName) -> {
|
.forAllColumnNames((columnName) -> {
|
||||||
currentTableHeader.add(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();
|
String tableName = (String) this.tablesDropdownList.getSelectedItem();
|
||||||
try (FileOutputStream out = new FileOutputStream(csvFile, false)) {
|
try (FileOutputStream out = new FileOutputStream(csvFile, false)) {
|
||||||
try (SQLiteTableReader sqliteStream = new SQLiteTableReader.Builder(sqliteDbFile)
|
try (SQLiteTableReader sqliteStream = new SQLiteTableReader.Builder(sqliteDbFile)
|
||||||
.onColumnNames(getColumnNameCSVStrategy(out))
|
.forAllColumnNames(getColumnNameCSVStrategy(out))
|
||||||
.forAll(getForAllCSVStrategy(out)).build()) {
|
.forAllTableValues(getForAllCSVStrategy(out)).build()) {
|
||||||
totalColumnCount = sqliteStream.getColumnCount(tableName);
|
totalColumnCount = sqliteStream.getColumnCount(tableName);
|
||||||
sqliteStream.read(tableName);
|
sqliteStream.read(tableName);
|
||||||
}
|
}
|
||||||
|
@ -42,30 +42,14 @@ import org.sleuthkit.datamodel.SleuthkitCase;
|
|||||||
import org.sleuthkit.datamodel.TskCoreException;
|
import org.sleuthkit.datamodel.TskCoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads row by row through SQLite tables and performs user-defined actions on
|
* Reads through SQLite tables row by row. Functions performed on the
|
||||||
* the row values. Table values are processed by data type. Users configure
|
* data must be declared up front to the Builder. For example:
|
||||||
* these actions for certain data types in the Builder. Example usage:
|
|
||||||
*
|
*
|
||||||
* SQLiteTableReader reader = new SQLiteTableReader.Builder(file)
|
* tableReader = new SQLiteTableReader.Builder(file).forAllColumnNames(System.out::println);
|
||||||
* .onInteger((i)
|
* tableReader.read("Sample Table X");
|
||||||
* -> { System.out.println(i); })
|
|
||||||
* .build();
|
|
||||||
*
|
*
|
||||||
* reader.read(tableName);
|
* By declaring the functions up front, the SQLiteTableReader instance can stream the
|
||||||
*
|
* table contents in the most memory efficient manner.
|
||||||
* or
|
|
||||||
*
|
|
||||||
* SQLiteTableReader reader = new SQLiteTableReader.Builder(file)
|
|
||||||
* .onInteger(new Consumer<Integer>() {
|
|
||||||
* (atSymbol)Override public void accept(Integer i) {
|
|
||||||
* System.out.println(i);
|
|
||||||
* }
|
|
||||||
* }).build();
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
public class SQLiteTableReader implements AutoCloseable {
|
public class SQLiteTableReader implements AutoCloseable {
|
||||||
|
|
||||||
@ -76,13 +60,13 @@ public class SQLiteTableReader implements AutoCloseable {
|
|||||||
|
|
||||||
private final AbstractFile file;
|
private final AbstractFile file;
|
||||||
|
|
||||||
private Consumer<String> onColumnNameAction;
|
private Consumer<String> forAllColumnNamesConsumer;
|
||||||
private Consumer<String> onStringAction;
|
private Consumer<String> forAllStringValuesConsumer;
|
||||||
private Consumer<Long> onLongAction;
|
private Consumer<Long> forAllLongValuesConsumer;
|
||||||
private Consumer<Integer> onIntegerAction;
|
private Consumer<Integer> forAllIntegerValuesConsumer;
|
||||||
private Consumer<Double> onFloatAction;
|
private Consumer<Double> forAllFloatValuesConsumer;
|
||||||
private Consumer<byte[]> onBlobAction;
|
private Consumer<byte[]> forAllBlobValuesConsumer;
|
||||||
private Consumer<Object> forAllAction;
|
private Consumer<Object> forAllTableValuesConsumer;
|
||||||
|
|
||||||
static <T> Consumer<T> doNothing() {
|
static <T> Consumer<T> doNothing() {
|
||||||
return NOOP -> {};
|
return NOOP -> {};
|
||||||
@ -96,13 +80,13 @@ public class SQLiteTableReader implements AutoCloseable {
|
|||||||
public Builder(AbstractFile file) {
|
public Builder(AbstractFile file) {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
|
|
||||||
this.onColumnNameAction = Builder.doNothing();
|
this.forAllColumnNamesConsumer = Builder.doNothing();
|
||||||
this.onStringAction = Builder.doNothing();
|
this.forAllStringValuesConsumer = Builder.doNothing();
|
||||||
this.onLongAction = Builder.doNothing();
|
this.forAllLongValuesConsumer = Builder.doNothing();
|
||||||
this.onIntegerAction = Builder.doNothing();
|
this.forAllIntegerValuesConsumer = Builder.doNothing();
|
||||||
this.onFloatAction = Builder.doNothing();
|
this.forAllFloatValuesConsumer = Builder.doNothing();
|
||||||
this.onBlobAction = Builder.doNothing();
|
this.forAllBlobValuesConsumer = Builder.doNothing();
|
||||||
this.forAllAction = Builder.doNothing();
|
this.forAllTableValuesConsumer = Builder.doNothing();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -113,8 +97,8 @@ public class SQLiteTableReader implements AutoCloseable {
|
|||||||
*
|
*
|
||||||
* @return Builder reference
|
* @return Builder reference
|
||||||
*/
|
*/
|
||||||
public Builder onColumnNames(Consumer<String> action) {
|
public Builder forAllColumnNames(Consumer<String> action) {
|
||||||
this.onColumnNameAction = action;
|
this.forAllColumnNamesConsumer = action;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,8 +110,8 @@ public class SQLiteTableReader implements AutoCloseable {
|
|||||||
*
|
*
|
||||||
* @return Builder reference
|
* @return Builder reference
|
||||||
*/
|
*/
|
||||||
public Builder onString(Consumer<String> action) {
|
public Builder forAllStringValues(Consumer<String> action) {
|
||||||
this.onStringAction = action;
|
this.forAllStringValuesConsumer = action;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,8 +123,8 @@ public class SQLiteTableReader implements AutoCloseable {
|
|||||||
*
|
*
|
||||||
* @return Builder reference
|
* @return Builder reference
|
||||||
*/
|
*/
|
||||||
public Builder onInteger(Consumer<Integer> action) {
|
public Builder forAllIntegerValues(Consumer<Integer> action) {
|
||||||
this.onIntegerAction = action;
|
this.forAllIntegerValuesConsumer = action;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,8 +136,8 @@ public class SQLiteTableReader implements AutoCloseable {
|
|||||||
*
|
*
|
||||||
* @return Builder reference
|
* @return Builder reference
|
||||||
*/
|
*/
|
||||||
public Builder onFloat(Consumer<Double> action) {
|
public Builder forAllFloatValues(Consumer<Double> action) {
|
||||||
this.onFloatAction = action;
|
this.forAllFloatValuesConsumer = action;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,8 +149,8 @@ public class SQLiteTableReader implements AutoCloseable {
|
|||||||
*
|
*
|
||||||
* @return Builder reference
|
* @return Builder reference
|
||||||
*/
|
*/
|
||||||
public Builder onLong(Consumer<Long> action) {
|
public Builder forAllLongVaues(Consumer<Long> action) {
|
||||||
this.onLongAction = action;
|
this.forAllLongValuesConsumer = action;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,8 +162,8 @@ public class SQLiteTableReader implements AutoCloseable {
|
|||||||
*
|
*
|
||||||
* @return Builder reference
|
* @return Builder reference
|
||||||
*/
|
*/
|
||||||
public Builder onBlob(Consumer<byte[]> action) {
|
public Builder forAllBlobValues(Consumer<byte[]> action) {
|
||||||
this.onBlobAction = action;
|
this.forAllBlobValuesConsumer = action;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,8 +176,8 @@ public class SQLiteTableReader implements AutoCloseable {
|
|||||||
*
|
*
|
||||||
* @return Builder reference
|
* @return Builder reference
|
||||||
*/
|
*/
|
||||||
public Builder forAll(Consumer<Object> action) {
|
public Builder forAllTableValues(Consumer<Object> action) {
|
||||||
this.forAllAction = action;
|
this.forAllTableValuesConsumer = action;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,7 +350,7 @@ public class SQLiteTableReader implements AutoCloseable {
|
|||||||
if (condition.getAsBoolean()) {
|
if (condition.getAsBoolean()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
builder.onColumnNameAction.accept(currentMetadata
|
builder.forAllColumnNamesConsumer.accept(currentMetadata
|
||||||
.getColumnName(++columnNameIndex));
|
.getColumnName(++columnNameIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,18 +363,18 @@ public class SQLiteTableReader implements AutoCloseable {
|
|||||||
|
|
||||||
Object item = queryResults.getObject(++currRowColumnIndex);
|
Object item = queryResults.getObject(++currRowColumnIndex);
|
||||||
if (item instanceof String) {
|
if (item instanceof String) {
|
||||||
builder.onStringAction.accept((String) item);
|
builder.forAllStringValuesConsumer.accept((String) item);
|
||||||
} else if (item instanceof Integer) {
|
} else if (item instanceof Integer) {
|
||||||
builder.onIntegerAction.accept((Integer) item);
|
builder.forAllIntegerValuesConsumer.accept((Integer) item);
|
||||||
} else if (item instanceof Double) {
|
} else if (item instanceof Double) {
|
||||||
builder.onFloatAction.accept((Double) item);
|
builder.forAllFloatValuesConsumer.accept((Double) item);
|
||||||
} else if (item instanceof Long) {
|
} else if (item instanceof Long) {
|
||||||
builder.onLongAction.accept((Long) item);
|
builder.forAllLongValuesConsumer.accept((Long) item);
|
||||||
} else if (item instanceof byte[]) {
|
} 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;
|
unfinishedRow = false;
|
||||||
//Wrap column index back around if we've reached the end of the row
|
//Wrap column index back around if we've reached the end of the row
|
||||||
|
@ -105,8 +105,8 @@ final class SqliteTextExtractor extends TextExtractor {
|
|||||||
public SQLiteStreamReader(AbstractFile file) {
|
public SQLiteStreamReader(AbstractFile file) {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
reader = new SQLiteTableReader.Builder(file)
|
reader = new SQLiteTableReader.Builder(file)
|
||||||
.onColumnNames(getColumnNameStrategy())
|
.forAllColumnNames(getColumnNameStrategy())
|
||||||
.forAll(getForAllTableValuesStrategy()).build();
|
.forAllTableValues(getForAllTableValuesStrategy()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user