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


Java ParcelFileDescriptor.close方法代码示例

本文整理汇总了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;
    }
  });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:FileLoader.java

示例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);
        }
    }
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:17,代码来源:Linker.java

示例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();
}
 
开发者ID:quanzhuo,项目名称:prada,代码行数:21,代码来源:UploadAgent.java

示例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);
        }
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:10,代码来源:SMimeApi.java

示例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);
        }
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:10,代码来源:OpenPgpApi.java

示例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));
    }
}
 
开发者ID:shivam141296,项目名称:Android-Firewall,代码行数:9,代码来源:BlackHoleService.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:31,代码来源:VideoBitmapDecoder.java

示例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);
	}
}
 
开发者ID:coding-dream,项目名称:TPlayer,代码行数:10,代码来源:IOUtils.java

示例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();
}
 
开发者ID:mobilemaster128,项目名称:quickblox-android,代码行数:31,代码来源:ImageUtils.java

示例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);
            }
        }
    });
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:21,代码来源:UploadDataProviders.java

示例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();
}
 
开发者ID:ujjwalagrawal17,项目名称:CodeCompilerApp,代码行数:8,代码来源:SaveFileTask.java

示例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;
}
 
开发者ID:akashdeepsingh9988,项目名称:Cybernet-VPN,代码行数:32,代码来源:OpenVpnManagementThread.java

示例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);
    }
}
 
开发者ID:mayurkaul,项目名称:medialibrary,代码行数:8,代码来源:Utils.java

示例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;
    }
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:32,代码来源:MediaStoreHack.java

示例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 ) {}
}
 
开发者ID:viseator,项目名称:MontageCam,代码行数:7,代码来源:IOUtils.java


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