Code Review
/
aaf
/
authz.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Approval Batch, prep better JUnit
[aaf/authz.git]
/
cadi
/
core
/
src
/
main
/
java
/
org
/
onap
/
aaf
/
cadi
/
util
/
CSV.java
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
c7fada7
..
a834db5
100644
(file)
--- 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 java.util.ArrayList;
import java.util.List;
+import org.onap.aaf.cadi.Access;
import org.onap.aaf.cadi.CadiException;
import org.onap.aaf.cadi.CadiException;
+import org.onap.aaf.cadi.Access.Level;
/**
* Read CSV file for various purposes
/**
* Read CSV file for various purposes
@@
-40,17
+42,26
@@
import org.onap.aaf.cadi.CadiException;
*/
public class CSV {
private File csv;
*/
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;
csv = file;
+ processAll = false;
}
}
- public CSV(String csvFilename) {
+ public CSV(Access access, String csvFilename) {
+ this.access = access;
csv = new File(csvFilename);
csv = new File(csvFilename);
+ processAll = false;
}
}
-
- /**
+ public CSV processAll() {
+ processAll = true;
+ return this;
+ }
+ /*
* Create your code to accept the List<String> row.
*
* Your code may keep the List... CSV does not hold onto it.
* Create your code to accept the List<String> row.
*
* Your code may keep the List... CSV does not hold onto it.
@@
-117,7
+128,15
@@
public class CSV {
row.add(sb.toString());
sb.setLength(0);
}
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 {
}
}
} finally {
@@
-138,33
+157,42
@@
public class CSV {
private Writer(final boolean append) throws FileNotFoundException {
ps = new PrintStream(new FileOutputStream(csv,append));
}
private Writer(final boolean append) throws FileNotFoundException {
ps = new PrintStream(new FileOutputStream(csv,append));
}
- public void row(Object ...
string
s) {
- if(
string
s.length>0) {
+ public void row(Object ...
obj
s) {
+ if(
obj
s.length>0) {
boolean first = true;
boolean first = true;
- boolean quote;
- String s;
- for(Object o : strings) {
+ for(Object o : objs) {
if(first) {
first = false;
} else {
ps.append(',');
}
if(first) {
first = false;
} else {
ps.append(',');
}
- s = o.toString();
- quote = s.matches(".*[,|\"].*");
- if(quote) {
- ps.append('"');
- ps.print(s.replace("\"", "\"\"")
- .replace("'", "''")
- .replace("\\", "\\\\"));
- ps.append('"');
+ if(o == null) {
+ } else if(o instanceof String[]) {
+ for(String str : (String[])o) {
+ print(str);
+ }
} else {
} else {
- p
s.append(s
);
+ p
rint(o.toString()
);
}
}
ps.println();
}
}
}
}
ps.println();
}
}
+ private void print(String s) {
+ boolean quote = s.matches(".*[,|\"].*");
+ if(quote) {
+ ps.append('"');
+ ps.print(s.replace("\"", "\"\"")
+ .replace("'", "''")
+ .replace("\\", "\\\\"));
+ ps.append('"');
+ } else {
+ ps.append(s);
+ }
+
+
+ }
/**
* Note: CSV files do not actually support Comments as a standard, but it is useful
* @param comment
/**
* Note: CSV files do not actually support Comments as a standard, but it is useful
* @param comment