コード例 #1
0
  public static InputStream openCachedStream(URI uri) {
    TiResponseCache rc = (TiResponseCache) TiResponseCache.getDefault();
    if (rc == null) {
      return null;
    }

    if (rc.cacheDir == null) {
      return null;
    }

    String hash = DigestUtils.shaHex(uri.toString());
    File hFile = new File(rc.cacheDir, hash + HEADER_SUFFIX);
    File bFile = new File(rc.cacheDir, hash + BODY_SUFFIX);

    if (!bFile.exists() || !hFile.exists()) {
      return null;
    }

    try {
      return new FileInputStream(bFile);
    } catch (FileNotFoundException e) {
      // Fallback to URL download?
      return null;
    }
  }
コード例 #2
0
  public static void remove(URI uri) {
    TiResponseCache rc = (TiResponseCache) TiResponseCache.getDefault();
    if (rc == null) return;
    if (rc.cacheDir == null) return;

    String hash = DigestUtils.shaHex(uri.toString());
    File hFile = new File(rc.cacheDir, hash + HEADER_SUFFIX);
    File bFile = new File(rc.cacheDir, hash + BODY_SUFFIX);
    if (bFile.exists()) bFile.delete();
    if (hFile.exists()) hFile.delete();
  }
コード例 #3
0
  public static boolean peek(URI uri) {
    TiResponseCache rc = (TiResponseCache) TiResponseCache.getDefault();
    if (rc == null) return false;
    if (rc.cacheDir == null) return false;

    String hash = DigestUtils.shaHex(uri.toString());
    File hFile = new File(rc.cacheDir, hash + HEADER_SUFFIX);
    File bFile = new File(rc.cacheDir, hash + BODY_SUFFIX);
    if (!bFile.exists() || !hFile.exists()) return false;
    return true;
  }