Exemplo n.º 1
0
  public static boolean isBreakpointAvailable(
      final int id, final FileDownloadModel model, final String path) {
    boolean result = false;

    do {
      if (path == null) {
        if (FileDownloadLog.NEED_LOG) {
          FileDownloadLog.d(FileDownloadMgr.class, "can't continue %d path = null", id);
        }
        break;
      }

      File file = new File(path);
      final boolean isExists = file.exists();
      final boolean isDirectory = file.isDirectory();

      if (!isExists || isDirectory) {
        if (FileDownloadLog.NEED_LOG) {
          FileDownloadLog.d(
              FileDownloadMgr.class,
              "can't continue %d file not suit, exists[%B], directory[%B]",
              id,
              isExists,
              isDirectory);
        }
        break;
      }

      final long fileLength = file.length();

      if (model.getSoFar() == 0) {
        if (FileDownloadLog.NEED_LOG) {
          FileDownloadLog.d(
              FileDownloadMgr.class, "can't continue %d the downloaded-record is zero.", id);
        }
        break;
      }

      if (fileLength < model.getSoFar()
          || (model.getTotal() != -1 // not chunk transfer encoding data
              && (fileLength > model.getTotal() || model.getSoFar() >= model.getTotal()))) {
        // dirty data.
        if (FileDownloadLog.NEED_LOG) {
          FileDownloadLog.d(
              FileDownloadMgr.class,
              "can't continue %d dirty data" + " fileLength[%d] sofar[%d] total[%d]",
              id,
              fileLength,
              model.getSoFar(),
              model.getTotal());
        }
        break;
      }

      result = true;
    } while (false);

    return result;
  }
Exemplo n.º 2
0
  public long getSoFar(final int id) {
    final FileDownloadModel model = mHelper.find(id);
    if (model == null) {
      return 0;
    }

    return model.getSoFar();
  }