`
zhanglibin1986
  • 浏览: 381569 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

代码3

阅读更多
 
ArrayList<ColumnInfo> columns = new ArrayList<ColumnInfo>();
columns.add(...);
ColumnInfo[] columnList = new ColumnInfo[columns.size()];
columns.toArray(columnList);//将容器columns中的元素放进数组columnList中,如果数组不够大则新建一个数组,如果够大,则将多余的位置置null


此代码为从URI获取where子句。
private final String whereWithId(Uri uri, String selection) {
        String id = uri.getPathSegments().get(1);
        StringBuilder where = new StringBuilder("_id=");
        where.append(id);
        if (!TextUtils.isEmpty(selection)) {
            where.append(" AND (");
            where.append(selection);
            where.append(')');
        }
        return where.toString();
    }

public byte[] get(long key, long timestamp) {
        // Look up the record for the given key.
        Record record = null;
        synchronized (mIndexMap) {
            record = mIndexMap.get(key);
        }
        if (record != null) {
            // Read the chunk from the file.
            if (record.timestamp < timestamp) {
                Log.i(TAG, "File has been updated to " + timestamp + " since the last time " + record.timestamp
                        + " stored in cache.");
                return null;
            }
            try {
                RandomAccessFile chunkFile = getChunkFile(record.chunk);
                if (chunkFile != null) {
                    byte[] data = new byte[record.size];
                    chunkFile.seek(record.offset);
                    chunkFile.readFully(data);
                    return data;
                }
            } catch (Exception e) {
                Log.e(TAG, "Unable to read from chunk file");
            }
        }
        return null;
    }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics