1 package at.ac.tuwien.lsdc.util;
4 import java.io.FileReader;
5 import java.io.IOException;
6 import java.util.LinkedList;
9 import at.ac.tuwien.lsdc.types.Application;
10 import au.com.bytecode.opencsv.CSVReader;
11 import au.com.bytecode.opencsv.CSVWriter;
13 public class CSVParser {
15 private static int count = 0;
17 public static LinkedList<Application> parseFile(File csvFile)
19 CSVReader reader = new CSVReader(new FileReader(csvFile), ';',
20 CSVWriter.NO_QUOTE_CHARACTER);
21 List<String[]> file = reader.readAll();
22 LinkedList<Application> apps = new LinkedList<Application>();
23 // start at 1 to ignore header
24 for (int i = 1; i < file.size(); i++) {
25 String[] line = file.get(i);
26 if (line.length != 5) {
28 throw new IOException("CSVParser: Not right amount of elements in line " + i + 1);
31 Application a = parseLine(line);
33 } catch (NumberFormatException e) {
35 throw new IOException("Couldn't parse line");
43 private static Application parseLine(String[] appStr)
44 throws NumberFormatException {
47 long timestamp = Long.parseLong(appStr[0]);
48 int size = Integer.parseInt(appStr[1]);
49 int ram = Integer.parseInt(appStr[2]);
50 int cpu = Integer.parseInt(appStr[3]);
51 int duration = Integer.parseInt(appStr[4]);
52 Application app = new Application(id, timestamp, size, ram, cpu,