Java Code Examples for android.os.ParcelFileDescriptor#createPipe()
The following examples show how to use
android.os.ParcelFileDescriptor#createPipe() .
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: CallNotificationSoundProvider.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
@Nullable @Override public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode) throws FileNotFoundException{ if(!"r".equals(mode)) throw new SecurityException("Unexpected file mode "+mode); if(ApplicationLoader.applicationContext==null) throw new FileNotFoundException("Unexpected application state"); VoIPBaseService srv=VoIPBaseService.getSharedInstance(); if(srv!=null){ srv.startRingtoneAndVibration(); } try{ ParcelFileDescriptor[] pipe=ParcelFileDescriptor.createPipe(); ParcelFileDescriptor.AutoCloseOutputStream outputStream = new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1]); byte[] silentWav={82,73,70,70,41,0,0,0,87,65,86,69,102,109,116,32,16,0,0,0,1,0,1,0,68,(byte)172,0,0,16,(byte)177,2,0,2,0,16,0,100,97,116,97,10,0,0,0,0,0,0,0,0,0,0,0,0,0}; outputStream.write(silentWav); outputStream.close(); return pipe[0]; }catch(IOException x){ throw new FileNotFoundException(x.getMessage()); } }
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!"); }
Example 3
Source File: ParcelFileDescriptorUtil.java From FireFiles with Apache License 2.0 | 5 votes |
public static ParcelFileDescriptor pipeFrom(InputStream inputStream) throws IOException { final ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe(); final OutputStream output = new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1]); new TransferThread(inputStream, output).start(); return pipe[0]; }
Example 4
Source File: ParcelFileDescriptorUtil.java From Android-SingleSignOn with GNU General Public License v3.0 | 5 votes |
public static ParcelFileDescriptor pipeTo(OutputStream outputStream, IThreadListener listener) throws IOException { ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe(); ParcelFileDescriptor readSide = pipe[0]; ParcelFileDescriptor writeSide = pipe[1]; // start the transfer thread new TransferThread(new ParcelFileDescriptor.AutoCloseInputStream(readSide), outputStream, listener) .start(); return writeSide; }
Example 5
Source File: ParcelFileDescriptorUtil.java From Android-SingleSignOn with GNU General Public License v3.0 | 5 votes |
public static ParcelFileDescriptor pipeFrom(InputStream inputStream, IThreadListener listener) throws IOException { ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe(); ParcelFileDescriptor readSide = pipe[0]; ParcelFileDescriptor writeSide = pipe[1]; // start the transfer thread new TransferThread(inputStream, new ParcelFileDescriptor.AutoCloseOutputStream(writeSide), listener) .start(); return readSide; }
Example 6
Source File: ACEParcelFileDescriptorUtil.java From appcan-android with GNU Lesser General Public License v3.0 | 5 votes |
public static ParcelFileDescriptor pipeTo(OutputStream outputStream) throws IOException { ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe(); ParcelFileDescriptor readSide = pipe[0]; ParcelFileDescriptor writeSide = pipe[1]; // start the transfer thread new TransferThread(new ParcelFileDescriptor.AutoCloseInputStream(readSide), outputStream) .start(); return writeSide; }
Example 7
Source File: ACEParcelFileDescriptorUtil.java From appcan-android with GNU Lesser General Public License v3.0 | 5 votes |
public static ParcelFileDescriptor pipeFrom(InputStream inputStream) throws IOException { ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe(); ParcelFileDescriptor readSide = pipe[0]; ParcelFileDescriptor writeSide = pipe[1]; // start the transfer thread new TransferThread(inputStream, new ParcelFileDescriptor.AutoCloseOutputStream(writeSide)) .start(); return readSide; }
Example 8
Source File: ParcelFileDescriptorUtil.java From openpgp-api with Apache License 2.0 | 5 votes |
public static ParcelFileDescriptor pipeFrom(InputStream inputStream) throws IOException { ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe(); ParcelFileDescriptor readSide = pipe[0]; ParcelFileDescriptor writeSide = pipe[1]; new TransferThread(inputStream, new ParcelFileDescriptor.AutoCloseOutputStream(writeSide)) .start(); return readSide; }
Example 9
Source File: TGAssetsProvider.java From tuxguitar with GNU Lesser General Public License v2.1 | 5 votes |
@Override public ParcelFileDescriptor openDocument(String documentId, String mode, CancellationSignal cancellationSignal) throws FileNotFoundException { try { ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe(); if( this.assets != null ) { TGStreamUtil.write(this.assets.open(documentId), new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1])); } return pipe[0]; } catch(IOException e) { e.printStackTrace(); throw new FileNotFoundException(); } }
Example 10
Source File: ParcelFileDescriptorUtil.java From FireFiles with Apache License 2.0 | 5 votes |
@SuppressWarnings("unused") public static ParcelFileDescriptor pipeTo(OutputStream outputStream) throws IOException { final ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe(); final InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(pipe[0]); new TransferThread(input, outputStream).start(); return pipe[1]; }
Example 11
Source File: ParcelFileDescriptorUtil.java From FireFiles with Apache License 2.0 | 5 votes |
public static ParcelFileDescriptor pipeFrom(InputStream inputStream) throws IOException { final ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe(); final OutputStream output = new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1]); new TransferThread(inputStream, output).start(); return pipe[0]; }
Example 12
Source File: ParcelFileDescriptorUtil.java From FireFiles with Apache License 2.0 | 5 votes |
@SuppressWarnings("unused") public static ParcelFileDescriptor pipeTo(OutputStream outputStream) throws IOException { final ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe(); final InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(pipe[0]); new TransferThread(input, outputStream).start(); return pipe[1]; }
Example 13
Source File: ParcelFileDescriptorUtil.java From FireFiles with Apache License 2.0 | 5 votes |
public static ParcelFileDescriptor pipeFrom(InputStream inputStream) throws IOException { final ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe(); final OutputStream output = new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1]); new TransferThread(inputStream, output).start(); return pipe[0]; }
Example 14
Source File: MainContentProviderBase.java From edslite with GNU General Public License v2.0 | 5 votes |
private static ParcelFileDescriptor writeToPipe(final File srcFile, final Bundle opts) throws IOException { final ParcelFileDescriptor[] pfds = ParcelFileDescriptor.createPipe(); Completable.create(s -> { FileOutputStream fout = new FileOutputStream(pfds[1].getFileDescriptor()); try { Util.CancellableProgressInfo pi = new Util.CancellableProgressInfo(); s.setCancellable(pi); Util.copyFileToOutputStream( fout, srcFile, opts.getLong(OPTION_OFFSET, 0), opts.getLong(OPTION_NUM_BYTES, -1), pi ); } finally { fout.close(); } pfds[1].close(); s.onComplete(); }). subscribeOn(Schedulers.newThread()). subscribe(() ->{}, Logger::log); return pfds[0]; }
Example 15
Source File: MainContentProviderBase.java From edslite with GNU General Public License v2.0 | 5 votes |
private static ParcelFileDescriptor readFromPipe(final File targetFile, final Bundle opts) throws IOException { final ParcelFileDescriptor[] pfds = ParcelFileDescriptor.createPipe(); Completable.create(s -> { FileInputStream fin = new FileInputStream(pfds[0].getFileDescriptor()); try { Util.CancellableProgressInfo pi = new Util.CancellableProgressInfo(); s.setCancellable(pi); Util.copyFileFromInputStream( fin, targetFile, opts.getLong(OPTION_OFFSET, 0), opts.getLong(OPTION_NUM_BYTES, -1), pi ); } finally { fin.close(); } pfds[0].close(); s.onComplete(); }). subscribeOn(Schedulers.io()). subscribe(() ->{}, Logger::log); return pfds[1]; }
Example 16
Source File: OpenPgpApi.java From FairEmail with GNU General Public License v3.0 | 5 votes |
public ParcelFileDescriptor startPumpThread() throws IOException { if (writeSidePfd != null) { throw new IllegalStateException("startPumpThread() must only be called once!"); } ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe(); ParcelFileDescriptor readSidePfd = pipe[0]; writeSidePfd = pipe[1]; new DataSourceTransferThread(this, new ParcelFileDescriptor.AutoCloseOutputStream(writeSidePfd)).start(); return readSidePfd; }
Example 17
Source File: ParcelFileDescriptorUtil.java From FairEmail with GNU General Public License v3.0 | 5 votes |
public static ParcelFileDescriptor pipeFrom(InputStream inputStream) throws IOException { ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe(); ParcelFileDescriptor readSide = pipe[0]; ParcelFileDescriptor writeSide = pipe[1]; new TransferThread(inputStream, new ParcelFileDescriptor.AutoCloseOutputStream(writeSide)) .start(); return readSide; }
Example 18
Source File: UiAutomation.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Executes a shell command. This method returns two file descriptors, * one that points to the standard output stream (element at index 0), and one that points * to the standard input stream (element at index 1). The command execution is similar * to running "adb shell <command>" from a host connected to the device. * <p> * <strong>Note:</strong> It is your responsibility to close the returned file * descriptors once you are done reading/writing. * </p> * * @param command The command to execute. * @return File descriptors (out, in) to the standard output/input streams. * * @hide */ @TestApi public ParcelFileDescriptor[] executeShellCommandRw(String command) { synchronized (mLock) { throwIfNotConnectedLocked(); } warnIfBetterCommand(command); ParcelFileDescriptor source_read = null; ParcelFileDescriptor sink_read = null; ParcelFileDescriptor source_write = null; ParcelFileDescriptor sink_write = null; try { ParcelFileDescriptor[] pipe_read = ParcelFileDescriptor.createPipe(); source_read = pipe_read[0]; sink_read = pipe_read[1]; ParcelFileDescriptor[] pipe_write = ParcelFileDescriptor.createPipe(); source_write = pipe_write[0]; sink_write = pipe_write[1]; // Calling out without a lock held. mUiAutomationConnection.executeShellCommand(command, sink_read, source_write); } catch (IOException ioe) { Log.e(LOG_TAG, "Error executing shell command!", ioe); } catch (RemoteException re) { Log.e(LOG_TAG, "Error executing shell command!", re); } finally { IoUtils.closeQuietly(sink_read); IoUtils.closeQuietly(source_write); } ParcelFileDescriptor[] result = new ParcelFileDescriptor[2]; result[0] = source_read; result[1] = sink_write; return result; }
Example 19
Source File: UiAutomation.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Executes a shell command. This method returns a file descriptor that points * to the standard output stream. The command execution is similar to running * "adb shell <command>" from a host connected to the device. * <p> * <strong>Note:</strong> It is your responsibility to close the returned file * descriptor once you are done reading. * </p> * * @param command The command to execute. * @return A file descriptor to the standard output stream. */ public ParcelFileDescriptor executeShellCommand(String command) { synchronized (mLock) { throwIfNotConnectedLocked(); } warnIfBetterCommand(command); ParcelFileDescriptor source = null; ParcelFileDescriptor sink = null; try { ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe(); source = pipe[0]; sink = pipe[1]; // Calling out without a lock held. mUiAutomationConnection.executeShellCommand(command, sink, null); } catch (IOException ioe) { Log.e(LOG_TAG, "Error executing shell command!", ioe); } catch (RemoteException re) { Log.e(LOG_TAG, "Error executing shell command!", re); } finally { IoUtils.closeQuietly(sink); } return source; }
Example 20
Source File: MediaStream.java From libstreaming with Apache License 2.0 | 5 votes |
protected void createSockets() throws IOException { if (sPipeApi == PIPE_API_LS) { final String LOCAL_ADDR = "net.majorkernelpanic.streaming-"; for (int i=0;i<10;i++) { try { mSocketId = new Random().nextInt(); mLss = new LocalServerSocket(LOCAL_ADDR+mSocketId); break; } catch (IOException e1) {} } mReceiver = new LocalSocket(); mReceiver.connect( new LocalSocketAddress(LOCAL_ADDR+mSocketId)); mReceiver.setReceiveBufferSize(500000); mReceiver.setSoTimeout(3000); mSender = mLss.accept(); mSender.setSendBufferSize(500000); } else { Log.e(TAG, "parcelFileDescriptors createPipe version = Lollipop"); mParcelFileDescriptors = ParcelFileDescriptor.createPipe(); mParcelRead = new ParcelFileDescriptor(mParcelFileDescriptors[0]); mParcelWrite = new ParcelFileDescriptor(mParcelFileDescriptors[1]); } }