VCardBean extends AbstractEntity { public void write(Writer w, String charset) { BEANS.get(ICalVCardHelper.class).write(this, w, charset); }  static VCardBean parse(Reader r, String charset); void write(Writer w, String charset); byte[] toBytes(String charset);  }
@Test public void testWrite() { VCardBean vcard = BEANS.get(VCardBean.class); ICalVCardHelper helper = BEANS.get(ICalVCardHelper.class); vcard.addProperty(VCardProperties.PROP_BEGIN_VCARD); vcard.addProperty(VCardProperties.PROP_VERSION_3_0); vcard.addProperty(new Property(VCardProperties.PROP_NAME_PRODID, "PRODID")); vcard.addProperty(new Property(VCardProperties.PROP_NAME_FN, "John Doe")); vcard.addProperty(new Property(VCardProperties.PROP_NAME_N, helper.composeStructuredValueFromSingleValues("Doe", "John", "Hannes", "Dr.", null))); vcard.addProperty(new Property(VCardProperties.PROP_NAME_TEL, Arrays.asList(new PropertyParameter(VCardProperties.PARAM_NAME_TYPE, VCardProperties.PARAM_VALUE_VOICE, VCardProperties.PARAM_VALUE_WORK)), "0998887766")); vcard.addProperty(new Property(VCardProperties.PROP_NAME_TITLE, "Software Engineer")); vcard.addProperty(new Property(VCardProperties.PROP_NAME_EMAIL, Arrays.asList(new PropertyParameter(VCardProperties.PARAM_NAME_TYPE, VCardProperties.PARAM_VALUE_WORK)), "john.doe@email.com")); vcard.addProperty(new Property(VCardProperties.PROP_NAME_ORG, helper.composeStructuredValueFromSingleValues("Doe Corporation"))); vcard.addProperty(new Property(VCardProperties.PROP_NAME_ADR, Arrays.asList(new PropertyParameter(VCardProperties.PARAM_NAME_TYPE, VCardProperties.PARAM_VALUE_HOME)), helper.composeStructuredValueFromSingleValues(null, null, "Bahnhofweg", "Zurich", null, "8000", "Switzerland"))); vcard.addProperty(VCardProperties.PROP_END_VCARD); StringWriter w = new StringWriter(); vcard.write(w, "utf-8"); String writtenVCard = w.toString(); assertEquals("BEGIN:VCARD\r\n" + "VERSION:3.0\r\n" + "PRODID;CHARSET=utf-8:PRODID\r\n" + "FN;CHARSET=utf-8:John Doe\r\n" + "N;CHARSET=utf-8:Doe;John;Hannes;Dr.;\r\n" + "TEL;CHARSET=utf-8;TYPE=VOICE,WORK:0998887766\r\n" + "TITLE;CHARSET=utf-8:Software Engineer\r\n" + "EMAIL;CHARSET=utf-8;TYPE=WORK:john.doe@email.com\r\n" + "ORG;CHARSET=utf-8:Doe Corporation\r\n" + "ADR;CHARSET=utf-8;TYPE=HOME:;;Bahnhofweg;Zurich;;8000;Switzerland\r\n" + "END:VCARD\r\n" + "", writtenVCard); }