use of com.dexels.navajo.adapter.csvmap.CSVEntryMap in project navajo by Dexels.
the class CSVMap method getEntryFieldCount.
public int getEntryFieldCount() {
int result = -1;
if (entries != null && entries.length > 0) {
CSVEntryMap e = entries[0];
result = e.getEntrySize();
}
return result;
}
use of com.dexels.navajo.adapter.csvmap.CSVEntryMap in project navajo by Dexels.
the class CSVMap method store.
@Override
public void store() throws MappableException, UserException {
if (draftEntries != null) {
entries = new CSVEntryMap[draftEntries.size()];
int i = 0;
for (CSVEntryMap ce : draftEntries) {
entries[i++] = ce;
}
}
if (update && entries != null) {
try (FileWriter writer = new FileWriter(fileName)) {
// Write CSV.
for (int i = 0; i < entries.length; i++) {
CSVEntryMap e = entries[i];
for (int j = 0; j < e.entries.length; j++) {
writer.write(e.getEntry(Integer.valueOf(j)));
if (j < (e.entries.length - 1))
writer.write(separator);
}
if (i < (entries.length - 1))
writer.write("\n");
}
writer.close();
} catch (IOException ioe) {
throw new UserException(-1, ioe.getMessage());
}
}
}
use of com.dexels.navajo.adapter.csvmap.CSVEntryMap in project navajo by Dexels.
the class CSVMap method main.
public static void main(String[] args) throws Exception {
Mappable csv = new CSVMap();
((CSVMap) csv).setSeparator(";");
((CSVMap) csv).setIncludeEmpty(true);
((CSVMap) csv).setSkipFirstRow(false);
Binary b = new Binary(new File("C:/Temp/LedenLIJST-vertrouwelijktest.csv"));
((CSVMap) csv).setFileContent(b);
Mappable[] all = ((CSVMap) csv).getEntries();
for (int i = 0; i < all.length; i++) {
CSVEntryMap entryMap = ((CSVEntryMap) all[i]);
logger.info("a = >" + entryMap.getEntry(Integer.valueOf(0)) + "< - >" + entryMap.getEntry(Integer.valueOf(1)) + "< - >" + entryMap.getEntry(Integer.valueOf(2)) + "< - >" + entryMap.getEntry(Integer.valueOf(3)) + "< - >" + entryMap.getEntry(Integer.valueOf(4)) + "< - >" + entryMap.getEntry(Integer.valueOf(5)) + "< - >" + entryMap.getEntry(Integer.valueOf(6)) + "< - >" + entryMap.getEntry(Integer.valueOf(7)) + "< - >" + entryMap.getEntry(Integer.valueOf(8)) + "< - >" + entryMap.getEntry(Integer.valueOf(9)) + "< - >" + entryMap.getEntry(Integer.valueOf(10)) + "< - >" + entryMap.getEntry(Integer.valueOf(11)) + "<");
}
}
use of com.dexels.navajo.adapter.csvmap.CSVEntryMap in project navajo by Dexels.
the class CSVMap method parseLineDefault.
private void parseLineDefault(String line, List<CSVEntryMap> entryList) {
StringTokenizer tokens = new StringTokenizer(line, separator);
CSVEntryMap csvEntry = new CSVEntryMap();
csvEntry.entries = new String[tokens.countTokens()];
int index = 0;
while (tokens.hasMoreTokens()) {
csvEntry.entries[index++] = tokens.nextToken();
}
entryList.add(csvEntry);
}
use of com.dexels.navajo.adapter.csvmap.CSVEntryMap in project navajo by Dexels.
the class CSVMap method getEntries.
public CSVEntryMap[] getEntries() throws UserException {
BufferedReader buffer = null;
try {
Reader f = null;
if (fileContent != null) {
f = new InputStreamReader(fileContent.getDataAsStream(), StandardCharsets.UTF_8);
} else {
f = new FileReader(fileName);
}
buffer = new BufferedReader(f);
String line = "";
boolean firstLine = true;
int importCount = 0;
List<CSVEntryMap> entryList = new ArrayList<>();
while ((line = buffer.readLine()) != null) {
if (maximumImportCount != 0 && (importCount >= maximumImportCount)) {
break;
}
if (isSkipFirstRow() && firstLine) {
// First line will be skipped. Probably contains headers
} else {
if (includeEmpty) {
parseLineWithEmpty(line, entryList);
} else {
parseLineDefault(line, entryList);
}
importCount++;
}
firstLine = false;
}
entries = new CSVEntryMap[entryList.size()];
int i = 0;
for (CSVEntryMap ce : entryList) {
entries[i++] = ce;
}
} catch (java.io.IOException ioe) {
throw new UserException(-1, ioe.getMessage());
} finally {
if (buffer != null) {
try {
buffer.close();
} catch (IOException e) {
// Too late to apologize!
}
}
}
return entries;
}
Aggregations