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


Java ParcelFileDescriptor.getStatSize方法代码示例

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


在下文中一共展示了ParcelFileDescriptor.getStatSize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: create

import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
/**
 * Uploads an entire file, closing the descriptor when it is no longer needed.
 *
 * @param fd The file descriptor to upload
 * @throws IllegalArgumentException if {@code fd} is not a file.
 * @return A new UploadDataProvider for the given file descriptor
 */
public static UploadDataProvider create(final ParcelFileDescriptor fd) {
    return new FileUploadProvider(new FileChannelProvider() {
        @Override
        public FileChannel getChannel() throws IOException {
            if (fd.getStatSize() != -1) {
                return new ParcelFileDescriptor.AutoCloseInputStream(fd).getChannel();
            } else {
                fd.close();
                throw new IllegalArgumentException("Not a file: " + fd);
            }
        }
    });
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:21,代码来源:UploadDataProviders.java

示例4: openAssetFile

import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
/**
 * Opens an asset file for an URI.
 *
 * Called by {@link ContentResolver#openAssetFileDescriptor(Uri, String)} or
 * {@link ContentResolver#openInputStream(Uri)} from a client requesting a
 * dictionary.
 * @see ContentProvider#openAssetFile(Uri, String)
 *
 * @param uri the URI the file is for.
 * @param mode the mode to read the file. MUST be "r" for readonly.
 * @return the descriptor, or null if the file is not found or if mode is not equals to "r".
 */
@Override
public AssetFileDescriptor openAssetFile(final Uri uri, final String mode) {
    if (null == mode || !"r".equals(mode)) return null;

    final int match = matchUri(uri);
    if (DICTIONARY_V1_DICT_INFO != match && DICTIONARY_V2_DATAFILE != match) {
        // Unsupported URI for openAssetFile
        Log.w(TAG, "Unsupported URI for openAssetFile : " + uri);
        return null;
    }
    final String wordlistId = uri.getLastPathSegment();
    final String clientId = getClientId(uri);
    final ContentValues wordList = getWordlistMetadataForWordlistId(clientId, wordlistId);

    if (null == wordList) return null;

    try {
        final int status = wordList.getAsInteger(MetadataDbHelper.STATUS_COLUMN);
        if (MetadataDbHelper.STATUS_DELETING == status) {
            // This will return an empty file (R.raw.empty points at an empty dictionary)
            // This is how we "delete" the files. It allows Android Keyboard to fake deleting
            // a default dictionary - which is actually in its assets and can't be really
            // deleted.
            final AssetFileDescriptor afd = getContext().getResources().openRawResourceFd(
                    R.raw.empty);
            return afd;
        }
        final String localFilename =
                wordList.getAsString(MetadataDbHelper.LOCAL_FILENAME_COLUMN);
        final File f = getContext().getFileStreamPath(localFilename);
        final ParcelFileDescriptor pfd =
                ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_ONLY);
        return new AssetFileDescriptor(pfd, 0, pfd.getStatSize());
    } catch (FileNotFoundException e) {
        // No file : fall through and return null
    }
    return null;
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:51,代码来源:DictionaryProvider.java


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