Search in sources :

Example 1 with AutoCloseOutputStream

use of android.os.ParcelFileDescriptor.AutoCloseOutputStream in project cw-omnibus by commonsguy.

the class PipeProvider method openFile.

@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
    ParcelFileDescriptor[] pipe = null;
    try {
        pipe = ParcelFileDescriptor.createPipe();
        AssetManager assets = getContext().getResources().getAssets();
        new TransferThread(assets.open(uri.getLastPathSegment()), new AutoCloseOutputStream(pipe[1])).start();
    } catch (IOException e) {
        Log.e(getClass().getSimpleName(), "Exception opening pipe", e);
        throw new FileNotFoundException("Could not open pipe for: " + uri.toString());
    }
    return (pipe[0]);
}
Also used : AssetManager(android.content.res.AssetManager) AutoCloseOutputStream(android.os.ParcelFileDescriptor.AutoCloseOutputStream) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Aggregations

AssetManager (android.content.res.AssetManager)1 ParcelFileDescriptor (android.os.ParcelFileDescriptor)1 AutoCloseOutputStream (android.os.ParcelFileDescriptor.AutoCloseOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1