android.content.res.AssetFileDescriptor#UNKNOWN_LENGTH源码实例Demo

下面列出了android.content.res.AssetFileDescriptor#UNKNOWN_LENGTH 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: FireFiles   文件: StorageProvider.java
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;
}
 
源代码2 项目: FireFiles   文件: StorageProvider.java
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;
}
 
源代码3 项目: FireFiles   文件: StorageProvider.java
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;
}
 
private AssetFileDescriptor fetchNonAssetFile(final Uri uri, final String fileName, final String identifier) {
    try {
        final File file = new File(contentPath + identifier, fileName);
        return new AssetFileDescriptor(ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY), 0,
                AssetFileDescriptor.UNKNOWN_LENGTH);
    } catch (final IOException e) {
        Log.e(Objects.requireNonNull(getContext()).getPackageName(),
                "IOException when getting asset file, uri:" + uri, e);
        return null;
    }
}
 
源代码5 项目: TelePlus-Android   文件: ContentDataSource.java
@Override
public long open(DataSpec dataSpec) throws ContentDataSourceException {
  try {
    uri = dataSpec.uri;
    transferInitializing(dataSpec);
    assetFileDescriptor = resolver.openAssetFileDescriptor(uri, "r");
    if (assetFileDescriptor == null) {
      throw new FileNotFoundException("Could not open file descriptor for: " + uri);
    }
    inputStream = new FileInputStream(assetFileDescriptor.getFileDescriptor());
    long assetStartOffset = assetFileDescriptor.getStartOffset();
    long skipped = inputStream.skip(assetStartOffset + dataSpec.position) - assetStartOffset;
    if (skipped != dataSpec.position) {
      // We expect the skip to be satisfied in full. If it isn't then we're probably trying to
      // skip beyond the end of the data.
      throw new EOFException();
    }
    if (dataSpec.length != C.LENGTH_UNSET) {
      bytesRemaining = dataSpec.length;
    } else {
      long assetFileDescriptorLength = assetFileDescriptor.getLength();
      if (assetFileDescriptorLength == AssetFileDescriptor.UNKNOWN_LENGTH) {
        // The asset must extend to the end of the file. If FileInputStream.getChannel().size()
        // returns 0 then the remaining length cannot be determined.
        FileChannel channel = inputStream.getChannel();
        long channelSize = channel.size();
        bytesRemaining = channelSize == 0 ? C.LENGTH_UNSET : channelSize - channel.position();
      } else {
        bytesRemaining = assetFileDescriptorLength - skipped;
      }
    }
  } catch (IOException e) {
    throw new ContentDataSourceException(e);
  }

  opened = true;
  transferStarted(dataSpec);

  return bytesRemaining;
}
 
源代码6 项目: storage-samples   文件: MyCloudProvider.java
@Override
public AssetFileDescriptor openDocumentThumbnail(String documentId, Point sizeHint,
                                                 CancellationSignal signal)
        throws FileNotFoundException {
    Log.v(TAG, "openDocumentThumbnail");

    final File file = getFileForDocId(documentId);
    final ParcelFileDescriptor pfd =
            ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
    return new AssetFileDescriptor(pfd, 0, AssetFileDescriptor.UNKNOWN_LENGTH);
}
 
源代码7 项目: Shelter   文件: CrossProfileDocumentsProvider.java
@Override
public AssetFileDescriptor openDocumentThumbnail(String documentId, Point sizeHint, CancellationSignal signal) {
    ensureServiceBound();
    try {
        return new AssetFileDescriptor(
                mService.openThumbnail(documentId, sizeHint), 0, AssetFileDescriptor.UNKNOWN_LENGTH);
    } catch (RemoteException e) {
        return null;
    }
}
 
