X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Fcore%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Futil%2FCSV.java;h=a395887882c84e591bccff1b338e2a00a58f3a00;hb=628b7105ce4d9818aac69a082e515f9275fd46fd;hp=ed4fcde69120a92e950a5c2f43abe736a0ef97ef;hpb=a6baa197a8a0333bc90e03a135441cacb7a133b9;p=aaf%2Fauthz.git diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/util/CSV.java b/cadi/core/src/main/java/org/onap/aaf/cadi/util/CSV.java index ed4fcde6..a3958878 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/util/CSV.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/util/CSV.java @@ -30,7 +30,9 @@ import java.io.PrintStream; import java.util.ArrayList; import java.util.List; +import org.onap.aaf.cadi.Access; import org.onap.aaf.cadi.CadiException; +import org.onap.aaf.cadi.Access.Level; /** * Read CSV file for various purposes @@ -40,17 +42,30 @@ import org.onap.aaf.cadi.CadiException; */ public class CSV { private File csv; + private Access access; + private boolean processAll; - public CSV(File file) { + public CSV(Access access, File file) { + this.access = access; csv = file; + processAll = false; } - public CSV(String csvFilename) { + public CSV(Access access, String csvFilename) { + this.access = access; csv = new File(csvFilename); + processAll = false; } + public String name() { + return csv.getName(); + } - /** + public CSV processAll() { + processAll = true; + return this; + } + /* * Create your code to accept the List row. * * Your code may keep the List... CSV does not hold onto it. @@ -74,7 +89,7 @@ public class CSV { List row = new ArrayList<>(); boolean quotes=false; boolean escape=false; - char c; + char c = 0; for(int i=0;i0) { + if(sb.length()>0 || c==',') { row.add(sb.toString()); sb.setLength(0); } - visitor.visit(row); + try { + visitor.visit(row); + } catch (CadiException e) { + if(processAll) { + access.log(Level.ERROR,e); + } else { + throw e; + } + } } } } finally { @@ -147,7 +170,8 @@ public class CSV { } else { ps.append(','); } - if(o instanceof String[]) { + if(o == null) { + } else if(o instanceof String[]) { for(String str : (String[])o) { print(str); } @@ -177,9 +201,10 @@ public class CSV { * Note: CSV files do not actually support Comments as a standard, but it is useful * @param comment */ - public void comment(String comment) { + public void comment(String comment, Object ... objs) { ps.print("# "); - ps.println(comment); + ps.printf(comment,objs); + ps.println(); } public void flush() {