本文整理汇总了Java中com.couchbase.lite.Attachment类的典型用法代码示例。如果您正苦于以下问题:Java Attachment类的具体用法?Java Attachment怎么用?Java Attachment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Attachment类属于com.couchbase.lite包,在下文中一共展示了Attachment类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAvatar
import com.couchbase.lite.Attachment; //导入依赖的package包/类
private Bitmap getAvatar() {
Document doc = mDatabase.getDocument(CONTACT_INFO_DOCUMENT_ID);
Revision rev = doc.getCurrentRevision();
Attachment att = rev.getAttachment("avatar.jpg");
if (att != null) {
try {
InputStream is = att.getContent();
BufferedInputStream bif = new BufferedInputStream(is);
return BitmapFactory.decodeStream(bif);
} catch (CouchbaseLiteException e) {
Log.e(TAG, "Cannot load attachment", e);
}
return null;
}
return null;
}
示例2: onBindViewHolder
import com.couchbase.lite.Attachment; //导入依赖的package包/类
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Place place = dataSet.get(position);
holder.restaurantName.setText(place.getName());
holder.restaurantText.setText(place.getAddress());
Document document = database.getDocument(place.getId());
Attachment attachment = document.getCurrentRevision().getAttachment("photo");
if (attachment != null) {
InputStream is = null;
try {
is = attachment.getContent();
} catch (CouchbaseLiteException e) {
e.printStackTrace();
}
Drawable drawable = Drawable.createFromStream(is, "photo");
holder.restaurantImage.setImageDrawable(drawable);
}
}
示例3: migrateGuestData
import com.couchbase.lite.Attachment; //导入依赖的package包/类
public static boolean migrateGuestData(final Database guestDb, final Document profile) {
boolean success = true;
final Database userDB = profile.getDatabase();
if (guestDb.getLastSequenceNumber() > 0 && userDB.getLastSequenceNumber() == 0) {
success = userDB.runInTransaction(new TransactionalTask() {
@Override
public boolean run() {
try {
QueryEnumerator rows = guestDb.createAllDocumentsQuery().run();
for (QueryRow row : rows) {
Document doc = row.getDocument();
Document newDoc = userDB.getDocument(doc.getId());
newDoc.putProperties(doc.getUserProperties());
List<Attachment> attachments = doc.getCurrentRevision().getAttachments();
if (attachments.size() > 0) {
UnsavedRevision rev = newDoc.getCurrentRevision().createRevision();
for (Attachment attachment : attachments) {
rev.setAttachment(
attachment.getName(),
attachment.getContentType(),
attachment.getContent());
}
rev.save();
}
}
// Delete guest database:
guestDb.delete();
} catch (CouchbaseLiteException e) {
Log.e(Application.TAG, "Error when migrating guest data to user", e);
return false;
}
return true;
}
});
}
return success;
}