本文整理汇总了Java中android.os.ParcelFileDescriptor.close方法的典型用法代码示例。如果您正苦于以下问题:Java ParcelFileDescriptor.close方法的具体用法?Java ParcelFileDescriptor.close怎么用?Java ParcelFileDescriptor.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.ParcelFileDescriptor
的用法示例。
在下文中一共展示了ParcelFileDescriptor.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: FileDescriptorFactory
import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
public FileDescriptorFactory() {
super(new FileOpener<ParcelFileDescriptor>() {
@Override
public ParcelFileDescriptor open(File file) throws FileNotFoundException {
return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
}
@Override
public void close(ParcelFileDescriptor parcelFileDescriptor) throws IOException {
parcelFileDescriptor.close();
}
@Override
public Class<ParcelFileDescriptor> getDataClass() {
return ParcelFileDescriptor.class;
}
});
}
示例2: writeToParcel
import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
@Override
public void writeToParcel(Parcel out, int flags) {
if (mRelroFd >= 0) {
out.writeLong(mLoadAddress);
out.writeLong(mLoadSize);
out.writeLong(mRelroStart);
out.writeLong(mRelroSize);
try {
ParcelFileDescriptor fd = ParcelFileDescriptor.fromFd(mRelroFd);
fd.writeToParcel(out, 0);
fd.close();
} catch (java.io.IOException e) {
Log.e(TAG, "Can't write LibInfo file descriptor to parcel", e);
}
}
}
示例3: onAgentServiceOff
import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
private void onAgentServiceOff(){
Iterator<String> fileNames = writeFilesHM.keySet().iterator();
String fileName = "";
while (fileNames.hasNext()) {
fileName = fileNames.next();
ParcelFileDescriptor fd = writeFilesHM.get(fileName);
try{
fd.close();
} catch(IOException ex) {
Log.i(TAG, "exception " + ex.toString());
}
}
if (mServiceBound) {
unbindService(mConnection);
mServiceBound = false;
}
writeFilesHM.clear();
uploadFiles.clear();
stopSelf();
}
示例4: closeLoudly
import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
private static void closeLoudly(ParcelFileDescriptor input) {
if (input != null) {
try {
input.close();
} catch (IOException e) {
Log.e(SMimeApi.TAG, "IOException when closing ParcelFileDescriptor!", e);
}
}
}
示例5: closeLoudly
import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
private static void closeLoudly(ParcelFileDescriptor input) {
if (input != null) {
try {
input.close();
} catch (IOException e) {
Log.e(OpenPgpApi.TAG, "IOException when closing ParcelFileDescriptor!", e);
}
}
}
示例6: vpnStop
import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
private void vpnStop(ParcelFileDescriptor pfd) {
Log.i(TAG, "Stopping");
try {
pfd.close();
} catch (IOException ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
}
}
示例7: decode
import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
@Override
public Resource<Bitmap> decode(ParcelFileDescriptor resource, int outWidth, int outHeight,
Options options) throws IOException {
long frameTimeMicros = options.get(TARGET_FRAME);
if (frameTimeMicros < 0 && frameTimeMicros != DEFAULT_FRAME) {
throw new IllegalArgumentException(
"Requested frame must be non-negative, or DEFAULT_FRAME, given: " + frameTimeMicros);
}
Integer frameOption = options.get(FRAME_OPTION);
final Bitmap result;
MediaMetadataRetriever mediaMetadataRetriever = factory.build();
try {
mediaMetadataRetriever.setDataSource(resource.getFileDescriptor());
if (frameTimeMicros == DEFAULT_FRAME) {
result = mediaMetadataRetriever.getFrameAtTime();
} else if (frameOption == null) {
result = mediaMetadataRetriever.getFrameAtTime(frameTimeMicros);
} else {
result = mediaMetadataRetriever.getFrameAtTime(frameTimeMicros, frameOption);
}
} catch (RuntimeException e) {
// MediaMetadataRetriever APIs throw generic runtime exceptions when given invalid data.
throw new IOException(e);
} finally {
mediaMetadataRetriever.release();
}
resource.close();
return BitmapResource.obtain(result, bitmapPool);
}
示例8: closeSilently
import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
public static void closeSilently(ParcelFileDescriptor c) {
if (c == null)
return;
try {
c.close();
} catch (Throwable t) {
Log.w(TAG, "fail to close", t);
}
}
示例9: saveUriToFile
import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
public static String saveUriToFile(Uri uri) throws Exception {
ParcelFileDescriptor parcelFileDescriptor = CoreApp.getInstance().getContentResolver().openFileDescriptor(uri, "r");
FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
InputStream inputStream = new FileInputStream(fileDescriptor);
BufferedInputStream bis = new BufferedInputStream(inputStream);
File parentDir = StorageUtils.getAppExternalDataDirectoryFile();
String fileName = String.valueOf(System.currentTimeMillis()) + ".jpg";
File resultFile = new File(parentDir, fileName);
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(resultFile));
byte[] buf = new byte[2048];
int length;
try {
while ((length = bis.read(buf)) > 0) {
bos.write(buf, 0, length);
}
} catch (Exception e) {
throw new IOException("Can\'t save Storage API bitmap to a file!", e);
} finally {
parcelFileDescriptor.close();
bis.close();
bos.close();
}
return resultFile.getAbsolutePath();
}
示例10: 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);
}
}
});
}
示例11: writeUri
import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
private void writeUri(Uri uri, String newContent, String encoding) throws IOException {
ParcelFileDescriptor pfd = activity.getContentResolver().openFileDescriptor(uri, "w");
FileOutputStream fileOutputStream = new FileOutputStream(pfd.getFileDescriptor());
fileOutputStream.write(newContent.getBytes(Charset.forName(encoding)));
fileOutputStream.close();
pfd.close();
}
示例12: sendTunFD
import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
private boolean sendTunFD(String needed, String extra) {
if (!extra.equals("tun")) {
// We only support tun
VpnStatus.logError(String.format("Device type %s requested, but only tun is possible with the Android API, sorry!", extra));
return false;
}
ParcelFileDescriptor pfd = mOpenVPNService.openTun();
if (pfd == null) return false;
Method setInt;
int fdint = pfd.getFd();
try {
setInt = FileDescriptor.class.getDeclaredMethod("setInt$", int.class);
FileDescriptor fdtosend = new FileDescriptor();
setInt.invoke(fdtosend, fdint);
FileDescriptor[] fds = {fdtosend};
mSocket.setFileDescriptorsForSend(fds);
// Trigger a send so we can close the fd on our side of the channel
// The API documentation fails to mention that it will not reset the file descriptor to
// be send and will happily send the file descriptor on every write ...
String cmd = String.format("needok '%s' %s\n", needed, "ok");
managmentCommand(cmd);
// Set the FileDescriptor to null to stop this mad behavior
mSocket.setFileDescriptorsForSend(null);
pfd.close();
return true;
} catch (NoSuchMethodException | IllegalArgumentException | InvocationTargetException |
IOException | IllegalAccessException exp) {
VpnStatus.logException("Could not send fd over socket", exp);
}
return false;
}
示例13: closeSilently
import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
public static void closeSilently(ParcelFileDescriptor fd) {
try {
if (fd != null) fd.close();
} catch (Throwable t) {
Log.w(TAG, "fail to close", t);
}
}
示例14: mkdir
import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
boolean mkdir(final Context context, final File file) throws IOException {
try {
if (file.exists()) {
return file.isDirectory();
}
final File tmpFile = new File(file, ".MediaWriteTemp");
final int albumId = getTemporaryAlbumId(context);
if (albumId == 0) {
throw new IOException("Failed to create temporary album id.");
}
final Uri albumUri = Uri.parse(String.format(Locale.US, ALBUM_ART_URI + "/%d", albumId));
final ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, tmpFile.getAbsolutePath());
final ContentResolver contentResolver = context.getContentResolver();
if (contentResolver.update(albumUri, values, null, null) == 0) {
values.put(MediaStore.Audio.AlbumColumns.ALBUM_ID, albumId);
contentResolver.insert(Uri.parse(ALBUM_ART_URI), values);
}
try {
final ParcelFileDescriptor fd = contentResolver.openFileDescriptor(albumUri, "r");
if (fd != null)
fd.close();
} finally {
delete(context, tmpFile);
}
return file.exists();
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
示例15: closeSilently
import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
public static void closeSilently( final ParcelFileDescriptor c ) {
if ( c == null ) return;
try {
c.close();
} catch ( final Throwable t ) {}
}