当前位置: 首页>>代码示例>>Java>>正文


Java ParcelFileDescriptor.AutoCloseInputStream方法代码示例

本文整理汇总了Java中android.os.ParcelFileDescriptor.AutoCloseInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java ParcelFileDescriptor.AutoCloseInputStream方法的具体用法?Java ParcelFileDescriptor.AutoCloseInputStream怎么用?Java ParcelFileDescriptor.AutoCloseInputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.os.ParcelFileDescriptor的用法示例。


在下文中一共展示了ParcelFileDescriptor.AutoCloseInputStream方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initialize

import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
private void initialize()
        throws FileNotFoundException {
    ParcelFileDescriptor fileDescriptor = null;
    try {
        if (Utility.isFileUri(videoUri)) {
            fileDescriptor = ParcelFileDescriptor.open(
                    new File(videoUri.getPath()),
                    ParcelFileDescriptor.MODE_READ_ONLY);
            videoSize = fileDescriptor.getStatSize();
            videoStream = new ParcelFileDescriptor.AutoCloseInputStream(fileDescriptor);
        } else if (Utility.isContentUri(videoUri)) {
            videoSize = Utility.getContentSize(videoUri);
            videoStream = FacebookSdk
                    .getApplicationContext()
                    .getContentResolver()
                    .openInputStream(videoUri);
        } else {
            throw new FacebookException("Uri must be a content:// or file:// uri");
        }
    } catch (FileNotFoundException e) {
        Utility.closeQuietly(videoStream);

        throw e;
    }
}
 
开发者ID:eviltnan,项目名称:kognitivo,代码行数:26,代码来源:VideoUploader.java

示例2: fileMd5Hash

import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
@Rpc(description = "Compute MD5 hash on a content URI. Return the MD5 has has a hex string.")
public String fileMd5Hash(String uri) throws IOException, NoSuchAlgorithmException {
    Uri uri_ = Uri.parse(uri);
    ParcelFileDescriptor pfd = mContext.getContentResolver().openFileDescriptor(uri_, "r");
    MessageDigest md = MessageDigest.getInstance("MD5");
    int length = (int) pfd.getStatSize();
    byte[] buf = new byte[length];
    ParcelFileDescriptor.AutoCloseInputStream stream =
            new ParcelFileDescriptor.AutoCloseInputStream(pfd);
    DigestInputStream dis = new DigestInputStream(stream, md);
    try {
        dis.read(buf, 0, length);
        return Utils.bytesToHexString(md.digest());
    } finally {
        dis.close();
        stream.close();
    }
}
 
开发者ID:google,项目名称:mobly-bundled-snippets,代码行数:19,代码来源:FileSnippet.java

示例3: 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

示例4: pipeTo

import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
@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];
}
 
开发者ID:kranthi0987,项目名称:easyfilemanager,代码行数:11,代码来源:ParcelFileDescriptorUtil.java

示例5: 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

示例6: grantWidgetPermission

import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
/**
 * Grants the launcher permission to bind widgets.
 */
protected void grantWidgetPermission() throws IOException {
    // Check bind widget permission
    if (mTargetContext.getPackageManager().checkPermission(
            mTargetPackage, android.Manifest.permission.BIND_APPWIDGET)
            != PackageManager.PERMISSION_GRANTED) {
        ParcelFileDescriptor pfd = getInstrumentation().getUiAutomation().executeShellCommand(
                "appwidget grantbind --package " + mTargetPackage);
        // Read the input stream fully.
        FileInputStream fis = new ParcelFileDescriptor.AutoCloseInputStream(pfd);
        while (fis.read() != -1);
        fis.close();
    }
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:17,代码来源:LauncherInstrumentationTestCase.java


注:本文中的android.os.ParcelFileDescriptor.AutoCloseInputStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。