All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.TKnudsen.ComplexDataObject.model.io.parsers.AbstractIDObjectFileParser Maven / Gradle / Ivy

Go to download

A library that models real-world objects in Java, referred to as ComplexDataObjects. Other features: IO and preprocessing of ComplexDataObjects.

There is a newer version: 0.2.13
Show newest version
package com.github.TKnudsen.ComplexDataObject.model.io.parsers;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.github.TKnudsen.ComplexDataObject.data.interfaces.IDObject;
import com.github.TKnudsen.ComplexDataObject.data.interfaces.ISelfDescription;

public abstract class AbstractIDObjectFileParser implements IDObjectParser, ISelfDescription {

	protected String tokenizerToken;
	protected String missingValueIdentifier;

	public AbstractIDObjectFileParser(String tokenizerToken, String missingValueIdentifier) {
		this.tokenizerToken = tokenizerToken;
		this.missingValueIdentifier = missingValueIdentifier;
	}

	/**
	 * reads a given file and returns a List of Strings each representing a line
	 * of the file.
	 * 
	 * @param file
	 * @return
	 * @throws IOException
	 */
	protected List readLines(String file) throws IOException, FileNotFoundException {
		List rows = new ArrayList();
		File fileObject = new File(file);
		BufferedReader reader = null;

		try {
			reader = new BufferedReader(new FileReader(fileObject));
		} catch (FileNotFoundException ex) {
			throw new FileNotFoundException("AbstractIDObjectFileParser.loadRows: file not found: " + file);
		}

		String line = reader.readLine();
		while (line != null) {
			rows.add(line);
			line = reader.readLine();
		}

		reader.close();

		return rows;
	}

	public String getTokenizerToken() {
		return tokenizerToken;
	}

	public void setTokenizerToken(String tokenizerToken) {
		this.tokenizerToken = tokenizerToken;
	}

	public String getMissingValueIdentifier() {
		return missingValueIdentifier;
	}

	public void setMissingValueIdentifier(String missingValueIdentifier) {
		this.missingValueIdentifier = missingValueIdentifier;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy