当前位置: 首页>>代码示例>>Java>>正文


Java Attachment类代码示例

本文整理汇总了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;
}
 
开发者ID:trinhlbk1991,项目名称:DemoCouchbaseLite,代码行数:17,代码来源:FirstDemoActivity.java

示例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);
    }
}
 
开发者ID:couchbaselabs,项目名称:mini-hacks,代码行数:21,代码来源:PlacesAdapter.java

示例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;
}
 
开发者ID:Kaufland,项目名称:andcouchbaseentity,代码行数:39,代码来源:UserProfile.java


注:本文中的com.couchbase.lite.Attachment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。