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=476b2df15a625cd3720faed366e89a7d28cda189;hb=refs%2Fchanges%2F24%2F97124%2F3;hp=2c9bb8c44ab6c842a188a7f3bf6bbcc43ffa50ac;hpb=bdce7667a6e272e2fa32e298d957a0d9090c5bc9;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 2c9bb8c4..476b2df1 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 @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -36,7 +36,7 @@ import org.onap.aaf.cadi.CadiException; /** * Read CSV file for various purposes - * + * * @author Instrumental(Jonathan) * */ @@ -46,26 +46,26 @@ public class CSV { private boolean processAll; private char delimiter = ','; private boolean go; - + public CSV(Access access, File file) { this.access = access; csv = file; processAll = false; go = true; } - + public CSV(Access access, String csvFilename) { this.access = access; csv = new File(csvFilename); processAll = false; go = true; } - + public CSV setDelimiter(char delimiter) { this.delimiter = delimiter; return this; } - + public String name() { return csv.getName(); } @@ -76,16 +76,16 @@ public class CSV { } /* * Create your code to accept the List row. - * + * * Your code may keep the List... CSV does not hold onto it. - * + * * @author Instrumental(Jonathan) * */ public interface Visitor { void visit(List row) throws IOException, CadiException; } - + public void visit(Visitor visitor) throws IOException, CadiException { BufferedReader br = new BufferedReader(new FileReader(csv)); try { @@ -165,7 +165,7 @@ public class CSV { br.close(); } } - + public Writer writer() throws FileNotFoundException { return new Writer(false); } @@ -177,10 +177,10 @@ public class CSV { public interface RowSetter { public void row(Object ... objs); } - + public static class Saver implements RowSetter { List ls= new ArrayList<>(); - + @Override public void row(Object ... objs) { if(objs.length>0) { @@ -197,7 +197,7 @@ public class CSV { } } } - + public List asList() { List rv = ls; ls = new ArrayList<>(); @@ -210,7 +210,7 @@ public class CSV { private Writer(final boolean append) throws FileNotFoundException { ps = new PrintStream(new FileOutputStream(csv,append)); } - + @Override public void row(Object ... objs) { if(objs.length>0) { @@ -233,7 +233,7 @@ public class CSV { ps.println(); } } - + private void print(String s) { boolean quote = s.matches(".*[,|\"].*"); if(quote) { @@ -246,7 +246,7 @@ public class CSV { ps.append(s); } - + } /** * Note: CSV files do not actually support Comments as a standard, but it is useful @@ -257,32 +257,32 @@ public class CSV { ps.printf(comment,objs); ps.println(); } - + public void flush() { ps.flush(); } - + public void close() { flush(); ps.close(); } - + public String toString() { return csv.getAbsolutePath(); } } - + /** * Provides a way to stop processing records from inside a Visit */ public void stop() { - go = false; + go = false; } public void delete() { csv.delete(); } - + public String toString() { return csv.getAbsolutePath(); }