package com.youza.test;
import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.io.*;
import info.ineighborhood.cardme.engine.VCardEngine;
import info.ineighborhood.cardme.io.VCardWriter;
import info.ineighborhood.cardme.util.Util;
import info.ineighborhood.cardme.vcard.EncodingType;
import info.ineighborhood.cardme.vcard.VCard;
import info.ineighborhood.cardme.vcard.types.PhotoType;
import info.ineighborhood.cardme.vcard.types.media.ImageMediaType;
public class CreateVCard {
/**
* @param args
*/
private static VCardEngine vcardEngine = null;
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
File vcard_file = new File("petrea.vcf");
System.out.println(vcard_file);
vcardEngine = new VCardEngine();
VCard vcard = vcardEngine.parse(vcard_file);
PhotoType photo = new PhotoType();
photo.setCompression(false);
photo.setEncodingType(EncodingType.BINARY);
photo.setImageMediaType(ImageMediaType.JPEG);
byte[] tuxPicture1 = Util.getFileAsBytes(new File(
"Hydrangeas.jpg"));
photo.setPhoto(tuxPicture1);
vcard.addPhoto(photo);
saveToFile( "petreb.vcf" , vcard);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void saveToFile( String fileName , VCard vcard) {
Writer output = null;
File file = new File(fileName);
try {
output = new BufferedWriter(new FileWriter(file));
VCardWriter writer = new VCardWriter();
writer.setVCard(vcard);
output.write(writer.buildVCardString());
output.flush();
output.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}