- stop = Math.min(stop, dataBuilder.length());
- if (continuation) {
- lines.add(' ' + dataBuilder.substring(0, stop));
- } else {
- lines.add(dataBuilder.substring(0, stop));
- }
- dataBuilder.delete(0, stop);
+ index = Math.min(index, dataBuilder.length());
+ if (previous > 0)
+ writer.append(' ');
+ writer.append(dataBuilder, previous, index);
+ writer.append("\r\n");
+ }
+ }
+
+ /**
+ * Clone the given {@link Card} by exporting then importing it again in VCF.
+ *
+ * @param c
+ * the {@link Card} to clone
+ *
+ * @return the clone {@link Contact}
+ */
+ public static Card clone(Card c) {
+ try {
+ File tmp = File.createTempFile("clone", ".vcf");
+ c.saveAs(tmp, Format.VCard21);
+
+ Card clone = new Card(tmp, Format.VCard21);
+ clone.unlink();
+ tmp.delete();
+
+ return clone;
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+ /**
+ * Clone the given {@link Contact} by exporting then importing it again in
+ * VCF.
+ *
+ * @param c
+ * the {@link Contact} to clone
+ *
+ * @return the clone {@link Contact}
+ */
+ public static Contact clone(Contact c) {
+ try {
+ File tmp = File.createTempFile("clone", ".vcf");
+ FileWriter writer = new FileWriter(tmp);
+ write(writer, c, -1);
+ writer.close();
+
+ Card clone = new Card(tmp, Format.VCard21);
+ clone.unlink();
+ tmp.delete();