Beispiel #1
0
 @Override
 public void store() throws MappableException, UserException {
   if (draftEntries != null) {
     entries = new CSVEntryMap[draftEntries.size()];
     int i = 0;
     for (CSVEntryMap ce : draftEntries) {
       entries[i++] = ce;
     }
     // entries = (CSVEntryMap[]) draftEntries.toArray();
   }
   if (update) {
     try {
       // Write CSV.
       if (entries != null) {
         FileWriter writer = new FileWriter(fileName);
         for (int i = 0; i < entries.length; i++) {
           CSVEntryMap e = entries[i];
           for (int j = 0; j < e.entries.length; j++) {
             writer.write(e.getEntry(new Integer(j)));
             if (j < (e.entries.length - 1)) writer.write(separator);
           }
           if (i < (entries.length - 1)) writer.write("\n");
         }
         writer.close();
       }
     } catch (IOException ioe) {
       throw new UserException(-1, ioe.getMessage());
     }
   }
 }
Beispiel #2
0
 public int getEntryFieldCount() {
   int result = -1;
   if (entries != null && entries.length > 0) {
     CSVEntryMap e = entries[0];
     result = e.getEntrySize();
   }
   return result;
 }
Beispiel #3
0
 private void parseLineDefault(String line, List<CSVEntryMap> entryList) {
   StringTokenizer tokens = new StringTokenizer(line, separator);
   CSVEntryMap csvEntry = new CSVEntryMap();
   csvEntry.entries = new String[tokens.countTokens()];
   int index = 0;
   while (tokens.hasMoreTokens()) {
     csvEntry.entries[index++] = tokens.nextToken();
   }
   entryList.add(csvEntry);
 }
Beispiel #4
0
  private void parseLineWithEmpty(String line, List<CSVEntryMap> entryList) {
    String sep = separator;
    if (sep == null) {
      sep = " ";
    }
    if (sep.length() > 1) {
      throw new IllegalArgumentException(
          "Can not include empty when separator is > 1 char.Sorry, feel free to implement.");
    }
    char sepChar = sep.charAt(0);
    int startindex = 0;
    List<String> currentLine = new ArrayList<String>();
    for (int i = 0; i < line.length(); i++) {
      char c = line.charAt(i);
      if (c == sepChar) {
        if (startindex == -1) {
          currentLine.add(null);
          startindex = -1;
        } else {
          if (startindex == i) {
            currentLine.add(null);
          } else {
            String ss = line.substring(startindex, i);
            currentLine.add(ss);
          }
          startindex = i + 1;
        }
      }
    }

    // add the last item on the line, not ended by the separator
    if (startindex == line.length()) {
      currentLine.add(null);
    } else {
      String ss = line.substring(startindex, line.length());
      currentLine.add(ss);
    }
    CSVEntryMap csvEntry = new CSVEntryMap();
    csvEntry.entries = new String[currentLine.size()];
    for (int i = 0; i < currentLine.size(); i++) {
      csvEntry.entries[i] = currentLine.get(i);
    }
    entryList.add(csvEntry);
  }
Beispiel #5
0
  public static void main(String[] args) throws Exception {
    Mappable csv = new CSVMap();
    ((CSVMap) csv).setSeparator(";");
    ((CSVMap) csv).setIncludeEmpty(true);
    ((CSVMap) csv).setSkipFirstRow(false);

    Binary b = new Binary(new File("C:/Temp/LedenLIJST-vertrouwelijktest.csv"));
    ((CSVMap) csv).setFileContent(b);
    Mappable[] all = ((CSVMap) csv).getEntries();
    for (int i = 0; i < all.length; i++) {
      CSVEntryMap entryMap = ((CSVEntryMap) all[i]);
      logger.info(
          "a = >"
              + entryMap.getEntry(new Integer(0))
              + "< - >"
              + entryMap.getEntry(new Integer(1))
              + "< - >"
              + entryMap.getEntry(new Integer(2))
              + "< - >"
              + entryMap.getEntry(new Integer(3))
              + "< - >"
              + entryMap.getEntry(new Integer(4))
              + "< - >"
              + entryMap.getEntry(new Integer(5))
              + "< - >"
              + entryMap.getEntry(new Integer(6))
              + "< - >"
              + entryMap.getEntry(new Integer(7))
              + "< - >"
              + entryMap.getEntry(new Integer(8))
              + "< - >"
              + entryMap.getEntry(new Integer(9))
              + "< - >"
              + entryMap.getEntry(new Integer(10))
              + "< - >"
              + entryMap.getEntry(new Integer(11))
              + "<");
    }
  }