X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Fparsers%2FAbookParser.java;h=fc4df3613f2af8e34947712cdcb0860217b9d168;hb=d5260eeb873fcf2ef9855dedcd9e2a3a3a990582;hp=344ae705401652905fe49563fa5fac4110be9f41;hpb=cf77cb3542f2aefbebdb9aa00b358dbeb4489a73;p=jvcard.git diff --git a/src/be/nikiroo/jvcard/parsers/AbookParser.java b/src/be/nikiroo/jvcard/parsers/AbookParser.java index 344ae70..fc4df36 100644 --- a/src/be/nikiroo/jvcard/parsers/AbookParser.java +++ b/src/be/nikiroo/jvcard/parsers/AbookParser.java @@ -1,5 +1,6 @@ package be.nikiroo.jvcard.parsers; +import java.io.IOException; import java.util.Arrays; import java.util.LinkedList; import java.util.List; @@ -9,7 +10,17 @@ import be.nikiroo.jvcard.Contact; import be.nikiroo.jvcard.Data; public class AbookParser { - public static List parse(List lines) { + /** + * Load the given data from under the given {@link Format}. + * + * @param lines + * the input to load from + * @param format + * the {@link Format} to load as + * + * @return the list of elements + */ + public static List parseContact(List lines) { List contacts = new LinkedList(); for (String line : lines) { @@ -47,11 +58,12 @@ public class AbookParser { * * @param startingBKey * the starting BKey number (all the other will follow) or -1 for - * no BKey + * no BKey (it is actually not used in this mode) * * @return the {@link String} representation */ - public static List toStrings(Contact contact, int startingBKey) { + public static List toStrings(Contact contact, + @SuppressWarnings("unused") int startingBKey) { // BKey is not used in pine mode StringBuilder builder = new StringBuilder(); @@ -122,4 +134,44 @@ public class AbookParser { return lines; } + + /** + * 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 { + for (String s : toStrings(contact, startingBKey)) { + writer.append(s); + writer.append('\n'); + } + } + + /** + * 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 (String s : toStrings(card)) { + writer.append(s); + writer.append('\n'); + } + } }