源代码8 项目: TelePlus-Android   文件: ContentDataSource.java
@Override
public long open(DataSpec dataSpec) throws ContentDataSourceException {
  try {
    uri = dataSpec.uri;
    transferInitializing(dataSpec);
    assetFileDescriptor = resolver.openAssetFileDescriptor(uri, "r");
    if (assetFileDescriptor == null) {
      throw new FileNotFoundException("Could not open file descriptor for: " + uri);
    }
    inputStream = new FileInputStream(assetFileDescriptor.getFileDescriptor());
    long assetStartOffset = assetFileDescriptor.getStartOffset();
    long skipped = inputStream.skip(assetStartOffset + dataSpec.position) - assetStartOffset;
    if (skipped != dataSpec.position) {
      // We expect the skip to be satisfied in full. If it isn't then we're probably trying to
      // skip beyond the end of the data.
      throw new EOFException();
    }
    if (dataSpec.length != C.LENGTH_UNSET) {
      bytesRemaining = dataSpec.length;
    } else {
      long assetFileDescriptorLength = assetFileDescriptor.getLength();
      if (assetFileDescriptorLength == AssetFileDescriptor.UNKNOWN_LENGTH) {
        // The asset must extend to the end of the file. If FileInputStream.getChannel().size()
        // returns 0 then the remaining length cannot be determined.
        FileChannel channel = inputStream.getChannel();
        long channelSize = channel.size();
        bytesRemaining = channelSize == 0 ? C.LENGTH_UNSET : channelSize - channel.position();
      } else {
        bytesRemaining = assetFileDescriptorLength - skipped;
      }
    }
  } catch (IOException e) {
    throw new ContentDataSourceException(e);
  }

  opened = true;
  transferStarted(dataSpec);

  return bytesRemaining;
}
 
源代码9 项目: FireFiles   文件: AppsProvider.java
@Override
public AssetFileDescriptor openDocumentThumbnail(
        String docId, Point sizeHint, CancellationSignal signal) throws FileNotFoundException {
    // TODO: extend ExifInterface to support fds
    final ParcelFileDescriptor pfd = openDocument(docId, "r", signal);
    return new AssetFileDescriptor(pfd, 0, AssetFileDescriptor.UNKNOWN_LENGTH);
}
 
源代码10 项目: FireFiles   文件: AppsProvider.java
@Override
public AssetFileDescriptor openDocumentThumbnail(
        String docId, Point sizeHint, CancellationSignal signal) throws FileNotFoundException {
    // TODO: extend ExifInterface to support fds
    final ParcelFileDescriptor pfd = openDocument(docId, "r", signal);
    return new AssetFileDescriptor(pfd, 0, AssetFileDescriptor.UNKNOWN_LENGTH);
}
 
源代码11 项目: FireFiles   文件: AppsProvider.java
@Override
public AssetFileDescriptor openDocumentThumbnail(
        String docId, Point sizeHint, CancellationSignal signal) throws FileNotFoundException {
    // TODO: extend ExifInterface to support fds
    final ParcelFileDescriptor pfd = openDocument(docId, "r", signal);
    return new AssetFileDescriptor(pfd, 0, AssetFileDescriptor.UNKNOWN_LENGTH);
}
 
源代码12 项目: Telegram-FOSS   文件: ContentDataSource.java
@Override
public long open(DataSpec dataSpec) throws ContentDataSourceException {
  try {
    uri = dataSpec.uri;
    transferInitializing(dataSpec);
    assetFileDescriptor = resolver.openAssetFileDescriptor(uri, "r");
    if (assetFileDescriptor == null) {
      throw new FileNotFoundException("Could not open file descriptor for: " + uri);
    }
    inputStream = new FileInputStream(assetFileDescriptor.getFileDescriptor());
    long assetStartOffset = assetFileDescriptor.getStartOffset();
    long skipped = inputStream.skip(assetStartOffset + dataSpec.position) - assetStartOffset;
    if (skipped != dataSpec.position) {
      // We expect the skip to be satisfied in full. If it isn't then we're probably trying to
      // skip beyond the end of the data.
      throw new EOFException();
    }
    if (dataSpec.length != C.LENGTH_UNSET) {
      bytesRemaining = dataSpec.length;
    } else {
      long assetFileDescriptorLength = assetFileDescriptor.getLength();
      if (assetFileDescriptorLength == AssetFileDescriptor.UNKNOWN_LENGTH) {
        // The asset must extend to the end of the file. If FileInputStream.getChannel().size()
        // returns 0 then the remaining length cannot be determined.
        FileChannel channel = inputStream.getChannel();
        long channelSize = channel.size();
        bytesRemaining = channelSize == 0 ? C.LENGTH_UNSET : channelSize - channel.position();
      } else {
        bytesRemaining = assetFileDescriptorLength - skipped;
      }
    }
  } catch (IOException e) {
    throw new ContentDataSourceException(e);
  }

  opened = true;
  transferStarted(dataSpec);

  return bytesRemaining;
}
 
源代码13 项目: android-StorageProvider   文件: MyCloudProvider.java
@Override
public AssetFileDescriptor openDocumentThumbnail(String documentId, Point sizeHint,
                                                 CancellationSignal signal)
        throws FileNotFoundException {
    Log.v(TAG, "openDocumentThumbnail");

    final File file = getFileForDocId(documentId);
    final ParcelFileDescriptor pfd =
            ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
    return new AssetFileDescriptor(pfd, 0, AssetFileDescriptor.UNKNOWN_LENGTH);
}
 
