Examples of CSVParse


Examples of com.Ostermiller.util.CSVParse

    int numRows = 0;
    int rowCountShowProgress = 0;
    int numFields = -1;
    try {
      FileInputStream in = new FileInputStream(csvFile);
      CSVParse shredderRowCount = getParser(in);
      while ((line = shredderRowCount.getLine()) != null) {
        if (numFields == -1) {
          numFields = line.length;
        } else {
          if (numFields != line.length) {
            resultMessage.append("Failed row=" + (numRows + 1) + " : All rows must have the same number of Fields" + "\n");
            workDialog.dispose();
            in.close();
            return resultMessage;
          }
        }
        numRows++;
      }
      in.close();
      if (numRows == 0) {
        resultMessage.append("The file is empty");
        workDialog.dispose();
        return resultMessage;
      }
      FileInputStream in2 = new FileInputStream(csvFile);
      CSVParse shredder = getParser(in2);
      line = shredder.getLine();
      //add two extra fields for the isDebt/Amount conversion
      String[] expandedLine = new String[line.length + 2];
      for (int k = 0; k < line.length; k++) {
        expandedLine[k] = line[k];
      }
      expandedLine[line.length] = "";
      expandedLine[line.length + 1] = "";
      v.add(expandedLine);
      try {
        act_id = ((Integer) (formatNumPane.numPanels[formatNumPane.SHOW_INTEGER]
            .parse(line[tableMatchedIndexes[INDEX_ACT_ID]]))).intValue();
      } catch (Exception e) {
        resultMessage.append("Failed row=" + rowCount + " : Cannot continue processing this file.  Bad transaction number found="
             + line[tableMatchedIndexes[tableMatchedIndexes[INDEX_ACT_ID]]] + "\n");
        workDialog.dispose();
        in2.close();
        return resultMessage;
      }
      do {
        rowCount++;
        rowCountShowProgress++;
        if (rowCountShowProgress >= 10) {
          workDialog.SetProgress(rowCount * 100 / numRows);
          rowCountShowProgress = 0;
        }
        line = shredder.getLine();
        if (line != null) {
          try {
            act_id_test = ((Integer) (formatNumPane.numPanels[formatNumPane.SHOW_INTEGER]
                .parse(line[tableMatchedIndexes[INDEX_ACT_ID]]))).intValue();
          } catch (Exception e) {
View Full Code Here

Examples of com.Ostermiller.util.CSVParse

    int numRows = 0;
    int numFields = -1;
    int rowCountShowProgress = 0;
    try {
      FileInputStream in = new FileInputStream(csvFile);
      CSVParse shredderRowCount = getParser(in);
      while ((t = shredderRowCount.getLine()) != null) {
        if (numFields == -1) {
          numFields = t.length;
        } else {
          if (numFields != t.length) {
            resultMessage.append("Failed row=" + (numRows + 1) + " : All rows must have the same number of Fields" + "\n");
            workDialog.dispose();
            in.close();
            ErrorDialog showErrors = new ErrorDialog(resultMessage, false, null);
            return;
          }
        }
        numRows++;
      }
      in.close();
      FileInputStream in2 = new FileInputStream(csvFile);
      CSVParse shredder = getParser(in2);
      while ((t = shredder.getLine()) != null) {
        rowCount++;
        rowCountShowProgress++;
        if (rowCountShowProgress >= 10) {
          workDialog.SetProgress(rowCount * 100 / numRows);
          rowCountShowProgress = 0;
View Full Code Here

Examples of com.Ostermiller.util.CSVParse

    int rowCount = 1;
    int oldSize = numUsedListRows;
    numUsedListRows = 0;
    try {
      FileInputStream in = new FileInputStream(csvFile);
      CSVParse shredder = getParser(in);
      if (shredder == null) {
        in.close();
        return false;
      }
      while ((t = shredder.getLine()) != null && rowCount <= showLine) {
        if (rowCount == showLine) {
          for (int i = 0; i < t.length; i++) {
            if (i < t.length) {
//Log.log(Log.DEBUG,this,"i=" + i + " ; t[i]=" + t[i]);
              listFields[numUsedListRows].delete(0, listFields[numUsedListRows].length()).append(t[i]);
View Full Code Here

Examples of com.Ostermiller.util.CSVParse

    int numRows = 0;
    int rowCountShowProgress = 0;
    int numFields = -1;
    try {
      FileInputStream in = new FileInputStream(csvFile);
      CSVParse shredderRowCount = getParser(in);
      while ((t = shredderRowCount.getLine()) != null) {
        if (numFields == -1) {
          numFields = t.length;
        } else {
          if (numFields != t.length) {
            resultMessage.append("Failed row=" + (numRows + 1) + " : All rows must have the same number of Fields" + "\n");
            workDialog.dispose();
            in.close();
            return resultMessage;
          }
        }
        numRows++;
      }
      in.close();
      FileInputStream in2 = new FileInputStream(csvFile);
      CSVParse shredder = getParser(in2);
      while ((t = shredder.getLine()) != null) {
        rowCount++;
        rowCountShowProgress++;
        if (rowCountShowProgress >= 10) {
          workDialog.SetProgress(rowCount * 100 / numRows);
          rowCountShowProgress = 0;
        }
        errorMess = IsRowUpdateable(t, rowCount, dc.con);
        if (errorMess.length() != 0) {
          resultMessage.append(errorMess + "\n");
        }
        for (int i = 0; i < tableMatchedIndexes.length; i++) {
          if (tableMatchedIndexes[i] != -1) {
            if (sqlUniqueTest[i].length() != 0) {
              //test uniqness locally in the file
              FileInputStream in3 = new FileInputStream(csvFile);
              CSVParse shredderSearch = getParser(in3);
              String[] t2;
              int rowCount2 = 0;
              while ((t2 = shredderSearch.getLine()) != null) {
                rowCount2++;
                if (t2[tableMatchedIndexes[i]].compareTo(t[tableMatchedIndexes[i]]) == 0 && rowCount != rowCount2) {
                  resultMessage.append("Failed row=" + rowCount + " :Field=" + importFields[i] +
                      " : Not allowed to have this field identical to same field in row=" + rowCount2 + "\n");
                }
View Full Code Here

Examples of com.Ostermiller.util.CSVParse

   *
   * @param  in  Description of the Parameter
   * @return     The parser value
   */
  protected CSVParse getParser(FileInputStream in) {
    CSVParse shredder;
    isExcel = options.fileTypeButton[1].isSelected();
    if (options.delimiterButton[0].isSelected()) {
      delimiter = ',';
    } else {
      delimiter = ';';
    }
    try {
      if (isExcel) {
        shredder = new ExcelCSVParser(new StraightStreamReader(in));
      } else {
        CSVParser standardParser = new CSVParser(new StraightStreamReader(in));
        standardParser.setCommentStart("#!");
        standardParser.setEscapes("nrtf", "\n\r\t\f");
        shredder = standardParser;
      }
      shredder.changeDelimiter(delimiter);
    } catch (Exception e) {
      return null;
    }
    return shredder;
  }//}}}
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.