/** * Closes resources. * * @throws IOException * If an I/O error occurs */ public void close() throws IOException { if (this.lexer != null) { this.lexer.close(); } }
/** * Returns the current line number in the input stream. * <p/> * ATTENTION: If your CSV input has multi-line values, the returned number does not correspond to the record number. * * @return current line number */ public long getCurrentLineNumber() { return this.lexer.getCurrentLineNumber(); }
public boolean isClosed() { return this.lexer.isClosed(); }
boolean eol = readEndOfLine(c); while (eol && isStartOfLine(lastChar)) { eol = readEndOfLine(c); if (isEndOfFile(c)) { token.type = EOF; if (isEndOfFile(lastChar) || (!isDelimiter(lastChar) && isEndOfFile(c))) { token.type = EOF; if (isStartOfLine(lastChar) && isCommentStart(c)) { final String line = in.readLine(); if (line == null) { while (isWhitespace(c) && !eol) { c = in.read(); eol = readEndOfLine(c); if (isDelimiter(c)) { } else if (isQuoteChar(c)) { parseEncapsulatedToken(token); } else if (isEndOfFile(c)) { parseSimpleToken(token, c);
final long startLineNumber = getCurrentLineNumber(); int c; while (true) { c = in.read(); if (isEscape(c)) { final int unescaped = readEscape(); if (unescaped == Constants.END_OF_STREAM) { // unexpected char after escape token.content.append((char) c).append((char) in.getLastChar()); } else if (isQuoteChar(c)) { if (isQuoteChar(in.lookAhead())) { if (isDelimiter(c)) { token.type = TOKEN; return token; } else if (isEndOfFile(c)) { token.type = EOF; token.isReady = true; // There is data at EOF return token; } else if (readEndOfLine(c)) { token.type = EORECORD; return token; } else if (!isWhitespace(c)) { throw new IOException("(line " + getCurrentLineNumber() + ") invalid char between encapsulated token and delimiter"); } else if (isEndOfFile(c)) {
if (readEndOfLine(ch)) { token.type = EORECORD; break; } else if (isEndOfFile(ch)) { token.type = EOF; token.isReady = true; // There is data at EOF break; } else if (isDelimiter(ch)) { token.type = TOKEN; break; } else if (isEscape(ch)) { final int unescaped = readEscape(); if (unescaped == Constants.END_OF_STREAM) { // unexpected char after escape token.content.append((char) ch).append((char) in.getLastChar()); trimTrailingSpaces(token.content);
/** * @return true if the given char is a whitespace character */ boolean isWhitespace(final int ch) { return !isDelimiter(ch) && Character.isWhitespace((char) ch); }
default: if (isMetaChar(ch)) { return ch;
/** * Customized CSV parser using the given {@link CSVFormat} * * <p> * If you do not read all records from the given {@code reader}, you should call {@link #close()} on the parser, * unless you close the {@code reader}. * </p> * * @param reader * a Reader containing CSV-formatted input. Must not be null. * @param format * the CSVFormat used for CSV parsing. Must not be null. * @throws IllegalArgumentException * If the parameters of the format are inconsistent or if either reader or format are null. * @throws IOException * If an I/O error occurs */ public CSVParser(final Reader reader, final CSVFormat format) throws IOException { Args.notNull(reader, "reader"); Args.notNull(format, "format"); format.validate(); this.format = format; this.lexer = new Lexer(format, new ExtendedBufferedReader(reader)); this.headerMap = this.initializeHeader(); }