mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-13 00:16:16 +00:00
Merge pull request #6664 from gdicristofaro/7215b-externalLibNonPrintableRemove
7215b remove erroneous rows
This commit is contained in:
commit
c3a0dbc794
@ -314,9 +314,10 @@ public final class LeappFileProcessor {
|
||||
idx -> idx,
|
||||
(val1, val2) -> val1));
|
||||
|
||||
int lineNum = 1;
|
||||
int lineNum = 2;
|
||||
while (iterator.hasNext()) {
|
||||
Collection<BlackboardAttribute> bbattributes = processReadLine(iterator.next(), columnIndexes, attrList, fileName, lineNum++);
|
||||
List<String> columnItems = iterator.next();
|
||||
Collection<BlackboardAttribute> bbattributes = processReadLine(columnItems, columnIndexes, attrList, fileName, lineNum);
|
||||
|
||||
if (!bbattributes.isEmpty()) {
|
||||
BlackboardArtifact bbartifact = createArtifactWithAttributes(artifactType.getTypeID(), dataSource, bbattributes);
|
||||
@ -324,6 +325,8 @@ public final class LeappFileProcessor {
|
||||
bbartifacts.add(bbartifact);
|
||||
}
|
||||
}
|
||||
|
||||
lineNum++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -334,7 +337,8 @@ public final class LeappFileProcessor {
|
||||
*
|
||||
* @param lineValues List of column values.
|
||||
* @param columnIndexes Mapping of column headers (trimmed; to lower case)
|
||||
* to column index.
|
||||
* to column index. All header columns and only all header columns should be
|
||||
* present.
|
||||
* @param attrList The list of attributes as specified for the schema of
|
||||
* this file.
|
||||
* @param fileName The name of the file being processed.
|
||||
@ -349,25 +353,38 @@ public final class LeappFileProcessor {
|
||||
if (MapUtils.isEmpty(columnIndexes) || CollectionUtils.isEmpty(lineValues)
|
||||
|| (lineValues.size() == 1 && StringUtils.isEmpty(lineValues.get(0)))) {
|
||||
return Collections.emptyList();
|
||||
} else if (lineValues.size() != columnIndexes.size()) {
|
||||
logger.log(Level.WARNING, String.format(
|
||||
"Row at line number %d in file %s has %d columns when %d were expected based on the header row.",
|
||||
lineNum, fileName, lineValues.size(), columnIndexes.size()));
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<BlackboardAttribute> attrsToRet = new ArrayList<>();
|
||||
for (TsvColumn colAttr : attrList) {
|
||||
if (colAttr.getAttributeType() == null) {
|
||||
// this handles columns that are currently ignored.
|
||||
continue;
|
||||
}
|
||||
|
||||
Integer columnIdx = columnIndexes.get(colAttr.getColumnName());
|
||||
String value = (columnIdx == null || columnIdx >= lineValues.size() || columnIdx < 0) ? null : lineValues.get(columnIdx);
|
||||
if (value == null) {
|
||||
logger.log(Level.WARNING, String.format("No value found for column %s at line %d in file %s.", colAttr.getColumnName(), lineNum, fileName));
|
||||
if (columnIdx == null) {
|
||||
logger.log(Level.WARNING, String.format("No column mapping found for %s in file %s. Omitting column.", colAttr.getColumnName(), fileName));
|
||||
continue;
|
||||
}
|
||||
|
||||
BlackboardAttribute attr = (value == null) ? null : getAttribute(colAttr.getAttributeType(), value, fileName);
|
||||
if (attr != null) {
|
||||
attrsToRet.add(attr);
|
||||
String value = (columnIdx >= lineValues.size() || columnIdx < 0) ? null : lineValues.get(columnIdx);
|
||||
if (value == null) {
|
||||
logger.log(Level.WARNING, String.format("No value found for column %s at line %d in file %s. Omitting row.", colAttr.getColumnName(), lineNum, fileName));
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
BlackboardAttribute attr = (value == null) ? null : getAttribute(colAttr.getAttributeType(), value, fileName);
|
||||
if (attr == null) {
|
||||
logger.log(Level.WARNING, String.format("Blackboard attribute could not be parsed column %s at line %d in file %s. Omitting row.", colAttr.getColumnName(), lineNum, fileName));
|
||||
return Collections.emptyList();
|
||||
}
|
||||
attrsToRet.add(attr);
|
||||
}
|
||||
|
||||
if (tsvFileArtifactComments.containsKey(fileName)) {
|
||||
@ -458,6 +475,10 @@ public final class LeappFileProcessor {
|
||||
* @return The generated blackboard attribute or null if not determined.
|
||||
*/
|
||||
private BlackboardAttribute parseAttrValue(String value, BlackboardAttribute.Type attrType, String fileName, boolean blankIsNull, boolean zeroIsNull, ParseExceptionFunction valueConverter) {
|
||||
// remove non-printable characters from tsv input
|
||||
// https://stackoverflow.com/a/6199346
|
||||
value = value.replaceAll("\\p{C}", "");
|
||||
|
||||
if (blankIsNull && StringUtils.isBlank(value)) {
|
||||
return null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user