本文整理汇总了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;
}
}
示例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();
}
}
示例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);
}
}
});
}
示例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;
}