ignore comment lines in CSV files
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package org.lucares.pdbui;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -18,9 +19,10 @@ public class CsvReaderSettings {
|
||||
|
||||
private String timeColumn;
|
||||
|
||||
private byte comment = '#';
|
||||
|
||||
public CsvReaderSettings() {
|
||||
separator = ',';
|
||||
timeColumn = "@timestamp";
|
||||
this("@timestamp", (byte) ',', Collections.emptyList());
|
||||
}
|
||||
|
||||
private CsvReaderSettings(final String timeColumn, final byte separator, final Collection<String> ignoreColumns) {
|
||||
@@ -65,6 +67,14 @@ public class CsvReaderSettings {
|
||||
this.separator = separator;
|
||||
}
|
||||
|
||||
public byte getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setComment(final byte comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public Set<String> getIgnoreColumnNames() {
|
||||
return ignoreColumnNames;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ class CsvToEntryTransformer {
|
||||
|
||||
final byte newline = '\n';
|
||||
final byte separator = settings.getSeparator();
|
||||
final byte comment = settings.getComment();
|
||||
final byte[] line = new byte[64 * 1024]; // max line length
|
||||
int offsetInLine = 0;
|
||||
int offsetInBuffer = 0;
|
||||
@@ -64,7 +65,9 @@ class CsvToEntryTransformer {
|
||||
bytesInLine = offsetInLine + length;
|
||||
separatorPositions.add(offsetInLine + i - offsetInBuffer);
|
||||
|
||||
if (columns != null) {
|
||||
if (line[0] == comment) {
|
||||
// ignore
|
||||
} else if (columns != null) {
|
||||
|
||||
final Entry entry = handleCsvLine(columns, line, bytesInLine, separatorPositions, keyTimestamp,
|
||||
keyDuration, dateParser, additionalTags);
|
||||
|
||||
Reference in New Issue
Block a user