Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* ************************************************************************
  #
  #  DivConq
  #
  #  http://divconq.com/
  #
  #  Copyright:
  #    Copyright 2014 eTimeline, LLC. All rights reserved.
  #
 #  License:
 #    See the license.txt file in the project's top-level directory for details.
 #
 #  Authors:
 #    * Andy White
 #
 ************************************************************************ */

Author(s):
Thomas Davis (sunsetbrew)
Copyright:
Copyright (c) 2010, Thomas Davis
License:
http://opensource.org/licenses/mit-license.php MIT License
 
 package divconq.util;
 
 import java.io.Reader;
CSV4180Reader provides a simple way to import CSV values from a file. The reader extends BufferedReader for improved performance.
 
 public class CSVReader extends BufferedReader {

Create a buffering character-input stream that uses a default-sized input buffer.

Parameters:
in A Reader
 
 	public CSVReader(Reader in) {
 		super(in);
 	}

Create a buffering character-input stream that uses an input buffer of the specified size.

Parameters:
in A Reader
sz Input-buffer size
 
 	public CSVReader(Reader inint sz) {
 		super(insz);
 	}

Indicates if the last field read was at the end of the line.

Returns:
true if last field read was at the end of the line, false otherwise or if no fields have been read.
 
 	public boolean hasMoreFieldsOnLine() {
 		return this.;
 	}

Indicates if all the data from the reader has been read.

Returns:
true if all the data from the reader has been read.
 
 	public boolean isEOF() {
 		return this.;
 	}

Reads the current line's fields into an ArrayList. This is a convenience method.

Parameters:
fields container for the fields in the current row. It will be cleared.
Throws:
java.io.IOException on general I/O error
java.io.EOFException on end of file
 
 	public void readFields(ArrayList<Stringfieldsthrows IOException {
 		fields.clear();
 		if (this.) {
 			throw new EOFException();
 		}
 		do {
 			fields.add(readField());
 		} while (this.);
	}

Reads the next field from the input removing quotes as necessary.

Returns:
next field
Throws:
java.io.IOException If an I/O error occurs, may be an EOFException on end of input.
	public String readField() throws IOException {
		int c;
		final int UNQUOTED = 0;
		final int QUOTED = 1;
		final int QUOTEDPLUS = 2;
		int state = UNQUOTED;
		if (this.) {
			throw new EOFException();
		}
		while ((c = this.read()) >= 0) {
			if (state == QUOTEDPLUS) {
				switch (c) {
				case '"':
					this..append('"');
					state = QUOTED;
					continue;
				default:
					state = UNQUOTED;
					break;
				}
			}
			if (state == QUOTED) {
				switch (c) {
				default:
					this..append((charc);
					continue;
				case '"':
					state = QUOTEDPLUS;
					continue;
				}
			}
			// (state == UNQUOTED)
			switch (c) {
			case '"':
				state = QUOTED;
				continue;
			case '\r':
				continue;
			case '\n':
			case ',':
				this. = (c != '\n');
				return this..toString();
			default:
				this..append((charc);
				continue;
			}
		}
		this. = true;
		this. = false;
		return this..toString();
	}

Ignore:
	private boolean moreFieldsOnLine = true;

Ignore:
	private boolean eof = false;

Ignore:
	private final StringBuffer buffer = new StringBuffer();
New to GrepCode? Check out our FAQ X