Skip to content

Commit

Permalink
added skip options to skip one failed line
Browse files Browse the repository at this point in the history
added skip options to skip one failed line
  • Loading branch information
namsor committed Oct 16, 2020
1 parent cf5b3c3 commit 7e3e2c2
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/main/java/com/namsor/tools/NamSorTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public class NamSorTools {
private final int TIMEOUT = 30000;
private final boolean withUID;
private final boolean recover;
private final boolean skipErrors;
private final MessageDigest digest;

public NamSorTools(CommandLine commandLineOptions) {
Expand All @@ -158,6 +159,7 @@ public NamSorTools(CommandLine commandLineOptions) {

withUID = commandLineOptions.hasOption("uid");
recover = commandLineOptions.hasOption("recover");
skipErrors = commandLineOptions.hasOption("skip");

MessageDigest digest_ = null;
if (commandLineOptions.hasOption("digest")) {
Expand Down Expand Up @@ -259,6 +261,13 @@ public static void main(String[] args) {
.required(false)
.build();

Option skipErrors = Option.builder("s").argName("skip")
.hasArg(false)
.desc("skip errors")
.longOpt("skip")
.required(false)
.build();

Option inputDataFormat = Option.builder("f").argName("inputDataFormat")
.hasArg()
.desc("input data format : first name, last name (fnln) / first name, last name, geo country iso2 (fnlngeo) / full name (name) / full name, geo country iso2 (namegeo) ")
Expand Down Expand Up @@ -316,6 +325,7 @@ public static void main(String[] args) {
options.addOption(outputFile);
options.addOption(outputHeader);
options.addOption(service);
options.addOption(skipErrors);
options.addOption(encoding);
options.addOption(outputFileOverwrite);
options.addOption(countryIso2);
Expand Down Expand Up @@ -495,7 +505,14 @@ private void process(String service, BufferedReader reader, Writer writer, Strin
}
String[] lineData = line.split("\\|");
if (lineData.length != dataLenExpected) {
throw new NamSorToolException("Line " + lineId + ", expected input with format : " + dataFormatExpected.toString() + " line = " + line);
if( skipErrors ) {
Logger.getLogger(getClass().getName()).warning("Line " + lineId + ", expected input with format : " + dataFormatExpected.toString() + " line = " + line);
lineId++;
line = reader.readLine();
continue;
} else {
throw new NamSorToolException("Line " + lineId + ", expected input with format : " + dataFormatExpected.toString() + " line = " + line);
}
}
String uid = null;
int col = 0;
Expand Down

0 comments on commit 7e3e2c2

Please sign in to comment.