源代码14 项目: codeexamples-android   文件: FileProvider.java
@Override
public AssetFileDescriptor openAssetFile(Uri uri, String mode) throws FileNotFoundException {
    // Try to open an asset with the given name.
    try {
        InputStream is = getContext().getAssets().open(uri.getPath());
        // Start a new thread that pipes the stream data back to the caller.
        return new AssetFileDescriptor(
                openPipeHelper(uri, null, null, is, this), 0,
                AssetFileDescriptor.UNKNOWN_LENGTH);
    } catch (IOException e) {
        FileNotFoundException fnf = new FileNotFoundException("Unable to open " + uri);
        throw fnf;
    }
}
 
源代码15 项目: Telegram   文件: ContentDataSource.java
@Override
public long open(DataSpec dataSpec) throws ContentDataSourceException {
  try {
    uri = dataSpec.uri;
    transferInitializing(dataSpec);
    assetFileDescriptor = resolver.openAssetFileDescriptor(uri, "r");
    if (assetFileDescriptor == null) {
      throw new FileNotFoundException("Could not open file descriptor for: " + uri);
    }
    inputStream = new FileInputStream(assetFileDescriptor.getFileDescriptor());
    long assetStartOffset = assetFileDescriptor.getStartOffset();
    long skipped = inputStream.skip(assetStartOffset + dataSpec.position) - assetStartOffset;
    if (skipped != dataSpec.position) {
      // We expect the skip to be satisfied in full. If it isn't then we're probably trying to
      // skip beyond the end of the data.
      throw new EOFException();
    }
    if (dataSpec.length != C.LENGTH_UNSET) {
      bytesRemaining = dataSpec.length;
    } else {
      long assetFileDescriptorLength = assetFileDescriptor.getLength();
      if (assetFileDescriptorLength == AssetFileDescriptor.UNKNOWN_LENGTH) {
        // The asset must extend to the end of the file. If FileInputStream.getChannel().size()
        // returns 0 then the remaining length cannot be determined.
        FileChannel channel = inputStream.getChannel();
        long channelSize = channel.size();
        bytesRemaining = channelSize == 0 ? C.LENGTH_UNSET : channelSize - channel.position();
      } else {
        bytesRemaining = assetFileDescriptorLength - skipped;
      }
    }
  } catch (IOException e) {
    throw new ContentDataSourceException(e);
  }

  opened = true;
  transferStarted(dataSpec);

  return bytesRemaining;
}
 
源代码16 项目: MediaSDK   文件: ContentDataSource.java
@Override
public long open(DataSpec dataSpec) throws ContentDataSourceException {
  try {
    Uri uri = dataSpec.uri;
    this.uri = uri;

    transferInitializing(dataSpec);
    AssetFileDescriptor assetFileDescriptor = resolver.openAssetFileDescriptor(uri, "r");
    this.assetFileDescriptor = assetFileDescriptor;
    if (assetFileDescriptor == null) {
      throw new FileNotFoundException("Could not open file descriptor for: " + uri);
    }
    FileInputStream inputStream = new FileInputStream(assetFileDescriptor.getFileDescriptor());
    this.inputStream = inputStream;

    long assetStartOffset = assetFileDescriptor.getStartOffset();
    long skipped = inputStream.skip(assetStartOffset + dataSpec.position) - assetStartOffset;
    if (skipped != dataSpec.position) {
      // We expect the skip to be satisfied in full. If it isn't then we're probably trying to
      // skip beyond the end of the data.
      throw new EOFException();
    }
    if (dataSpec.length != C.LENGTH_UNSET) {
      bytesRemaining = dataSpec.length;
    } else {
      long assetFileDescriptorLength = assetFileDescriptor.getLength();
      if (assetFileDescriptorLength == AssetFileDescriptor.UNKNOWN_LENGTH) {
        // The asset must extend to the end of the file. If FileInputStream.getChannel().size()
        // returns 0 then the remaining length cannot be determined.
        FileChannel channel = inputStream.getChannel();
        long channelSize = channel.size();
        bytesRemaining = channelSize == 0 ? C.LENGTH_UNSET : channelSize - channel.position();
      } else {
        bytesRemaining = assetFileDescriptorLength - skipped;
      }
    }
  } catch (IOException e) {
    throw new ContentDataSourceException(e);
  }

  opened = true;
  transferStarted(dataSpec);

  return bytesRemaining;
}