Example #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;
  }
 private void Download_exec(Xodb_tbl_oimg_xfer_itm fsdb) {
   Io_stream_rdr src_rdr = src_bin_mgr.Find_as_rdr(Xof_exec_tid.Tid_wiki_page, fsdb);
   try {
     if (src_rdr == Io_stream_rdr_.Noop) { // download failed
       ++exec_fail;
       usr_dlg.Warn_many(
           "",
           "",
           "failed: ttl=~{0}",
           String_.Format("[[File:{0}|{1}px]]", fsdb.Orig_ttl(), fsdb.Html_w()));
       Print_progress(fsdb);
     } else { // download passed
       long src_rdr_len = src_rdr.Len();
       int lnki_tier_id = fsdb.Lnki_tier_id();
       if (src_rdr_len > download_size_max && !Int_.In(lnki_tier_id, download_keep_tier_ids)) {
         usr_dlg.Warn_many(
             "",
             "",
             "skipped; ttl=~{0} w=~{1} size=~{2} tier=~{3}",
             fsdb.Orig_ttl(),
             fsdb.Lnki_w(),
             src_rdr_len,
             lnki_tier_id);
         return;
       }
       if (trg_bin_fil == null) // no trg_bin_fil
       Make_trg_bin_file(Bool_.Y, fsdb, src_rdr_len);
       else if (trg_bin_fil.Bin_len() + src_rdr_len
           > trg_bin_db_max) // or trg_bin_fil is out of space
       Make_trg_bin_file(Bool_.N, fsdb, src_rdr_len);
       else if (prv_lnki_tier_id != lnki_tier_id) { // or tier has changed
         if (prv_lnki_tier_id != -1 && !bin_db_mgr.Schema_is_1()) // do not increment dbs for v1
         Make_trg_bin_file(Bool_.Y, fsdb, src_rdr_len);
         prv_lnki_tier_id = lnki_tier_id;
       }
       trg_bin_updater.Save_bin(trg_mnt_itm, trg_atr_fil, trg_bin_fil, fsdb, src_rdr, src_rdr_len);
     }
   } finally {
     src_rdr.Rls();
   }
 }