Package no.priv.garshol.duke.utils

Examples of no.priv.garshol.duke.utils.CSVReader


  public void setMappingFile(String filename) {
    mapping = new HashMap();
   
    // FIXME: character encoding?
    try {
      CSVReader csv = new CSVReader(new FileReader(filename));

      String[] row = csv.next();
      while (row != null) {
        mapping.put(row[0], row[1]);
        row = csv.next();
      }
     
      csv.close();
    } catch (IOException e) {
      throw new DukeException("Error loading mapping file " + filename, e);
    }
  } 
View Full Code Here


          in = new FileReader(file);
        else
          in = new InputStreamReader(new FileInputStream(file), encoding);
      }

      CSVReader csv = new CSVReader(in);
      if (separator != 0)
        csv.setSeparator(separator);
      return new CSVRecordIterator(csv);
    } catch (FileNotFoundException e) {
      throw new DukeConfigException("Couldn't find CSV file '" + file + "'");
    } catch (IOException e) {
      throw new DukeException(e);
View Full Code Here

public class CSVReaderTest {

  @Test
  public void testEmpty() throws IOException {
    String data = "";
    CSVReader reader = new CSVReader(new StringReader(data));
    compareRows("couldn't read empty file correctly", null, reader.next());
  }
View Full Code Here

  }

  @Test
  public void testOneRow() throws IOException {
    String data = "a,b,c";
    CSVReader reader = new CSVReader(new StringReader(data));

    String[] row = reader.next();
    compareRows("first row read incorrectly", new String[]{"a", "b", "c"},
                row);
    compareRows("reading not terminated correctly", null, reader.next());
  }
View Full Code Here

  }

  @Test
  public void testOneRowWithLineBreak() throws IOException {
    String data = "a,b,c\n";
    CSVReader reader = new CSVReader(new StringReader(data));

    String[] row = reader.next();
    compareRows("first row read incorrectly", new String[]{"a", "b", "c"},
                row);
    compareRows("reading not terminated correctly", null, reader.next());
  }
View Full Code Here

  }

  @Test
  public void testTwoRows() throws IOException {
    String data = "a,b,c\nd,e,f";
    CSVReader reader = new CSVReader(new StringReader(data));

    String[] row = reader.next();
    compareRows("first row read incorrectly", new String[]{"a", "b", "c"},
                row);
    row = reader.next();
    compareRows("second row read incorrectly", new String[]{"d", "e", "f"},
                row);
    compareRows("reading not terminated correctly", null, reader.next());
  }
View Full Code Here

  }

  @Test
  public void testOneRowQuotes() throws IOException {
    String data = "\"a\",\"b\",\"c\"";
    CSVReader reader = new CSVReader(new StringReader(data));

    String[] row = reader.next();
    compareRows("first row read incorrectly", new String[]{"a", "b", "c"},
                row);
    compareRows("reading not terminated correctly", null, reader.next());
  }
View Full Code Here

  }

  @Test
  public void testOneRowInconsistentQuotes() throws IOException {
    String data = "\"a\",b,\"c\"";
    CSVReader reader = new CSVReader(new StringReader(data));

    String[] row = reader.next();
    compareRows("first row read incorrectly", new String[]{"a", "b", "c"},
                row);
    compareRows("reading not terminated correctly", null, reader.next());
  }
View Full Code Here

  }

  @Test
  public void testTwoRowsQuotes() throws IOException {
    String data = "\"a\",\"b\",\"c\"\n\"d\",\"e\",\"f\"";
    CSVReader reader = new CSVReader(new StringReader(data));

    String[] row = reader.next();
    compareRows("first row read incorrectly", new String[]{"a", "b", "c"},
                row);
    row = reader.next();
    compareRows("second row read incorrectly", new String[]{"d", "e", "f"},
                row);
    compareRows("reading not terminated correctly", null, reader.next());
  }
View Full Code Here

  }

  @Test
  public void testOneRowQuotesLineBreak() throws IOException {
    String data = "\"a\",\"b\nc\",\"d\"";
    CSVReader reader = new CSVReader(new StringReader(data));

    String[] row = reader.next();
    compareRows("first row read incorrectly", new String[]{"a", "b\nc", "d"},
                row);
    compareRows("reading not terminated correctly", null, reader.next());
  }
View Full Code Here

TOP

Related Classes of no.priv.garshol.duke.utils.CSVReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.