/** * Skips the next record of data by parsing each column. Does not * increment * {@link org.jumpmind.symmetric.csv.CsvReader#getCurrentRecord getCurrentRecord()}. * * @return Whether another record was successfully skipped or not. * @exception IOException * Thrown if an error occurs while reading data from the * source stream. */ public boolean skipRecord() throws IOException { checkClosed(); boolean recordRead = false; if (hasMoreData) { recordRead = readRecord(); if (recordRead) { currentRecord--; } } return recordRead; }
/** * Read the first record of data as column headers. * * @return Whether the header record was successfully read or not. * @exception IOException * Thrown if an error occurs while reading data from the * source stream. */ public boolean readHeaders() throws IOException { boolean result = readRecord(); // copy the header data from the column array // to the header string array headersHolder.Length = columnsCount; headersHolder.Headers = new String[columnsCount]; for (int i = 0; i < headersHolder.Length; i++) { String columnValue = get(i); headersHolder.Headers[i] = columnValue; // if there are duplicate header names, we will save the last one headersHolder.IndexByName.put(columnValue, new Integer(i)); } if (result) { currentRecord--; } columnsCount = 0; return result; }
public static String[] tokenizeCsvData(String csvData) { String[] tokens = null; if (csvData != null) { CsvReader csvReader = getCsvReader(new StringReader(csvData)); try { if (csvReader.readRecord()) { tokens = csvReader.getValues(); } } catch (IOException e) { } } return tokens; }
@Override protected CsvData readNext() { try { if (csvReader.readRecord()) { String[] tokens = csvReader.getValues(); return buildCsvData(tokens, DataEventType.INSERT); } else { return null; } } catch (IOException ex) { throw new IoException(ex); } }
long bytesRead = 0; Table table = null; while (tokens != null || csvReader.readRecord()) { lineNumber++; context.put(CTX_LINE_NUMBER, lineNumber);