代码三

代码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;
    }