當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。