0

Is there a way how to read multiple vcards from only one file using cardme? According to examples show here it seems that it's not possible.

robodasha
  • 286
  • 6
  • 21
  • Updated the cardme wiki site to include an example of parsing a file containing multiple vcards inside it. – george_h Jun 26 '12 at 15:21

3 Answers3

2

There is no build in method to do this. You can iterate the file line by line until END:VCARD and then use the method VCardEngine.parse(String) to read each VCard one by one.

Something like this may work:

BufferedReader buffer = new BufferedReader(new FileReader("allcards.txt"));

VCardEngine engine = new VCardEngine();
StringBuilder builder = new StringBuilder();
List<VCard> vcards = new ArrayList<VCard>();

String line;
while ((line = buffer.readLine()) != null) {
    builder.append(line);

    if (line.contains("END:VCARD")) {
        VCard vcard = engine.parse(builder.toString());
        vcards.add(vcard);
        builder = new StringBuilder();
    }
}
jordeu
  • 6,711
  • 1
  • 19
  • 19
2

I don't know if the method parseMultiple() is newer than this post, but this is actually possible with the versión I'm using (v0.3.3).

Here's a method that iterates over a Files array, in which each file may have multiple vcards, and adds all the read VCards to a List.

public List<VCard> importVCards() {
    List<VCard> vcards = new ArrayList<VCard>();
    vcardFiles = getFiles();        
    for(int i = 0; i < vcardFiles.length; i++){
        try {               
            vcards.addAll(vcardEngine.parseMultiple(vcardFiles[i]));
        }
        catch(IOException ioe) {
            System.err.println("Could not read vcard file:
                "+vcardFiles[i].getAbsolutePath());
            ioe.printStackTrace();
        }
    }

    return vcards;
} 

cardme can be found here:https://github.com/george-haddad/cardme

SiHa
  • 7,830
  • 13
  • 34
  • 43
hectorg87
  • 753
  • 1
  • 7
  • 24
0

Cardme version 0.3.3 has been released which supports parsing multiple vcards from 1 file. You can download it here http://sourceforge.net/projects/cardme/files/Cardme/Card%20Me%20Version%200.3.3/

george_h
  • 1,562
  • 2
  • 19
  • 37