当前位置: 首页>>代码示例>>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;未经允许,请勿转载。