public class

RenamingDelegatingContext

extends ContextWrapper
java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.test.RenamingDelegatingContext

Class Overview

This is a class which delegates to the given context, but performs database and file operations with a renamed database/file name (prefixes default names with a given prefix).

Summary

[Expand]
Inherited Constants
From class android.content.Context
Public Constructors
RenamingDelegatingContext(Context context, String filePrefix)
RenamingDelegatingContext(Context context, Context fileContext, String filePrefix)
Public Methods
String[] databaseList()
Returns an array of strings naming the private databases associated with this Context's application package.
boolean deleteDatabase(String name)
Delete an existing private SQLiteDatabase associated with this Context's application package.
boolean deleteFile(String name)
Delete the given private file associated with this Context's application package.
String[] fileList()
Returns an array of strings naming the private files associated with this Context's application package.
String getDatabasePrefix()
File getFileStreamPath(String name)
Returns the absolute path on the filesystem where a file created with openFileOutput(String, int) is stored.
void makeExistingFilesAndDbsAccessible()
Makes accessible all files and databases whose names match the filePrefix that was passed to the constructor.
FileInputStream openFileInput(String name)
Open a private file associated with this Context's application package for reading.
FileOutputStream openFileOutput(String name, int mode)
Open a private file associated with this Context's application package for writing.
SQLiteDatabase openOrCreateDatabase(String name, int mode, SQLiteDatabase.CursorFactory factory)
Open a new private SQLiteDatabase associated with this Context's application package.
static <T extends ContentProvider> T providerWithRenamedContext(Class<T> contentProvider, Context c, String filePrefix)
static <T extends ContentProvider> T providerWithRenamedContext(Class<T> contentProvider, Context c, String filePrefix, boolean allowAccessToExistingFilesAndDbs)
[Expand]
Inherited Methods
From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object

Public Constructors

public RenamingDelegatingContext (Context context, String filePrefix)

Parameters
context : the context that will be delagated.
filePrefix : a prefix with which database and file names will be prefixed.

public RenamingDelegatingContext (Context context, Context fileContext, String filePrefix)

Parameters
context : the context that will be delagated.
fileContext : the context that file and db methods will be delgated to
filePrefix : a prefix with which database and file names will be prefixed.

Public Methods

public String[] databaseList ()

Returns an array of strings naming the private databases associated with this Context's application package.

Returns
  • Array of strings naming the private databases.

public boolean deleteDatabase (String name)

Delete an existing private SQLiteDatabase associated with this Context's application package.

Parameters
name The name (unique in the application package) of the database.
Returns
  • True if the database was successfully deleted; else false.

public boolean deleteFile (String name)

Delete the given private file associated with this Context's application package.

Parameters
name The name of the file to delete; can not contain path separators.
Returns
  • True if the file was successfully deleted; else false.

public String[] fileList ()

Returns an array of strings naming the private files associated with this Context's application package.

Returns
  • Array of strings naming the private files.

public String getDatabasePrefix ()

public File getFileStreamPath (String name)

Returns the absolute path on the filesystem where a file created with openFileOutput(String, int) is stored.

Parameters
name The name of the file for which you would like to get its path.
Returns
  • Returns an absolute path to the given file.

public void makeExistingFilesAndDbsAccessible ()

Makes accessible all files and databases whose names match the filePrefix that was passed to the constructor. Normally only files and databases that were created through this context are accessible.

public FileInputStream openFileInput (String name)

Open a private file associated with this Context's application package for reading.

Parameters
name The name of the file to open; can not contain path separators.
Returns
  • FileInputStream Resulting input stream.

public FileOutputStream openFileOutput (String name, int mode)

Open a private file associated with this Context's application package for writing. Creates the file if it doesn't already exist.

Parameters
name The name of the file to open; can not contain path separators.
mode Operating mode. Use 0 or MODE_PRIVATE for the default operation, MODE_APPEND to append to an existing file, MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE to control permissions.
Returns
  • FileOutputStream Resulting output stream.

public SQLiteDatabase openOrCreateDatabase (String name, int mode, SQLiteDatabase.CursorFactory factory)

Open a new private SQLiteDatabase associated with this Context's application package. Create the database file if it doesn't exist.

Parameters
name The name (unique in the application package) of the database.
mode Operating mode. Use 0 or MODE_PRIVATE for the default operation, MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE to control permissions.
factory An optional factory class that is called to instantiate a cursor when query is called.
Returns
  • The contents of a newly created database with the given name.

public static T providerWithRenamedContext (Class<T> contentProvider, Context c, String filePrefix)

public static T providerWithRenamedContext (Class<T> contentProvider, Context c, String filePrefix, boolean allowAccessToExistingFilesAndDbs)