Package com.csvreader

Examples of com.csvreader.CsvReader$RawRecordBuffer


  public void testRightNumberOfFields5() throws IOException {
    String line = "2450001.5\t10.0\n";

    try {
      CsvReader reader = new CsvReader(new StringReader(line));
      reader.setDelimiter('\t');
      assertTrue(reader.readRecord());
      ObservationFieldSplitter splitter = new ObservationFieldSplitter(
          reader, 2, 5);
      String[] fields = splitter.getFields();
      assertEquals(5, fields.length);
    } catch (ObservationValidationError e) {
View Full Code Here


  public void testRightNumberOfFields5AllPresent() throws IOException {
    String line = "2450001.5\t10.0\t0.1\tDJB\tD\n";

    try {
      CsvReader reader = new CsvReader(new StringReader(line));
      reader.setDelimiter('\t');
      assertTrue(reader.readRecord());
      ObservationFieldSplitter splitter = new ObservationFieldSplitter(
          reader, 5, 5);
      String[] fields = splitter.getFields();
      assertEquals(5, fields.length);
    } catch (ObservationValidationError e) {
View Full Code Here

  public void testRightNumberOfFields5NoObsCode() throws IOException {
    String line = "2450001.5\t10.0\t0.1\t\tD\n";

    try {
      CsvReader reader = new CsvReader(new StringReader(line));
      reader.setDelimiter('\t');
      assertTrue(reader.readRecord());
      ObservationFieldSplitter splitter = new ObservationFieldSplitter(
          reader, 5, 5);
      String[] fields = splitter.getFields();
      assertEquals(5, fields.length);
    } catch (ObservationValidationError e) {
View Full Code Here

  public void testTabDelimitedFieldsWithSingleQuotedField()
      throws IOException {
    String line = "2456362.04142\t8.2\t\t\tVis.\tBDJB\tBU\t82\t76\t10 star\t\"\"\"8\\\"\" SCT, 24.5mm eyepiece\"\"\"\t\t\tZ\t\t\t\tR CAR\t\tSTD\t\t\t";

    try {
      CsvReader reader = new CsvReader(new StringReader(line));
      reader.setDelimiter('\t');
      assertTrue(reader.readRecord());
      ObservationFieldSplitter splitter = new ObservationFieldSplitter(
          reader, 23, 23);
      String[] fields = splitter.getFields();
      assertEquals(23, fields.length);
    } catch (ObservationValidationError e) {
View Full Code Here

  public void testCommaDelimitedFieldsWithSingleQuotedField()
      throws IOException {
    String line = "2456362.04142,8.2,,,Vis.,BDJB,BU,82,76,10 star,\"\"\"8\\\"\" SCT, 24.5mm eyepiece\"\"\",,,Z,,,,R CAR,,STD,,,";

    try {
      CsvReader reader = new CsvReader(new StringReader(line));
      reader.setDelimiter(',');
      assertTrue(reader.readRecord());
      ObservationFieldSplitter splitter = new ObservationFieldSplitter(
          reader, 23, 23);
      String[] fields = splitter.getFields();
      assertEquals(23, fields.length);
    } catch (ObservationValidationError e) {
View Full Code Here

        || ObservationSourceAnalyser.COMMA_DELIM.equals(delimiter) || ObservationSourceAnalyser.SPACE_DELIM
        .equals(delimiter));

    CommonTextFormatValidator validator = null;

    CsvReader lineReader = new CsvReader(obsSource);
    lineReader.setDelimiter(delimiter.charAt(0));

    if (NewStarType.NEW_STAR_FROM_SIMPLE_FILE.equals(newStarType)) {
      validator = new SimpleTextFormatValidator(lineReader, newStarType
          .getMinFields(), newStarType.getMaxFields(), newStarType
          .getFieldInfoSource());
View Full Code Here

  /* (non-Javadoc)
   * @see net.sourceforge.squirrel_sql.plugins.dataimport.importer.IFileImporter#getPreview(int)
   */
  public String[][] getPreview(int noOfLines) throws IOException {
    CsvReader csvReader = new CsvReader(new InputStreamReader(new FileInputStream(importFile), settings.getImportCharset()), settings.getSeperator());
    String[][] data = new String[noOfLines][];
   
    int row = 0;
    int columns = -1;
    while (csvReader.readRecord() && row < noOfLines) {
      if (columns == -1) {
        columns = csvReader.getColumnCount();
      }
      data[row] = new String[columns];
      for (int i = 0; i < columns; i++) {
        data[row][i] = csvReader.get(i);
      }
      row++;
    }
    csvReader.close();
   
    String[][] outData = new String[row][];
    for (int i = 0; i < row; i++) {
      outData[i] = data[i];
    }
View Full Code Here

   */
  public boolean reset() throws IOException {
    if (reader != null) {
      reader.close();
    }
    reader = new CsvReader(new InputStreamReader(new FileInputStream(importFile), settings.getImportCharset()), settings.getSeperator());
    return true;
  }
View Full Code Here

     * @param reader
     * @return
     */
    protected CsvReader initializeReader (Reader reader)
    {
        CsvReader csvReader = new CsvReader(reader);

        char customDelimiter = getCustomDelimiter();
        csvReader.setDelimiter(customDelimiter);

        char commentChar = getCommentChar();
        if (commentChar != Character.UNASSIGNED) {
            csvReader.setComment(commentChar);
            // prevent loss of comment in csv source file
            csvReader.setUseComments(false);
        }

        csvReader.setTextQualifier(getTextQualifier());
        csvReader.setUseTextQualifier(true);

        return csvReader;
    }
View Full Code Here

     */
    protected void readLines(String fileText) {
        rows.clear();

        try {
            CsvReader csvReader = initializeReader(new StringReader(fileText));
            // case when the first line is the encoding
            if (!displayFirstLine) {
                csvReader.skipLine();
            }

            boolean setHeader = false;
            while (csvReader.readRecord()) {
                String[] rowValues = csvReader.getValues();
                CSVRow csvRow = new CSVRow(rowValues, this);
                if (!rowValues[0].startsWith(String.valueOf(getCommentChar()))) {
                    if (isFirstLineHeader() && !setHeader) {
                        setHeader = true;
                        csvRow.setHeader(true);
                        populateHeaders(rowValues);
                    }
                }
                else {
                    csvRow.setCommentLine(true);
                }
                rows.add(csvRow);

                if (rowValues.length > nbOfColumns) {
                    nbOfColumns = rowValues.length;
                }
            }

            if (!isFirstLineHeader()) {
                populateHeaders(null);
            }

            csvReader.close();
        } catch (Exception e) {
            System.out.println("exception in readLines " + e);
            e.printStackTrace();
        }
    }
View Full Code Here

TOP

Related Classes of com.csvreader.CsvReader$RawRecordBuffer

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.