use of org.supercsv.io.CsvListReader in project Xponents by OpenSextant.
the class TextUtils method initLOCLanguageData.
/**
* This is Libray of Congress data for language IDs. This is offered as a
* tool to help downstream language ID and enrich metadata when tagging data
* from particular countries.
*
* Reference: http://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt
*
* @throws java.io.IOException
* if resource file is not found
*/
public static void initLOCLanguageData() throws java.io.IOException {
//
// DATA FILE: http://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt
java.io.InputStream io = TextUtils.class.getResourceAsStream("/ISO-639-2_utf-8.txt");
java.io.Reader featIO = new InputStreamReader(io, "UTF-8");
CsvListReader langReader = new CsvListReader(featIO, new CsvPreference.Builder('"', '|', "\n").build());
CellProcessor[] cells = { new Optional(), new Optional(), new Optional(), new Optional(), new NotNull() };
List<Object> lang = null;
/*
* ISO3,XX,ISO2,NAME,NAME_FR
*/
while ((lang = langReader.read(cells)) != null) {
//
String names = (String) lang.get(3);
if (isBlank(names)) {
continue;
}
if ("NAME".equals(names)) {
continue;
}
List<String> namelist = TextUtils.string2list(names, ";");
String iso3 = (String) lang.get(0);
if (iso3.startsWith("#")) {
continue;
}
String iso2 = (String) lang.get(2);
Language l = new Language(iso3, iso2, namelist.get(0));
addLanguage(l);
}
langReader.close();
// Popular languages that go by other codes.
// ISO languages as listed by LOC are listed with Bibliographic vs.
// Terminological codes.
// FRE vs. FRA are subtle difference for French, but important if you
// cannot find French by lang ID.
//
// Fully override French and Trad Chinese:
Language fr = new Language("fra", "fr", "French");
addLanguage(fr, true);
Language zhtw = new Language("zh-tw", "zt", "Chinese/Taiwain");
addLanguage(zhtw, true);
// Delicately insert more common names and codes as well as locales
// here.
Language zh = new Language("zho", "zh", "Chinese");
languageMapISO639.put("zho", zh);
Language zhcn = new Language("chi", "zh", "Chinese");
languageMapISO639.put("zh-cn", zhcn);
Language fas = new Language("per", "fa", "Farsi");
languageMapISO639.put("farsi", fas);
// Locales of English -- are still "English"
Language en1 = new Language("eng", "en", "English");
languageMapISO639.put("en-gb", en1);
languageMapISO639.put("en-us", en1);
languageMapISO639.put("en-au", en1);
}
use of org.supercsv.io.CsvListReader in project adempiere by adempiere.
the class CSVFactory method read.
public Collection<TestableMRP> read(InputStream in) throws Exception {
ArrayList<TestableMRP> tests = new ArrayList<TestableMRP>();
//
reader = new CsvListReader(new InputStreamReader(in), CsvPreference.STANDARD_PREFERENCE);
String[] header = reader.getCSVHeader(true);
System.out.println("HEADER: " + MRPUtil.toString(header));
//
List<String> line;
int last_lineNo = -1;
boolean isPlanningLine = true;
TestableMRP mrpTest = null;
try {
while ((line = reader.read()) != null) {
if (last_lineNo == -1 || last_lineNo + 1 < reader.getLineNumber()) {
isPlanningLine = true;
if (mrpTest != null) {
tests.add(mrpTest);
}
mrpTest = new TestableMRP();
}
if (isPlanningLine) {
readProductPlanning(mrpTest, header, line);
isPlanningLine = false;
} else {
readMRPLine(mrpTest, header, line);
}
//
last_lineNo = reader.getLineNumber();
}
} catch (Exception e) {
throw new RuntimeException("Error on line " + reader.getLineNumber() + ": " + e.getLocalizedMessage(), e);
}
if (mrpTest != null) {
tests.add(mrpTest);
}
//
return tests;
}
use of org.supercsv.io.CsvListReader in project adempiere by adempiere.
the class CSVFactory method read.
public Collection<MMScenario> read(InputStream in) throws Exception {
ArrayList<MMScenario> tests = new ArrayList<MMScenario>();
//
reader = new CsvListReader(new InputStreamReader(in), CsvPreference.STANDARD_PREFERENCE);
String[] header = getCSVHeader();
//
List<String> line;
int last_lineNo = -1;
MMScenario scenario = null;
try {
while ((line = reader.read()) != null) {
if (last_lineNo == -1 || last_lineNo + 1 < reader.getLineNumber()) {
if (scenario != null) {
tests.add(scenario);
}
scenario = new MMScenario("junit-test-line_" + (new DecimalFormat("000").format(reader.getLineNumber())));
}
readDocument(scenario, header, line);
last_lineNo = reader.getLineNumber();
}
} catch (Exception e) {
throw new RuntimeException("Error on line " + reader.getLineNumber() + ": " + e.getLocalizedMessage(), e);
}
if (scenario != null) {
tests.add(scenario);
}
//
return tests;
}
use of org.supercsv.io.CsvListReader in project adempiere by adempiere.
the class CSVFactory method read.
public Collection<MMScenario> read(InputStream in) throws Exception {
ArrayList<MMScenario> tests = new ArrayList<MMScenario>();
//
reader = new CsvListReader(new InputStreamReader(in), CsvPreference.STANDARD_PREFERENCE);
String[] header = getCSVHeader();
//
List<String> line;
int last_lineNo = -1;
MMScenario scenario = null;
try {
while ((line = reader.read()) != null) {
if (last_lineNo == -1 || last_lineNo + 1 < reader.getLineNumber()) {
if (scenario != null) {
tests.add(scenario);
}
scenario = new MMScenario("junit-test-line_" + (new DecimalFormat("000").format(reader.getLineNumber())));
}
readDocument(scenario, header, line);
last_lineNo = reader.getLineNumber();
}
} catch (Exception e) {
throw new RuntimeException("Error on line " + reader.getLineNumber() + ": " + e.getLocalizedMessage(), e);
}
if (scenario != null) {
tests.add(scenario);
}
//
return tests;
}
use of org.supercsv.io.CsvListReader in project voltdb by VoltDB.
the class CSVLoader method main.
/**
* csvloader main. (main is directly used by tests as well be sure to reset statics that you need to start over)
*
* @param args
* @throws IOException
* @throws InterruptedException
*
*/
public static void main(String[] args) throws IOException, InterruptedException {
start = System.currentTimeMillis();
long insertTimeStart = start;
long insertTimeEnd;
final CSVConfig cfg = new CSVConfig();
cfg.parse(CSVLoader.class.getName(), args);
config = cfg;
if (config.noquotechar) {
config.quotechar = '