本文整理匯總了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;
}