Search in sources :

Example 1 with UsbFileOutputStream

use of com.github.mjdev.libaums.fs.UsbFileOutputStream in project AnExplorer by 1hakr.

the class UsbStorageProvider method openDocument.

@Override
public ParcelFileDescriptor openDocument(String documentId, String mode, CancellationSignal signal) throws FileNotFoundException {
    try {
        UsbFile file = getFileForDocId(documentId);
        /*            final int accessMode = ParcelFileDescriptorUtil.parseMode(mode);
            if ((accessMode | ParcelFileDescriptor.MODE_READ_ONLY) == ParcelFileDescriptor.MODE_READ_ONLY) {
                return ParcelFileDescriptorUtil.pipeFrom(new UsbFileInputStream(file));
            } else if ((accessMode | ParcelFileDescriptor.MODE_WRITE_ONLY) == ParcelFileDescriptor.MODE_WRITE_ONLY) {
                return ParcelFileDescriptorUtil.pipeTo(new UsbFileOutputStream(file));
            }*/
        final boolean isWrite = (mode.indexOf('w') != -1);
        if (isWrite) {
            return ParcelFileDescriptorUtil.pipeTo(new UsbFileOutputStream(file));
        } else {
            return ParcelFileDescriptorUtil.pipeFrom(new UsbFileInputStream(file));
        }
    } catch (IOException e) {
        throw new FileNotFoundException(e.getMessage());
    }
}
Also used : UsbFile(com.github.mjdev.libaums.fs.UsbFile) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) UsbFileInputStream(com.github.mjdev.libaums.fs.UsbFileInputStream) UsbFileOutputStream(com.github.mjdev.libaums.fs.UsbFileOutputStream)

Aggregations

UsbFile (com.github.mjdev.libaums.fs.UsbFile)1 UsbFileInputStream (com.github.mjdev.libaums.fs.UsbFileInputStream)1 UsbFileOutputStream (com.github.mjdev.libaums.fs.UsbFileOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1