android.os.ParcelFileDescriptor.AutoCloseOutputStream Java Examples
The following examples show how to use
android.os.ParcelFileDescriptor.AutoCloseOutputStream.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReadFileTask.java From samba-documents-provider with GNU General Public License v3.0 | 6 votes |
@Override public Void doInBackground(Void... args) { try (final AutoCloseOutputStream os = new AutoCloseOutputStream(mPfd); final SmbFile file = mClient.openFile(mUri, "r")) { int size; byte[] buf = new byte[mBuffer.capacity()]; while ((size = file.read(mBuffer, Integer.MAX_VALUE)) > 0) { mBuffer.get(buf, 0, size); os.write(buf, 0, size); mBuffer.clear(); } } catch (IOException e) { Log.e(TAG, "Failed to read file.", e); try { mPfd.closeWithError(e.getMessage()); } catch (IOException exc) { Log.e(TAG, "Can't even close PFD with error.", exc); } } return null; }
Example #2
Source File: AbstractPipeStrategy.java From cwac-provider with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException { if ("r".equals(mode)) { ParcelFileDescriptor[] pipe=null; try { pipe=ParcelFileDescriptor.createPipe(); new TransferOutThread(getInputStream(uri), 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]); } throw new IllegalArgumentException("Cannot support writing!"); }