Пример #1
0
  private void processVCard(
      String fileName,
      String eTag,
      InputStream stream,
      Charset charset,
      Contact.Downloader downloader)
      throws IOException, ContactsStorageException {
    Contact[] contacts = Contact.fromStream(stream, charset, downloader);
    if (contacts.length == 1) {
      Contact newData = contacts[0];

      // update local contact, if it exists
      LocalContact localContact = (LocalContact) localResources.get(fileName);
      if (localContact != null) {
        App.log.info("Updating " + fileName + " in local address book");
        localContact.eTag = eTag;
        localContact.update(newData);
        syncResult.stats.numUpdates++;
      } else {
        App.log.info("Adding " + fileName + " to local address book");
        localContact = new LocalContact(localAddressBook(), newData, fileName, eTag);
        localContact.add();
        syncResult.stats.numInserts++;
      }
    } else App.log.severe("Received VCard with not exactly one VCARD, ignoring " + fileName);
  }
Пример #2
0
 @Override
 protected RequestBody prepareUpload(LocalResource resource)
     throws IOException, ContactsStorageException {
   LocalContact local = (LocalContact) resource;
   return RequestBody.create(
       hasVCard4 ? DavAddressBook.MIME_VCARD4 : DavAddressBook.MIME_VCARD3_UTF8,
       local
           .getContact()
           .toStream(hasVCard4 ? VCardVersion.V4_0 : VCardVersion.V3_0)
           .toByteArray());
 }