當前位置: 首頁>>代碼示例>>Java>>正文


Java AssetFileDescriptor.getLength方法代碼示例

本文整理匯總了Java中android.content.res.AssetFileDescriptor.getLength方法的典型用法代碼示例。如果您正苦於以下問題:Java AssetFileDescriptor.getLength方法的具體用法?Java AssetFileDescriptor.getLength怎麽用?Java AssetFileDescriptor.getLength使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.content.res.AssetFileDescriptor的用法示例。


在下文中一共展示了AssetFileDescriptor.getLength方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getLength

import android.content.res.AssetFileDescriptor; //導入方法依賴的package包/類
private int getLength(ImageRequest imageRequest) {
  AssetFileDescriptor fd = null;
  try {
    fd = mResources.openRawResourceFd(getResourceId(imageRequest));
    return (int) fd.getLength();
  } catch (Resources.NotFoundException e) {
    return -1;
  } finally {
    try {
      if (fd != null) {
        fd.close();
      }
    } catch (IOException ignored) {
      // There's nothing we can do with the exception when closing descriptor.
    }
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:LocalResourceFetchProducer.java

示例2: getLength

import android.content.res.AssetFileDescriptor; //導入方法依賴的package包/類
private int getLength(ImageRequest imageRequest) {
  AssetFileDescriptor fd = null;
  try {
    fd = mAssetManager.openFd(getAssetName(imageRequest));
    return (int) fd.getLength();
  } catch (IOException e) {
    return -1;
  } finally {
    try {
      if (fd != null) {
        fd.close();
      }
    } catch (IOException ignored) {
      // There's nothing we can do with the exception when closing descriptor.
    }
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:LocalAssetFetchProducer.java

示例3: open

import android.content.res.AssetFileDescriptor; //導入方法依賴的package包/類
@CalledByNative
public static long[] open(Context context, String fileName) {
    AssetFileDescriptor afd = null;
    try {
        AssetManager manager = context.getAssets();
        afd = manager.openNonAssetFd(fileName);
        return new long[] { afd.getParcelFileDescriptor().detachFd(),
                            afd.getStartOffset(),
                            afd.getLength() };
    } catch (IOException e) {
        // As a general rule there's no point logging here because the caller should handle
        // receiving an fd of -1 sensibly, and the log message is either mirrored later, or
        // unwanted (in the case where a missing file is expected), or wanted but will be
        // ignored, as most non-fatal logs are.
        // It makes sense to log here when the file exists, but is unable to be opened as an fd
        // because (for example) it is unexpectedly compressed in an apk. In that case, the log
        // message might save someone some time working out what has gone wrong.
        // For that reason, we only suppress the message when the exception message doesn't look
        // informative (Android framework passes the filename as the message on actual file not
        // found, and the empty string also wouldn't give any useful information for debugging).
        if (!e.getMessage().equals("") && !e.getMessage().equals(fileName)) {
            Log.e(LOGTAG, "Error while loading asset " + fileName + ": " + e);
        }
        return new long[] {-1, -1, -1};
    } finally {
        try {
            if (afd != null) {
                afd.close();
            }
        } catch (IOException e2) {
            Log.e(LOGTAG, "Unable to close AssetFileDescriptor", e2);
        }
    }
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:35,代碼來源:ApkAssets.java

示例4: load

import android.content.res.AssetFileDescriptor; //導入方法依賴的package包/類
@Override public Result load(Request request, int networkPolicy) throws IOException {
  String imagePath = request.uri.getPath().substring(1); // Grab only the path sans leading slash.

  // Check the disk cache for the image. A non-null return value indicates a hit.
  boolean cacheHit = emulatedDiskCache.get(imagePath) != null;

  // If there's a hit, grab the image stream and return it.
  if (cacheHit) {
    return new Result(loadBitmap(imagePath), Picasso.LoadedFrom.DISK);
  }

  // If we are not allowed to hit the network and the cache missed return a big fat nothing.
  if (NetworkPolicy.isOfflineOnly(networkPolicy)) {
    return null;
  }

  // If we got this far there was a cache miss and hitting the network is required. See if we need
  // to fake an network error.
  if (behavior.calculateIsFailure()) {
    SystemClock.sleep(behavior.calculateDelay(MILLISECONDS));
    throw new IOException("Fake network error!");
  }

  // We aren't throwing a network error so fake a round trip delay.
  SystemClock.sleep(behavior.calculateDelay(MILLISECONDS));

  // Since we cache missed put it in the LRU.
  AssetFileDescriptor fileDescriptor = assetManager.openFd(imagePath);
  long size = fileDescriptor.getLength();
  fileDescriptor.close();

  emulatedDiskCache.put(imagePath, size);

  // Grab the image stream and return it.
  return new Result(loadBitmap(imagePath), Picasso.LoadedFrom.NETWORK);
}
 
開發者ID:rogues-dev,項目名稱:superglue,代碼行數:37,代碼來源:MockRequestHandler.java

示例5: loadMediaPlayer

import android.content.res.AssetFileDescriptor; //導入方法依賴的package包/類
/**
 * Loads the audio or video specified by mediaPath into the given
 * MediaPlayer.
 *
 * @param mediaPlayer the MediaPlayer
 * @param form the Form
 * @param mediaPath the path to the media
 */
public static void loadMediaPlayer(MediaPlayer mediaPlayer, Form form, String mediaPath)
    throws IOException {
  MediaSource mediaSource = determineMediaSource(form, mediaPath);
  switch (mediaSource) {
    case ASSET:
      AssetFileDescriptor afd = getAssetsIgnoreCaseAfd(form,mediaPath);
      try {
        FileDescriptor fd = afd.getFileDescriptor();
        long offset = afd.getStartOffset();
        long length = afd.getLength();
        mediaPlayer.setDataSource(fd, offset, length);
      } finally {
        afd.close();
      }
      return;


    case REPL_ASSET:
      mediaPlayer.setDataSource(replAssetPath(mediaPath));
      return;

    case SDCARD:
      mediaPlayer.setDataSource(mediaPath);
      return;

    case FILE_URL:
      mediaPlayer.setDataSource(fileUrlToFilePath(mediaPath));
      return;

    case URL:
      // This works both for streaming and non-streaming.
      // TODO(halabelson): Think about whether we could get improved
      // performance if we did buffering control.
      mediaPlayer.setDataSource(mediaPath);
      return;

    case CONTENT_URI:
      mediaPlayer.setDataSource(form, Uri.parse(mediaPath));
      return;

    case CONTACT_URI:
      throw new IOException("Unable to load audio or video for contact " + mediaPath + ".");
  }
  throw new IOException("Unable to load audio or video " + mediaPath + ".");
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:54,代碼來源:MediaUtil.java

示例6: getFileSize

import android.content.res.AssetFileDescriptor; //導入方法依賴的package包/類
/**
 * 獲取assets下文件內容長度
 *
 * @param pContext
 * @param pFilePath 文件路徑, 如"assets/fonts/zh.ttf"傳入"fonts/zh.ttf"
 * @return 文件長度
 */
public static final long getFileSize(Context pContext, String pFilePath) {
    AssetFileDescriptor fileDescriptor = getAssetFileDescriptor(pContext, pFilePath);
    return fileDescriptor.getLength();
}
 
開發者ID:zeng3234,項目名稱:GrowingProject,代碼行數:12,代碼來源:AssetUtils.java


注:本文中的android.content.res.AssetFileDescriptor.getLength方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。