public static CsvReader getCsvReader(Reader reader) { CsvReader csvReader = new CsvReader(reader); csvReader.setEscapeMode(CsvReader.ESCAPE_MODE_BACKSLASH); csvReader.setSafetySwitch(false); csvReader.setCaptureRawRecord(false); return csvReader; }
/** * Closes and releases all related resources. */ public void close() { if (!closed) { close(true); closed = true; } }
public boolean isQualified(int columnIndex) throws IOException { checkClosed(); if (columnIndex < columnsCount && columnIndex > -1) { return isQualified[columnIndex]; } else { return false; } }
/** * Returns the current column value for a given column header name. * * @param headerName * The header name of the column. * @return The current column value. * @exception IOException * Thrown if this object has already been closed. */ public String get(String headerName) throws IOException { checkClosed(); return get(getIndex(headerName)); }
/** * 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; }
/** * Writes a new record using the passed in array of values. * * @param values * Values to be written. * * @param preserveSpaces * Whether to preserver leading and trailing spaces in * columns while writing out to the record or not. * * @throws IOException * Thrown if an error occurs while writing data to the * destination stream. */ public void writeRecord(String[] values, boolean preserveSpaces) throws IOException { if (values != null && values.length > 0) { for (int i = 0; i < values.length; i++) { write(values[i], preserveSpaces); } endRecord(); } }
/** * Closes and releases all related resources. */ public void close() { if (!closed) { close(true); closed = true; } }
/** * Writes another column of data to this record. Does not preserve * leading and trailing whitespace in this column of data. * * @param content * The data for the new column. * @exception IOException * Thrown if an error occurs while writing data to the * destination stream. */ public void write(String content) throws IOException { write(content, false); }
/** * Writes a new record using the passed in array of values. * * @param values * Values to be written. * * @throws IOException * Thrown if an error occurs while writing data to the * destination stream. */ public void writeRecord(String[] values) throws IOException { writeRecord(values, false); }
public void writeComment(String commentText) throws IOException { checkClosed(); checkInit(); outputStream.write(userSettings.Comment); outputStream.write(commentText); if (useCustomRecordDelimiter) { outputStream.write(userSettings.RecordDelimiter); } else { outputStream.println(); } firstColumn = true; }
private void appendLetter(char letter) { if (columnBuffer.Position == columnBuffer.Buffer.length) { int newLength = newLength(columnBuffer.Buffer.length); char[] holder = new char[newLength]; System.arraycopy(columnBuffer.Buffer, 0, holder, 0, columnBuffer.Position); columnBuffer.Buffer = holder; } columnBuffer.Buffer[columnBuffer.Position++] = letter; dataBuffer.ColumnStart = dataBuffer.Position + 1; }
private void updateCurrentValue() { if (startedColumn && dataBuffer.ColumnStart < dataBuffer.Position) { expandColumnBuffer(); System.arraycopy(dataBuffer.Buffer, dataBuffer.ColumnStart, columnBuffer.Buffer, columnBuffer.Position, dataBuffer.Position - dataBuffer.ColumnStart); columnBuffer.Position += dataBuffer.Position - dataBuffer.ColumnStart; } dataBuffer.ColumnStart = dataBuffer.Position + 1; }
@Override protected void finish() { if (csvReader != null) { csvReader.close(); } }
@Override protected void finalize() { close(false); }
/** * Returns the current column value for a given column index. * * @param columnIndex * The index of the column. * @return The current column value. * @exception IOException * Thrown if this object has already been closed. */ public String get(int columnIndex) throws IOException { checkClosed(); if (columnIndex > -1 && columnIndex < columnsCount) { return values[columnIndex]; } else { return ""; } }
protected void expandColumnBuffer() { int roomLeftInColumnBuffer = columnBuffer.Buffer.length - columnBuffer.Position; int dataLeftInDataBuffer = dataBuffer.Position - dataBuffer.ColumnStart; if (roomLeftInColumnBuffer < dataLeftInDataBuffer) { int newLength = Math.max(columnBuffer.Buffer.length + dataLeftInDataBuffer - roomLeftInColumnBuffer, newLength(columnBuffer.Buffer.length)); char[] holder = new char[newLength]; System.arraycopy(columnBuffer.Buffer, 0, holder, 0, columnBuffer.Position); columnBuffer.Buffer = holder; } }
@Override protected void finalize() { close(false); }
/** * Returns the column header value for a given column index. * * @param columnIndex * The index of the header column being requested. * @return The value of the column header at the given column index. * @exception IOException * Thrown if this object has already been closed. */ public String getHeader(int columnIndex) throws IOException { checkClosed(); // check to see if we have read the header record yet // check to see if the column index is within the bounds // of our header array if (columnIndex > -1 && columnIndex < headersHolder.Length) { // return the processed header data for this column return headersHolder.Headers[columnIndex]; } else { return ""; } }
public void close() { if (csvReader != null) { csvReader.close(); } if (stagedResource != null) { stagedResource.close(); } }
public String[] getValues() throws IOException { checkClosed(); // need to return a clone, and can't use clone because values.Length // might be greater than columnsCount String[] clone = new String[columnsCount]; System.arraycopy(values, 0, clone, 0, columnsCount); return clone; }