Ejemplo n.º 1
0
  public static Io_stream_rdr Get_rdr_or_null(
      Io_url src_fil, Io_url src_dir, Io_stream_unzip_mgr unzip_mgr, String... filter_ary) {
    IoItmFil src_itm = null;
    if (src_fil != null) src_itm = Io_mgr.I.QueryFil(src_fil);

    // specified file doesn't exist; try to find similar file based on filter
    if (src_itm == null || !src_itm.Exists()) {
      src_itm = Get_itm_by_filters(src_dir, filter_ary);
      if (src_itm == null) return null;
    }

    // return rdr
    Io_url src_itm_url = src_itm.Url();
    Io_stream_rdr rv =
        unzip_mgr.Handles(src_itm_url)
            ? unzip_mgr.New_rdr(src_itm_url)
            : Io_stream_rdr_.file_(src_itm_url);
    rv.Len_(src_itm.Size());
    return rv;
  }
Ejemplo n.º 2
0
  private static IoItmFil Get_itm_by_filters(Io_url dir, String... filter_ary) {
    // create array of matches based on filters
    int match_ary_len = filter_ary.length;
    Criteria_ioMatch[] match_ary = new Criteria_ioMatch[match_ary_len];
    for (int i = 0; i < match_ary_len; ++i)
      match_ary[i] = Criteria_ioMatch.parse_(true, filter_ary[i], dir.Info().CaseSensitive());

    // get files and check each file for match
    IoItmFil rv = null;
    IoItmHash itm_hash = Io_mgr.I.QueryDir_args(dir).ExecAsItmHash();
    int len = itm_hash.Count();
    for (int i = 0; i < len; ++i) {
      IoItm_base itm = itm_hash.Get_at(i);
      for (int j = 0; j < match_ary_len; ++j) {
        if (itm.Type_fil() && match_ary[j].Matches(itm.Url()))
          rv =
              (IoItmFil)
                  itm; // NOTE: this will return the last match; useful for getting latest dump when
                       // multiple dumps are in one dir; (assuming latest should alphabetize last)
      }
    }
    return rv;
  }