當前位置: 首頁>>代碼示例>>Java>>正文


Java ParcelFileDescriptor.AutoCloseOutputStream方法代碼示例

本文整理匯總了Java中android.os.ParcelFileDescriptor.AutoCloseOutputStream方法的典型用法代碼示例。如果您正苦於以下問題:Java ParcelFileDescriptor.AutoCloseOutputStream方法的具體用法?Java ParcelFileDescriptor.AutoCloseOutputStream怎麽用?Java ParcelFileDescriptor.AutoCloseOutputStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.os.ParcelFileDescriptor的用法示例。


在下文中一共展示了ParcelFileDescriptor.AutoCloseOutputStream方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: pipeFrom

import android.os.ParcelFileDescriptor; //導入方法依賴的package包/類
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];
}
 
開發者ID:medalionk,項目名稱:simple-share-android,代碼行數:10,代碼來源:ParcelFileDescriptorUtil.java

示例2: createForParcelFileDescriptor

import android.os.ParcelFileDescriptor; //導入方法依賴的package包/類
/**
 * Creates a DocumentsArchive instance for opening, browsing and accessing
 * documents within the archive passed as a file descriptor.
 *
 * <p>Note, that this method should be used only if the document does not exist
 * on the local storage. A snapshot file will be created, which may be slower
 * and consume significant resources, in contrast to using
 * {@see createForLocalFile(Context, File, String, char, Uri}.
 *
 * @param context Context of the provider.
 * @param descriptor File descriptor for the archive's contents.
 * @param documentId ID of the archive document.
 * @param idDelimiter Delimiter for constructing IDs of documents within the archive.
 *            The delimiter must never be used for IDs of other documents.
 * @param Uri notificationUri Uri for notifying that the archive file has changed.
 * @see createForLocalFile(Context, File, String, char, Uri)
 */
public static DocumentArchive createForParcelFileDescriptor(
        Context context, ParcelFileDescriptor descriptor, String documentId,
        char idDelimiter, @Nullable Uri notificationUri)
        throws IOException {
    File snapshotFile = null;
    try {
        // Create a copy of the archive, as ZipFile doesn't operate on streams.
        // Moreover, ZipInputStream would be inefficient for large files on
        // pipes.
        snapshotFile = File.createTempFile("android.support.provider.snapshot{",
                "}.zip", context.getCacheDir());

        try {
            final FileOutputStream outputStream =
                    new ParcelFileDescriptor.AutoCloseOutputStream(
                            ParcelFileDescriptor.open(
                                    snapshotFile, ParcelFileDescriptor.MODE_WRITE_ONLY));
            final ParcelFileDescriptor.AutoCloseInputStream inputStream =
                    new ParcelFileDescriptor.AutoCloseInputStream(descriptor);
            final byte[] buffer = new byte[32 * 1024];
            int bytes;
            while ((bytes = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, bytes);
            }
            outputStream.flush();
            return new DocumentArchive(context, snapshotFile, documentId, idDelimiter,
                    notificationUri);
        } catch (Exception e){
            CrashReportingManager.logException(e);
            return null;
        }
    } finally {
        // On UNIX the file will be still available for processes which opened it, even
        // after deleting it. Remove it ASAP, as it won't be used by anyone else.
        if (snapshotFile != null) {
            snapshotFile.delete();
        }
    }
}
 
開發者ID:kranthi0987,項目名稱:easyfilemanager,代碼行數:57,代碼來源:DocumentArchive.java

示例3: NativePipe

import android.os.ParcelFileDescriptor; //導入方法依賴的package包/類
public NativePipe() {
    try {
        ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
        inputStream = new ParcelFileDescriptor.AutoCloseInputStream(pipe[0]) {
            private boolean closed = false;

            @Override
            public void close() throws IOException {
                if (closed) return;
                closed = true;
                super.close();
                outputStream.close();
            }
        };
        outputStream = new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1]) {
            private boolean closed = false;

            @Override
            public void close() throws IOException {
                if (closed) return;
                closed = true;
                super.close();
                inputStream.close();
            }
        };
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:martinmarinov,項目名稱:AndroidDvbDriver,代碼行數:30,代碼來源:NativePipe.java


注:本文中的android.os.ParcelFileDescriptor.AutoCloseOutputStream方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。