ITeye博客

代码3

zhanglibin1986 · 2011-02-11 16:13 · Android · 移动开发 · Cache · UP · Markdown

[code="java"] ArrayList columns = new ArrayList(); columns.add(...); ColumnInfo[] columnList = new ColumnInfo[columns.size()]; columns.toArray(columnList);//将容器columns中的元素放进数组columnList中,如果数组不够大则新建一个数组,如果够大,则将多余的位置置null[/code] 此代码为从URI获取where子句。 [code="java"]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(); } [/code] [code="java"]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; }[/code]

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。