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


Java ParcelFileDescriptor类代码示例

本文整理汇总了Java中android.os.ParcelFileDescriptor的典型用法代码示例。如果您正苦于以下问题:Java ParcelFileDescriptor类的具体用法?Java ParcelFileDescriptor怎么用?Java ParcelFileDescriptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ParcelFileDescriptor类属于android.os包,在下文中一共展示了ParcelFileDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: openFile

import android.os.ParcelFileDescriptor; //导入依赖的package包/类
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode)
		throws FileNotFoundException {
       initIfNecessary();
	AssetFileDescriptor af = openAssetFile(uri, mode);
	if ( null != af ) {
		return af.getParcelFileDescriptor();
	}
	return null;
}
 
开发者ID:12d,项目名称:react-native-videoplayer,代码行数:11,代码来源:APEZProvider.java

示例2: openDocument

import android.os.ParcelFileDescriptor; //导入依赖的package包/类
@Override
public ParcelFileDescriptor openDocument(String docId, String mode, CancellationSignal signal)
        throws FileNotFoundException {

    if (!"r".equals(mode)) {
        throw new IllegalArgumentException("Media is read-only");
    }

    final Uri target = getUriForDocumentId(docId);

    // Delegate to real provider
    final long token = Binder.clearCallingIdentity();
    try {
        return getContext().getContentResolver().openFileDescriptor(target, mode);
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
 
开发者ID:gigabytedevelopers,项目名称:FireFiles,代码行数:19,代码来源:MediaDocumentsProvider.java

示例3: openImageThumbnailCleared

import android.os.ParcelFileDescriptor; //导入依赖的package包/类
protected ParcelFileDescriptor openImageThumbnailCleared(long id, CancellationSignal signal)
        throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();

    Cursor cursor = null;
    try {
        cursor = resolver.query(Images.Thumbnails.EXTERNAL_CONTENT_URI,
                ImageThumbnailQuery.PROJECTION, Images.Thumbnails.IMAGE_ID + "=" + id, null,
                null);
        if (cursor.moveToFirst()) {
            final String data = cursor.getString(ImageThumbnailQuery._DATA);
            return ParcelFileDescriptor.open(
                    new File(data), ParcelFileDescriptor.MODE_READ_ONLY);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
    }
    return null;
}
 
开发者ID:gigabytedevelopers,项目名称:FireFiles,代码行数:20,代码来源:StorageProvider.java

示例4: 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

示例5: openReadInternal

import android.os.ParcelFileDescriptor; //导入依赖的package包/类
private ParcelFileDescriptor openReadInternal(String name) throws IOException {
    assertPreparedAndNotSealed("openRead");

    try {
        if (!FileUtils.isValidExtFilename(name)) {
            throw new IllegalArgumentException("Invalid name: " + name);
        }
        final File target = new File(resolveStageDir(), name);

        final FileDescriptor targetFd = Os.open(target.getAbsolutePath(), O_RDONLY, 0);
        return ParcelFileDescriptor.dup(targetFd);

    } catch (ErrnoException e) {
        throw new IOException(e);
    }
}
 
开发者ID:codehz,项目名称:container,代码行数:17,代码来源:PackageInstallerSession.java

示例6: 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

示例7: openVideoThumbnailCleared

import android.os.ParcelFileDescriptor; //导入依赖的package包/类
protected AssetFileDescriptor openVideoThumbnailCleared(long id, CancellationSignal signal)
        throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    Cursor cursor = null;
    try {
        cursor = resolver.query(Video.Thumbnails.EXTERNAL_CONTENT_URI,
                VideoThumbnailQuery.PROJECTION, Video.Thumbnails.VIDEO_ID + "=" + id, null,
                null);
        if (cursor.moveToFirst()) {
            final String data = cursor.getString(VideoThumbnailQuery._DATA);
            return new AssetFileDescriptor(ParcelFileDescriptor.open(
                    new File(data), ParcelFileDescriptor.MODE_READ_ONLY), 0,
                    AssetFileDescriptor.UNKNOWN_LENGTH);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
    }
    return null;
}
 
开发者ID:kranthi0987,项目名称:easyfilemanager,代码行数:20,代码来源:StorageProvider.java

示例8: 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

示例9: modeToMode

import android.os.ParcelFileDescriptor; //导入依赖的package包/类
/**
 * Copied from ContentResolver.java
 */
private static int modeToMode(String mode) {
    int modeBits;
    if ("r".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_ONLY;
    } else if ("w".equals(mode) || "wt".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_WRITE_ONLY
                | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_TRUNCATE;
    } else if ("wa".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_WRITE_ONLY
                | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_APPEND;
    } else if ("rw".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_WRITE
                | ParcelFileDescriptor.MODE_CREATE;
    } else if ("rwt".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_WRITE
                | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_TRUNCATE;
    } else {
        throw new IllegalArgumentException("Invalid mode: " + mode);
    }
    return modeBits;
}
 
开发者ID:roshakorost,项目名称:Phial,代码行数:28,代码来源:FileProvider.java

示例10: testLoadResource_returnsFileDescriptor

import android.os.ParcelFileDescriptor; //导入依赖的package包/类
@Test
public void testLoadResource_returnsFileDescriptor() throws Exception {
  Context context = RuntimeEnvironment.application;
  Uri uri = Uri.parse("file://nothing");

  ContentResolver contentResolver = context.getContentResolver();
  ContentResolverShadow shadow = Shadow.extract(contentResolver);

  AssetFileDescriptor assetFileDescriptor = mock(AssetFileDescriptor.class);
  ParcelFileDescriptor parcelFileDescriptor = mock(ParcelFileDescriptor.class);
  when(assetFileDescriptor.getParcelFileDescriptor()).thenReturn(parcelFileDescriptor);
  shadow.registerFileDescriptor(uri, assetFileDescriptor);

  FileDescriptorLocalUriFetcher fetcher =
      new FileDescriptorLocalUriFetcher(context.getContentResolver(), uri);
  fetcher.loadData(Priority.NORMAL, callback);
  verify(callback).onDataReady(eq(parcelFileDescriptor));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:FileDescriptorLocalUriFetcherTest.java

示例11: openFile

import android.os.ParcelFileDescriptor; //导入依赖的package包/类
@Override
public android.os.ParcelFileDescriptor openFile(android.net.Uri uri, java.lang.String mode)
        throws java.io.FileNotFoundException {

    Pair<UUID, String> callIdAndAttachmentName = parseCallIdAndAttachmentName(uri);
    if (callIdAndAttachmentName == null) {
        throw new FileNotFoundException();
    }

    try {
        File file = NativeAppCallAttachmentStore.openAttachment(
                callIdAndAttachmentName.first,
                callIdAndAttachmentName.second);

        return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
    } catch (FileNotFoundException exception) {
        Log.e(TAG, "Got unexpected exception:" + exception);
        throw exception;
    }
}
 
开发者ID:eviltnan,项目名称:kognitivo,代码行数:21,代码来源:FacebookContentProvider.java

示例12: 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

示例13: openFile

import android.os.ParcelFileDescriptor; //导入依赖的package包/类
@Override
public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode) throws FileNotFoundException {
  final MasterSecret masterSecret = KeyCachingService.getMasterSecret(getContext());
  Log.w(TAG, "openFile() called!");

  if (masterSecret == null) {
    Log.w(TAG, "masterSecret was null, abandoning.");
    return null;
  }

  switch (uriMatcher.match(uri)) {
  case SINGLE_ROW:
    Log.w(TAG, "Parting out a single row...");
    try {
      final PartUriParser partUri = new PartUriParser(uri);
      return getParcelStreamForAttachment(masterSecret, partUri.getPartId());
    } catch (IOException ioe) {
      Log.w(TAG, ioe);
      throw new FileNotFoundException("Error opening file");
    }
  }

  throw new FileNotFoundException("Request for bad part.");
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:25,代码来源:PartProvider.java

示例14: parseMode

import android.os.ParcelFileDescriptor; //导入依赖的package包/类
public static int parseMode(String mode) {
    final int modeBits;
    if ("r".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_ONLY;
    } else if ("w".equals(mode) || "wt".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_WRITE_ONLY
                | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_TRUNCATE;
    } else if ("wa".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_WRITE_ONLY
                | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_APPEND;
    } else if ("rw".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_WRITE
                | ParcelFileDescriptor.MODE_CREATE;
    } else if ("rwt".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_WRITE
                | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_TRUNCATE;
    } else {
        throw new IllegalArgumentException("Bad mode '" + mode + "'");
    }
    return modeBits;
}
 
开发者ID:kranthi0987,项目名称:easyfilemanager,代码行数:25,代码来源:Utils.java

示例15: openRenderer

import android.os.ParcelFileDescriptor; //导入依赖的package包/类
private void openRenderer( )  {
    // In this sample, we read a PDF from the assets directory.
    File f = new File(uri.getPath());
    try {
        mFileDescriptor = ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_ONLY);
        mPdfRenderer = new PdfRenderer(mFileDescriptor);
        cnt=mPdfRenderer.getPageCount();
    } catch (Exception e) {
        log.e(e);
    }
}
 
开发者ID:yippeesoft,项目名称:NotifyTools,代码行数:12,代码来源:PdfActivity.java


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