FileDocCategorySizeDatePackage
MemoryFileProvider.javaAPI DocAndroid 5.1 API6227Thu Mar 12 22:22:12 GMT 2015android.content

MemoryFileProvider

public class MemoryFileProvider extends ContentProvider
Simple test provider that runs in the local process.

Fields Summary
private static final String
TAG
private static final String
DATA_FILE
public static final byte[]
TEST_BLOB
private android.database.sqlite.SQLiteOpenHelper
mOpenHelper
private static final int
DATA_ID_BLOB
private static final int
HUGE
private static final int
FILE
private static final UriMatcher
sURLMatcher
Constructors Summary
public MemoryFileProvider()

    
Methods Summary
public intdelete(android.net.Uri url, java.lang.String where, java.lang.String[] whereArgs)

        throw new UnsupportedOperationException("delete not supported");
    
private android.os.ParcelFileDescriptorgetBlobColumnAsFile(android.net.Uri url, java.lang.String mode, java.lang.String sql)

        if (!"r".equals(mode)) {
            throw new FileNotFoundException("Mode " + mode + " not supported for " + url);
        }

        SQLiteDatabase db = mOpenHelper.getReadableDatabase();
        return DatabaseUtils.blobFileDescriptorForQuery(db, sql, null);
    
public java.lang.StringgetType(android.net.Uri url)

        int match = sURLMatcher.match(url);
        switch (match) {
            case DATA_ID_BLOB:
                return "application/octet-stream";
            case FILE:
                return "application/octet-stream";
            default:
                throw new IllegalArgumentException("Unknown URL");
        }
    
public android.net.Uriinsert(android.net.Uri url, ContentValues initialValues)

        throw new UnsupportedOperationException("insert not supported");
    
public booleanonCreate()

        mOpenHelper = new DatabaseHelper(getContext());
        try {
            OutputStream out = getContext().openFileOutput(DATA_FILE, Context.MODE_PRIVATE);
            out.write(TEST_BLOB);
            out.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return true;
    
public android.os.ParcelFileDescriptoropenFile(android.net.Uri url, java.lang.String mode)

        int match = sURLMatcher.match(url);
        switch (match) {
            case DATA_ID_BLOB:
                String sql = "SELECT _blob FROM data WHERE _id=" + url.getPathSegments().get(1);
                return getBlobColumnAsFile(url, mode, sql);
            case HUGE:
                try {
                    return ParcelFileDescriptor.fromData(TEST_BLOB, null);
                } catch (IOException ex) {
                    throw new FileNotFoundException("Error reading " + url + ":" + ex.toString());
                }
            case FILE:
                File file = getContext().getFileStreamPath(DATA_FILE);
                return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
            default:
                throw new FileNotFoundException("No files supported by provider at " + url);
        }
    
public android.database.Cursorquery(android.net.Uri url, java.lang.String[] projectionIn, java.lang.String selection, java.lang.String[] selectionArgs, java.lang.String sort)

        throw new UnsupportedOperationException("query not supported");
    
public intupdate(android.net.Uri url, ContentValues values, java.lang.String where, java.lang.String[] whereArgs)

        throw new UnsupportedOperationException("update not supported");