/** INTERNAL API. but ctor needs to be called dynamically by PerformanceTest class */ Lexer(final CSVFormat format, final ExtendedBufferedReader in) { this.in = in; this.delimiter = format.getDelimiter(); this.escape = mapNullToDisabled(format.getEscape()); this.quoteChar = mapNullToDisabled(format.getQuoteChar()); this.commentStart = mapNullToDisabled(format.getCommentStart()); this.ignoreSurroundingSpaces = format.getIgnoreSurroundingSpaces(); this.ignoreEmptyLines = format.getIgnoreEmptyLines(); }
public boolean hasNext() { if (CSVParser.this.isClosed()) { return false; } if (this.current == null) { this.current = this.getNextRecord(); } return this.current != null; }
/** * Sets the trimming behavior of the format. * * @param ignoreSurroundingSpaces * the trimming behavior, <tt>true</tt> to remove the surrounding spaces, <tt>false</tt> to leave the * spaces as is. * @return A new CSVFormat that is equal to this but with the specified trimming behavior. */ public CSVFormat withIgnoreSurroundingSpaces(final boolean ignoreSurroundingSpaces) { return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape, ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, header, skipHeaderRecord); }
private void print(final Object object, final CharSequence value, final int offset, final int len) throws IOException { if (!newRecord) { out.append(format.getDelimiter()); } if (format.isQuoting()) { // the original object is needed so can check for Number printAndQuote(object, value, offset, len); } else if (format.isEscaping()) { printAndEscape(value, offset, len); } else { out.append(value, offset, offset + len); } newRecord = false; }
/** * Greedily accepts \n, \r and \r\n This checker consumes silently the second control-character... * * @return true if the given or next character is a line-terminator */ boolean readEndOfLine(int ch) throws IOException { // check if we have \r\n... if (ch == CR && in.lookAhead() == LF) { // note: does not change ch outside of this method! ch = in.read(); } return ch == LF || ch == CR; }
/** * Prints a single line of delimiter separated values. The values will be quoted if needed. Quotes and newLine * characters will be escaped. * * @param values * values to output. * @throws IOException * If an I/O error occurs */ public void printRecord(final Object... values) throws IOException { for (final Object value : values) { print(value); } println(); }
/** * Parses the next record from the current point in the stream. * * @return the record as an array of values, or <tt>null</tt> if the end of the stream has been reached * @throws IOException * on parse error or input read-failure */ CSVRecord nextRecord() throws IOException { if(tryNextRecord()){ return new CSVRecord(this.record.toArray(new String[this.record.size()]), this.headerMap,recordComment,this.recordNumber); } return null; }
/** * Closes resources. * * @throws IOException * If an I/O error occurs */ void close() throws IOException { in.close(); } }
/** * 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(); }
/** * Returns the current line number * * @return the current line number */ long getCurrentLineNumber() { return in.getCurrentLineNumber(); }
public boolean isClosed() { return this.lexer.isClosed(); }
public static Map<String, String> readMapFromResources(String location, CaseType toCase, final boolean skipHeader) { return readMapFromResources(new String[]{location}, toCase, skipHeader); }
public static List<String[]> readSkipHeader(Reader reader) { return readList(reader, DEFAULT_FORMAT_SKIP_HEADER); }
boolean isClosed() { return in.isClosed(); }
public CSVRecord next() { if (CSVParser.this.isClosed()) { throw new NoSuchElementException("CSVParser has been closed"); } CSVRecord next = this.current; this.current = null; if (next == null) { // hasNext() wasn't called before next = this.getNextRecord(); if (next == null) { throw new NoSuchElementException("No more CSV records available"); } } return next; }
/** * Sets the output quote policy of the format to the specified value. * * @param quotePolicy * the quote policy to use for output. * * @return A new CSVFormat that is equal to this but with the specified quote policy */ public CSVFormat withQuotePolicy(final Quote quotePolicy) { return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape, ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, header, skipHeaderRecord); }
/** * Creates a new CSV format with the specified delimiter. * * @param delimiter * the char used for value separation, must not be a line break character * @return a new CSV format. * @throws IllegalArgumentException if the delimiter is a line break character */ public static CSVFormat newFormat(final char delimiter) { return new CSVFormat(delimiter, null, null, null, null, false, false, null, null, null, false); }
/** * Sets the empty line skipping behavior of the format. * * @param ignoreEmptyLines * the empty line skipping behavior, <tt>true</tt> to ignore the empty lines between the records, * <tt>false</tt> to translate empty lines to empty records. * @return A new CSVFormat that is equal to this but with the specified empty line skipping behavior. */ public CSVFormat withIgnoreEmptyLines(final boolean ignoreEmptyLines) { return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape, ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, header, skipHeaderRecord); }
/** * Sets the record separator of the format to the specified String. * * @param recordSeparator * the record separator to use for output. * * @return A new CSVFormat that is equal to this but with the the specified output record separator */ public CSVFormat withRecordSeparator(final String recordSeparator) { return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape, ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, header, skipHeaderRecord); }