- // -1 = no bkeys
- public static String toString(Contact contact, int startingBKey) {
- StringBuilder builder = new StringBuilder();
-
- builder.append("BEGIN:VCARD");
- builder.append("\r\n");
- builder.append("VERSION:2.1");
- builder.append("\r\n");
- for (Data data : contact.getContent()) {
- if (data.getGroup() != null && !data.getGroup().trim().equals("")) {
- builder.append(data.getGroup().trim());
- builder.append('.');
+ /**
+ * Write the given {@link Card} in the {@link Appendable}.
+ *
+ * @param writer
+ * the {@link Appendable}
+ * @param card
+ * the {@link Card} to write
+ *
+ * @throws IOException
+ * in case of IO error
+ */
+ public static void write(Appendable writer, Card card) throws IOException {
+ for (Contact contact : card) {
+ write(writer, contact, -1);
+ }
+ }
+
+ /**
+ * Write the given {@link Contact} in the {@link Appendable}.
+ *
+ * @param writer
+ * the {@link Appendable}
+ * @param contact
+ * the {@link Contact} to write
+ * @param startingBKey
+ * the starting BKey number (all the other will follow) or -1 for
+ * no BKey
+ *
+ * @throws IOException
+ * in case of IO error
+ */
+ public static void write(Appendable writer, Contact contact,
+ int startingBKey) throws IOException {
+
+ writer.append("BEGIN:VCARD\r\n");
+ writer.append("VERSION:2.1\r\n");
+ for (Data data : contact) {
+ write(writer, data);
+ }
+ writer.append("END:VCARD\r\n");
+ }
+
+ /**
+ * Write the given {@link Data} in the {@link Appendable}.
+ *
+ * @param writer
+ * the {@link Appendable}
+ * @param data
+ * the {@link Data} to write
+ *
+ * @throws IOException
+ * in case of IO error
+ */
+ public static void write(Appendable writer, Data data) throws IOException {
+ StringBuilder dataBuilder = new StringBuilder();
+ if (data.getGroup() != null && !data.getGroup().trim().equals("")) {
+ dataBuilder.append(data.getGroup().trim());
+ dataBuilder.append('.');
+ }
+ dataBuilder.append(data.getName());
+ for (TypeInfo type : data) {
+ dataBuilder.append(';');
+ dataBuilder.append(type.getName());
+ if (type.getValue() != null && !type.getValue().trim().equals("")) {
+ dataBuilder.append('=');
+ dataBuilder.append(type.getRawValue());