1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

'v3.6.3.1'

This commit is contained in:
gnosygnu
2016-06-19 23:58:10 -04:00
parent 96636f3161
commit d4e8590345
1960 changed files with 20790 additions and 9272 deletions

View File

@@ -17,11 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.brys; import gplx.*; import gplx.core.*;
public class Bit_heap_wtr {
private final gplx.xowa.htmls.core.hzips.Xoh_hzip_int hzip_int = new gplx.xowa.htmls.core.hzips.Xoh_hzip_int().Mode_is_b256_(true);
private final Bry_bfr hzip_int_bfr = Bry_bfr.reset_(5);
private final gplx.xowa.htmls.core.hzips.Xoh_hzip_int hzip_int = new gplx.xowa.htmls.core.hzips.Xoh_hzip_int().Mode_is_b256_(true);
private final Bry_bfr hzip_int_bfr = Bry_bfr_.Reset(5);
public int Cur() {return cur;} private int cur;
public int Cur_bits() {return cur_bits;} private int cur_bits;
public Bry_bfr Heap() {return heap;} private final Bry_bfr heap = Bry_bfr.new_();
public Bry_bfr Heap() {return heap;} private final Bry_bfr heap = Bry_bfr_.New();
public void Clear() {heap.Clear(); cur = 0; cur_bits = 0;}
public void Add_bool(boolean v) {
if (v)
@@ -67,5 +67,5 @@ public class Bit_heap_wtr {
hzip_int_bfr.Clear();
}
public void Save(Bry_bfr bfr) {}
public static final int[] Pow_ary = new int[] {1, 2, 4, 8, 16, 32, 64, 128, 256};
public static final int[] Pow_ary = new int[] {1, 2, 4, 8, 16, 32, 64, 128, 256};
}

View File

@@ -0,0 +1,108 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.brys.evals; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
public class Bry_eval_mgr {
private final Hash_adp_bry hash = Hash_adp_bry.cs();
private final byte sym_escape, sym_key_end, sym_grp_bgn, sym_grp_end;
public Bry_eval_mgr(byte sym_escape, byte sym_key_end, byte sym_grp_bgn, byte sym_grp_end) {
this.sym_escape = sym_escape;
this.sym_key_end = sym_key_end;
this.sym_grp_bgn = sym_grp_bgn;
this.sym_grp_end = sym_grp_end;
}
public Bry_eval_mgr Add_many(Bry_eval_wkr... ary) {
for (Bry_eval_wkr itm : ary)
hash.Add(Bry_.new_u8(itm.Key()), itm);
return this;
}
public byte[] Eval(byte[] src) {
Bry_eval_rslt rv = Eval_txt(0, src, 0, src.length);
return rv == null ? src : rv.Bry();
}
private Bry_eval_rslt Eval_txt(int depth, byte[] src, int src_bgn, int src_end) {
Bry_bfr cur_bfr = null;
int cur_pos = src_bgn;
while (true) {
if (cur_pos == src_end) break;
byte cur_byte = src[cur_pos];
// cur_byte is ~
if (cur_byte == sym_escape) {
// create cur_bfr
if (cur_bfr == null) {cur_bfr = Bry_bfr_.New(); cur_bfr.Add_mid(src, src_bgn, cur_pos);}
// eval nxt_byte
int nxt_pos = cur_pos + 1;
if (nxt_pos == src_end) throw Err_.new_wo_type("bry_eval:escape at eos", "src", src);
byte nxt_byte = src[nxt_pos];
if (nxt_byte == sym_grp_bgn) { // ~{key|} -> eval;
Bry_eval_rslt sub = Eval_txt(depth + 1, src, nxt_pos + 1, src_end); // get "}"
cur_bfr.Add(Eval_grp(sub.Bry()));
cur_pos = sub.Pos();
continue;
}
else if (nxt_byte == sym_escape) {
cur_bfr.Add_byte(nxt_byte);
cur_pos = nxt_pos + 1;
continue;
}
}
else if (depth > 0 && cur_byte == sym_grp_end) {
return cur_bfr == null
? new Bry_eval_rslt(Bry_.Mid(src, src_bgn, cur_pos), cur_pos + 1)
: new Bry_eval_rslt(cur_bfr.To_bry_and_clear(), cur_pos + 1);
}
if (cur_bfr != null) cur_bfr.Add_byte(cur_byte);
++cur_pos;
}
return cur_bfr == null ? null : new Bry_eval_rslt(cur_bfr.To_bry_and_clear(), src_end);
}
private byte[] Eval_grp(byte[] src) {
// search for "|" or "}"
boolean args_is_empty = true;
int src_end = src.length;
int key_bgn = 0, key_end = src_end;
for (int i = key_bgn; i < src_end; ++i) {
int key_end_byte = src[i];
if (key_end_byte == sym_key_end) {
key_end = i;
args_is_empty = false;
break;
}
}
// get wkr
Bry_eval_wkr wkr = (Bry_eval_wkr)hash.Get_by_mid(src, key_bgn, key_end);
if (wkr == null) throw Err_.new_wo_type("bry_eval:key not found", "src", src);
Bry_bfr bfr = Bry_bfr_.New();
if (args_is_empty) {
wkr.Resolve(bfr, src, -1, -1);
}
else {
wkr.Resolve(bfr, src, key_end + 1, src_end);
}
return bfr.To_bry_and_clear();
}
public static Bry_eval_mgr Dflt() {return new Bry_eval_mgr(Byte_ascii.Tilde, Byte_ascii.Pipe, Byte_ascii.Curly_bgn, Byte_ascii.Curly_end);}
}
class Bry_eval_rslt {
public Bry_eval_rslt(byte[] bry, int pos) {
this.bry = bry; this.pos = pos;
}
public byte[] Bry() {return bry;} private final byte[] bry;
public int Pos() {return pos;} private final int pos;
}

View File

@@ -0,0 +1,52 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.brys.evals; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
import org.junit.*; import gplx.core.tests.*;
public class Bry_eval_mgr__tst {
private final Bry_eval_mgr__fxt fxt = new Bry_eval_mgr__fxt();
@Test public void Text() {fxt.Test__eval("abc" , "abc");}
@Test public void Args_0() {fxt.Test__eval("abc~{test}xyz" , "abctestxyz");}
@Test public void Args_n() {fxt.Test__eval("abc~{concat|d|e|f}xyz" , "abcdefxyz");}
@Test public void Recur_1() {fxt.Test__eval("abc~{~{test}}xyz" , "abctestxyz");}
@Test public void Recur_2() {fxt.Test__eval("abc~{t~{concat|e|s}t}xyz" , "abctestxyz");}
@Test public void Grp_end() {fxt.Test__eval("a}b" , "a}b");}
@Test public void Escape() {fxt.Test__eval("a~~b" , "a~b");}
// @Test public void Eos() {fxt.Test__eval("a~" , "a~");}
}
class Bry_eval_mgr__fxt {
private final Bry_eval_mgr mgr = Bry_eval_mgr.Dflt().Add_many(new Bry_eval_wkr__test(), new Bry_eval_wkr__concat());
public Bry_eval_mgr__fxt Test__eval(String raw, String expd) {
Gftest.Eq__bry(Bry_.new_u8(expd), mgr.Eval(Bry_.new_u8(raw)));
return this;
}
}
class Bry_eval_wkr__test implements Bry_eval_wkr {
public String Key() {return "test";}
public void Resolve(Bry_bfr rv, byte[] src, int src_bgn, int src_end) {
rv.Add_str_a7("test");
}
}
class Bry_eval_wkr__concat implements Bry_eval_wkr {
public String Key() {return "concat";}
public void Resolve(Bry_bfr rv, byte[] src, int src_bgn, int src_end) {
byte[][] ary = Bry_split_.Split(src, src_bgn, src_end, Byte_ascii.Pipe, false);
for (byte[] itm : ary) {
rv.Add(itm);
}
}
}

View File

@@ -0,0 +1,22 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.brys.evals; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
public interface Bry_eval_wkr {
String Key();
void Resolve(Bry_bfr rv, byte[] src, int args_bgn, int args_end);
}

View File

@@ -77,7 +77,7 @@ public class Gfo_cache_mgr {
Console_adp__sys.Instance.Write_str_w_nl("compacting:");
// hash.Sort();
// int len = hash.Count();
// List_adp deleted = List_adp_.new_();
// List_adp deleted = List_adp_.New();
// int deleted_size = 0, deleted_count = 0;
// for (int i = 0; i < len; i++) {
// Gfo_cache_data itm = (Gfo_cache_data)hash.Get_at(i);

View File

@@ -35,7 +35,7 @@ public class Gfo_cache_mgr_base {
public void Compress() {
hash.Sort_by(Gfo_cache_itm_comparer.Touched_asc);
int del_len = hash.Count() - compress_to;
List_adp del_list = List_adp_.new_();
List_adp del_list = List_adp_.New();
for (int i = 0; i < del_len; i++) {
Gfo_cache_itm itm = (Gfo_cache_itm)hash.Get_at(i);
del_list.Add(itm);

View File

@@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.consoles; import gplx.*; import gplx.core.*;
public class Gfo_cmd_arg_mgr {
private final Ordered_hash hash = Ordered_hash_.New();
private final List_adp err_list = List_adp_.new_(), tmp_vals = List_adp_.new_();
private final Ordered_hash hash = Ordered_hash_.New();
private final List_adp err_list = List_adp_.New(), tmp_vals = List_adp_.New();
public String[] Orig_ary() {return orig_ary;} private String[] orig_ary;
public void Reset() {
hash.Clear();

View File

@@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.consoles; import gplx.*; import gplx.core.*;
public class Gfo_cmd_arg_mgr_printer {
private final Gfo_cmd_arg_mgr arg_mgr;
private final Bry_bfr tmp_bfr = Bry_bfr.new_();
private final Gfo_cmd_arg_mgr arg_mgr;
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
public Gfo_cmd_arg_mgr_printer(Gfo_cmd_arg_mgr arg_mgr) {this.arg_mgr = arg_mgr;}
public boolean Print(Gfo_usr_dlg usr_dlg, String header, String app_name, String key__print_help, String key__print_header, String key__print_args) {
if (arg_mgr.Get_by_as_bool(key__print_header))

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.core.flds; import gplx.*; import gplx.core.*;
import gplx.core.encoders.*;
public class Gfo_fld_rdr extends Gfo_fld_base {
private Bry_bfr bfr = Bry_bfr.new_(); private static final byte[] Bry_nil = Bry_.new_a7("\\0");
private Bry_bfr bfr = Bry_bfr_.New(); private static final byte[] Bry_nil = Bry_.new_a7("\\0");
public byte[] Data() {return data;} public Gfo_fld_rdr Data_(byte[] v) {data = v; data_len = v.length; pos = 0; return this;} private byte[] data; int data_len;
public int Pos() {return pos;} public Gfo_fld_rdr Pos_(int v) {pos = v; return this;} private int pos;
public int Fld_bgn() {return fld_bgn;} public Gfo_fld_rdr Fld_bgn_(int v) {fld_bgn = v; return this;} private int fld_bgn;

View File

@@ -52,5 +52,5 @@ class Gfo_fld_rdr_fxt {
wtr.Write_bry_escape_fld(bry);
Tfds.Eq(expd, bfr.To_str());
return this;
} private Bry_bfr bfr = Bry_bfr.new_();
} private Bry_bfr bfr = Bry_bfr_.New();
}

View File

@@ -19,7 +19,7 @@ package gplx.core.flds; import gplx.*; import gplx.core.*;
import gplx.core.ios.*; import gplx.core.encoders.*;
public class Gfo_fld_wtr extends Gfo_fld_base {
public Bry_bfr Bfr() {return bfr;} public Gfo_fld_wtr Bfr_(Bry_bfr v) {bfr = v; return this;} Bry_bfr bfr;
public Gfo_fld_wtr() {this.bfr = Bry_bfr.new_();}
public Gfo_fld_wtr() {this.bfr = Bry_bfr_.New();}
public Gfo_fld_wtr Write_int_base85_len5_fld(int v) {bfr.Add_base85(v, Base85_.Len_int); bfr.Add_byte(fld_dlm); return this;}
public Gfo_fld_wtr Write_int_base85_lenN_fld(int v, int len) {bfr.Add_base85(v, len); bfr.Add_byte(fld_dlm); return this;}
public Gfo_fld_wtr Write_int_variable_fld(int v) {bfr.Add_int_variable(v); bfr.Add_byte(fld_dlm); return this;}

View File

@@ -16,31 +16,16 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
public interface Gfobj_ary extends Gfobj_grp {
byte Ary_tid();
int Len();
}
class Gfo_ary_str implements Gfobj_ary {
public Gfo_ary_str(String[] ary) {this.ary = ary;}
public byte Grp_tid() {return Gfobj_grp_.Grp_tid__ary;}
public byte Ary_tid() {return Gfobj_ary_.Ary_tid__str;}
public int Len() {return ary.length;}
public Object Get_at(int i) {return ary[i];}
public String[] Ary_str() {return ary;} private final String[] ary;
}
class Gfo_ary_int implements Gfobj_ary {
public Gfo_ary_int(int[] ary) {this.ary = ary;}
public byte Grp_tid() {return Gfobj_grp_.Grp_tid__ary;}
public byte Ary_tid() {return Gfobj_ary_.Ary_tid__int;}
public int Len() {return ary.length;}
public Object Get_at(int i) {return ary[i];}
public int[] Ary_int() {return ary;} private final int[] ary;
}
class Gfo_ary_ary implements Gfobj_ary {
public Gfo_ary_ary(Gfobj_ary[] ary) {this.ary = ary;}
public byte Grp_tid() {return Gfobj_grp_.Grp_tid__ary;}
public byte Ary_tid() {return Gfobj_ary_.Ary_tid__ary;}
public int Len() {return ary.length;}
public Object Get_at(int i) {return ary[i];}
public Gfobj_ary[] Ary_ary() {return ary;} private Gfobj_ary[] ary;
public class Gfobj_ary implements Gfobj_grp { // NOTE: items in array can vary in types; EX:['a', 1, false]
public Gfobj_ary(Object[] ary) {this.ary = ary;}
public byte Grp_tid() {return Gfobj_grp_.Grp_tid__ary;}
public int Len() {return ary.length;}
public Object Get_at(int i) {return ary[i];}
public Object[] Ary_obj() {return ary;} private Object[] ary;
public Gfobj_ary Ary_(Object[] v) {this.ary = v; return this;}
public Gfobj_nde New_nde_at(int i) {
Gfobj_nde rv = Gfobj_nde.New();
ary[i] = rv;
return rv;
}
}

View File

@@ -25,9 +25,11 @@ class Gfobj_fld_ {
public static final byte
Fld_tid__ary = 0
, Fld_tid__nde = 1
, Fld_tid__int = 2
, Fld_tid__long = 3
, Fld_tid__str = 4
, Fld_tid__bool = 2
, Fld_tid__int = 3
, Fld_tid__long = 4
, Fld_tid__double = 5
, Fld_tid__str = 6
;
}
class Gfobj_fld_str implements Gfobj_fld {
@@ -37,6 +39,13 @@ class Gfobj_fld_str implements Gfobj_fld {
public Object As_obj() {return val;}
public String As_str() {return val;} private String val;
}
class Gfobj_fld_bool implements Gfobj_fld {
public Gfobj_fld_bool(String key, boolean val) {this.key = key; this.val = val;}
public String Key() {return key;} private final String key;
public byte Fld_tid() {return Gfobj_fld_.Fld_tid__bool;}
public Object As_obj() {return val;}
public boolean As_bool() {return val;} private boolean val;
}
class Gfobj_fld_int implements Gfobj_fld {
public Gfobj_fld_int(String key, int val) {this.key = key; this.val = val;}
public String Key() {return key;} private final String key;
@@ -51,6 +60,13 @@ class Gfobj_fld_long implements Gfobj_fld {
public Object As_obj() {return val;}
public long As_long() {return val;} private long val;
}
class Gfobj_fld_double implements Gfobj_fld {
public Gfobj_fld_double(String key, double val) {this.key = key; this.val = val;}
public String Key() {return key;} private final String key;
public byte Fld_tid() {return Gfobj_fld_.Fld_tid__double;}
public Object As_obj() {return val;}
public double As_double() {return val;} private double val;
}
class Gfobj_fld_nde implements Gfobj_fld {
public Gfobj_fld_nde(String key, Gfobj_nde val) {this.key = key; this.val = val;}
public String Key() {return key;} private final String key;

View File

@@ -17,5 +17,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
public interface Gfobj_grp {
byte Grp_tid();
byte Grp_tid();
}

View File

@@ -22,13 +22,39 @@ public class Gfobj_nde implements Gfobj_grp {
public int Len() {return subs == null ? 0 : subs.Len();}
public Gfobj_fld Get_at(int i) {return subs == null ? null : (Gfobj_fld)subs.Get_at(i);}
public Gfobj_fld Get_by(String k) {return subs == null ? null : (Gfobj_fld)subs.Get_by(k);}
public Gfobj_ary Get_ary(String k) {return ((Gfobj_fld_ary)Get_by(k)).As_ary();}
public Gfobj_nde Get_nde(int i) {return ((Gfobj_fld_nde)Get_at(i)).As_nde();}
public Gfobj_nde Get_nde(String k) {return ((Gfobj_fld_nde)Get_by(k)).As_nde();}
public long Get_long(String k) {
Gfobj_fld fld = Get_by(k);
switch (fld.Fld_tid()) {
case Gfobj_fld_.Fld_tid__long: return ((Gfobj_fld_long)fld).As_long();
case Gfobj_fld_.Fld_tid__int : return ((Gfobj_fld_int )fld).As_int();
default: throw Err_.new_unhandled_default(fld.Fld_tid());
}
}
public int Get_int(String k) {
Gfobj_fld fld = Get_by(k);
switch (fld.Fld_tid()) {
case Gfobj_fld_.Fld_tid__int : return ((Gfobj_fld_int )fld).As_int();
default: throw Err_.new_unhandled_default(fld.Fld_tid());
}
}
public byte Get_byte(String k) {return (byte)Get_int(k);}
public String Get_str(String k) {return ((Gfobj_fld_str)Get_by(k)).As_str();}
public Io_url Get_url(String k) {return Io_url_.new_any_(((Gfobj_fld_str)Get_by(k)).As_str());}
public Gfobj_nde Add_fld(Gfobj_fld fld) {if (subs == null) subs = Ordered_hash_.New(); subs.Add(fld.Key(), fld); return this;}
public Gfobj_nde Add_bool(String key, boolean val) {return Add_fld(new Gfobj_fld_bool(key, val));}
public Gfobj_nde Add_byte(String key, byte val) {return Add_fld(new Gfobj_fld_int(key, val));}
public Gfobj_nde Add_int(String key, int val) {return Add_fld(new Gfobj_fld_int(key, val));}
public Gfobj_nde Add_long(String key, long val) {return Add_fld(new Gfobj_fld_long(key, val));}
public Gfobj_nde Add_str(String key, String val) {return Add_fld(new Gfobj_fld_str(key, val));}
public Gfobj_nde Add_url(String key, Io_url val) {return Add_fld(new Gfobj_fld_str(key, val.Raw()));}
public Gfobj_nde Add_double(String key, double val) {return Add_fld(new Gfobj_fld_double(key, val));}
public Gfobj_nde Add_nde(String key, Gfobj_nde val) {return Add_fld(new Gfobj_fld_nde(key, val));}
public Gfobj_nde Add_ary(String key, Gfobj_ary val) {return Add_fld(new Gfobj_fld_ary(key, val));}
public Gfobj_nde New_nde(String key) {Gfobj_nde rv = new Gfobj_nde(); Add_fld(new Gfobj_fld_nde(key, rv)); return rv;}
public Gfobj_ary_nde New_ary_nde(String key) {Gfobj_ary_nde rv = new Gfobj_ary_nde(null); Add_fld(new Gfobj_fld_ary(key, rv)); return rv;}
public Gfobj_nde New_nde(String key) {Gfobj_nde rv = new Gfobj_nde(); Add_fld(new Gfobj_fld_nde(key, rv)); return rv;}
public Gfobj_ary New_ary(String key) {Gfobj_ary rv = new Gfobj_ary(null); Add_fld(new Gfobj_fld_ary(key, rv)); return rv;}
public Gfobj_ary New_ary(String key, int subs_len) {return New_ary(key).Ary_(new Object[subs_len]);}
public static Gfobj_nde New() {return new Gfobj_nde();}
}

View File

@@ -0,0 +1,92 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
import gplx.langs.jsons.*;
public class Gfobj_rdr__json {
private final Json_parser parser = new Json_parser();
public Gfobj_grp Load(Io_url url) {
byte[] src = Io_mgr.Instance.LoadFilBryOrNull(url); if (src == null) return null;
return this.Parse(src);
}
public Gfobj_grp Parse(byte[] src) {
Json_doc jdoc = parser.Parse(src);
if (jdoc.Root_grp().Tid() == Json_itm_.Tid__nde) {
Gfobj_nde rv_nde = Gfobj_nde.New();
Parse_nde((Json_nde)jdoc.Root_grp(), rv_nde);
return rv_nde;
}
else {
Gfobj_ary rv_ary = new Gfobj_ary(null);
Parse_ary((Json_ary)jdoc.Root_grp(), rv_ary);
return rv_ary;
}
}
private void Parse_nde(Json_nde jnde, Gfobj_nde gnde) {
int len = jnde.Len();
for (int i = 0; i < len; ++i) {
Json_kv kv = jnde.Get_at_as_kv(i);
String key_str = kv.Key_as_str();
Json_itm val = kv.Val();
byte val_tid = val.Tid();
switch (val_tid) {
case Json_itm_.Tid__str: gnde.Add_str (key_str, ((Json_itm_str)val).Data_as_str()); break;
case Json_itm_.Tid__bool: gnde.Add_bool (key_str, ((Json_itm_bool)val).Data_as_bool()); break;
case Json_itm_.Tid__int: gnde.Add_int (key_str, ((Json_itm_int)val).Data_as_int()); break;
case Json_itm_.Tid__long: gnde.Add_long (key_str, ((Json_itm_long)val).Data_as_long()); break;
case Json_itm_.Tid__decimal: gnde.Add_double (key_str, ((Json_itm_decimal)val).Data_as_decimal().To_double()); break;
case Json_itm_.Tid__null: gnde.Add_str (key_str, null); break;
case Json_itm_.Tid__ary:
Gfobj_ary sub_ary = new Gfobj_ary(null);
gnde.Add_ary(key_str, sub_ary);
Parse_ary(Json_ary.cast(val), sub_ary);
break;
case Json_itm_.Tid__nde:
Gfobj_nde sub_gnde = Gfobj_nde.New();
gnde.Add_nde(key_str, sub_gnde);
Parse_nde(Json_nde.cast(val), sub_gnde);
break;
default: throw Err_.new_unhandled_default(val_tid);
}
}
}
private void Parse_ary(Json_ary jry, Gfobj_ary gry) {
int len = jry.Len();
Object[] ary = new Object[len];
gry.Ary_(ary);
for (int i = 0; i < len; ++i) {
Json_itm jsub = jry.Get_at(i);
switch (jsub.Tid()) {
case Json_itm_.Tid__ary: {
Gfobj_ary sub_ary = new Gfobj_ary(null);
Parse_ary(Json_ary.cast(jsub), sub_ary);
ary[i] = sub_ary;
break;
}
case Json_itm_.Tid__nde: {
Gfobj_nde sub_ary = Gfobj_nde.New();
Parse_nde(Json_nde.cast(jsub), sub_ary);
ary[i] = sub_ary;
break;
}
default:
ary[i] = jsub.Data();
break;
}
}
}
}

View File

@@ -0,0 +1,88 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.tests.*;
import gplx.langs.jsons.*;
public class Gfobj_rdr__json_tst {
private final Gfobj_wtr__json_fxt fxt = new Gfobj_wtr__json_fxt();
@Test public void Type() {
fxt.Test__parse(String_.Concat_lines_nl_skip_last
( "{ 'k1':true"
, ", 'k2':123"
, ", 'k3':9876543210"
, ", 'k4':1.23"
, ", 'k5':null"
, ", 'k6':'abc'"
, "}"
)
, fxt.Make__nde
( fxt.Make__fld_bool ("k1", true)
, fxt.Make__fld_int ("k2", 123)
, fxt.Make__fld_long ("k3", 9876543210L)
, fxt.Make__fld_double ("k4", 1.23)
, fxt.Make__fld_str ("k5", null)
, fxt.Make__fld_str ("k6", "abc")
));
}
@Test public void Nested() {
fxt.Test__parse(String_.Concat_lines_nl_skip_last
( "{ 'a1':'1a'"
, ", 'a2':"
, " { 'b1':'1b'"
, " , 'b2':"
, " { 'c1':'1c'"
, " }"
, " }"
, ", 'a3':[1, 2, 3]"
, "}"
)
, fxt.Make__nde
( fxt.Make__fld_str ("a1", "1a")
, fxt.Make__fld_nde ("a2"
, fxt.Make__fld_str("b1", "1b")
, fxt.Make__fld_nde("b2"
, fxt.Make__fld_str("c1", "1c"))
)
, fxt.Make__fld_ary ("a3", 1, 2, 3)
));
}
@Test public void Array() {
fxt.Test__parse(String_.Concat_lines_nl_skip_last
( "["
, " [1, 2, 3]"
, ", ['a', 'b', 'c']"
, ", [true, false]"
, ", [9876543210, 9876543211, 9876543212]"
//, ", [1.23, 1.24, 1.25]"
, ", [{'a':1}, {'b':2}, {'c':3}]"
, "]"
)
, fxt.Make__ary
( fxt.Make__ary (1, 2, 3)
, fxt.Make__ary ("a", "b", "c")
, fxt.Make__ary (true, false)
, fxt.Make__ary (9876543210L, 9876543211L, 9876543212L)
// , fxt.Make__ary (1.23, 1.24, 1.25)
, fxt.Make__ary
( fxt.Make__nde(fxt.Make__fld_int("a", 1))
, fxt.Make__nde(fxt.Make__fld_int("b", 2))
, fxt.Make__nde(fxt.Make__fld_int("c", 3))
)
));
}
}

View File

@@ -20,8 +20,12 @@ import gplx.langs.jsons.*;
public class Gfobj_wtr__json {
private final Json_wtr wtr = new Json_wtr();
public Gfobj_wtr__json Opt_ws_(boolean v) {wtr.Opt_ws_(v); return this;}
public Gfobj_wtr__json Opt_backslash_2x_(boolean v) {wtr.Opt_backslash_2x_(v); return this;}
public Bry_bfr Bfr() {return wtr.Bfr();}
public String To_str() {return wtr.To_str_and_clear();}
public void Save(Io_url url) {
Io_mgr.Instance.SaveFilBry(url, wtr.To_bry_and_clear());
}
public Gfobj_wtr__json Write(Gfobj_grp root) {
switch (root.Grp_tid()) {
case Gfobj_grp_.Grp_tid__nde:
@@ -51,6 +55,8 @@ public class Gfobj_wtr__json {
case Gfobj_fld_.Fld_tid__str: wtr.Kv_str(itm.Key() , ((Gfobj_fld_str)itm).As_str()); break;
case Gfobj_fld_.Fld_tid__int: wtr.Kv_int(itm.Key() , ((Gfobj_fld_int)itm).As_int()); break;
case Gfobj_fld_.Fld_tid__long: wtr.Kv_long(itm.Key() , ((Gfobj_fld_long)itm).As_long()); break;
case Gfobj_fld_.Fld_tid__bool: wtr.Kv_bool(itm.Key() , ((Gfobj_fld_bool)itm).As_bool()); break;
case Gfobj_fld_.Fld_tid__double: wtr.Kv_double(itm.Key() , ((Gfobj_fld_double)itm).As_double()); break;
case Gfobj_fld_.Fld_tid__nde: wtr.Nde_bgn(itm.Key()); Write_nde(((Gfobj_fld_nde)itm).As_nde()); wtr.Nde_end();break;
case Gfobj_fld_.Fld_tid__ary: wtr.Ary_bgn(itm.Key()); Write_ary(((Gfobj_fld_ary)itm).As_ary()); wtr.Ary_end();break;
default: throw Err_.new_unhandled_default(itm.Fld_tid());
@@ -58,35 +64,22 @@ public class Gfobj_wtr__json {
}
private void Write_ary(Gfobj_ary ary) {
int len = ary.Len();
byte ary_tid = ary.Ary_tid();
switch (ary_tid) {
case Gfobj_ary_.Ary_tid__str:
String[] ary_str = ((Gfo_ary_str)ary).Ary_str();
for (int i = 0; i < len; ++i)
wtr.Ary_itm_str(ary_str[i]);
break;
case Gfobj_ary_.Ary_tid__int:
int[] ary_int = ((Gfo_ary_int)ary).Ary_int();
for (int i = 0; i < len; ++i)
wtr.Ary_itm_obj(ary_int[i]);
break;
case Gfobj_ary_.Ary_tid__nde:
Gfobj_nde[] ary_nde = ((Gfobj_ary_nde)ary).Ary_nde();
for (int i = 0; i < len; ++i) {
wtr.Nde_bgn_ary();
Write_nde(ary_nde[i]);
wtr.Nde_end();
}
break;
case Gfobj_ary_.Ary_tid__ary:
Gfobj_ary[] ary_ary = ((Gfo_ary_ary)ary).Ary_ary();
for (int i = 0; i < len; ++i) {
wtr.Ary_bgn_ary();
Write_ary(ary_ary[i]);
wtr.Ary_end();
}
break;
default: throw Err_.new_unhandled_default(ary_tid);
Object[] ary_obj = ((Gfobj_ary)ary).Ary_obj();
for (int i = 0; i < len; ++i) {
Object sub_itm = ary_obj[i];
Class<?> sub_itm_type = Type_adp_.ClassOf_obj(sub_itm);
if (Type_adp_.Eq(sub_itm_type, Gfobj_ary.class)) {
wtr.Ary_bgn_ary();
Write_ary((Gfobj_ary)sub_itm);
wtr.Ary_end();
}
else if (Type_adp_.Eq(sub_itm_type, Gfobj_nde.class)) {
wtr.Nde_bgn_ary();
Write_nde((Gfobj_nde)sub_itm);
wtr.Nde_end();
}
else
wtr.Ary_itm_obj(sub_itm);
}
}
}

View File

@@ -28,22 +28,27 @@ public class Gfobj_wtr__json_fxt {
}
return nde;
}
public Gfobj_fld Make__fld_str(String key, String val) {return new Gfobj_fld_str(key, val);}
public Gfobj_fld Make__fld_int(String key, int val) {return new Gfobj_fld_int(key, val);}
public Gfobj_fld Make__fld_long(String key, long val) {return new Gfobj_fld_long(key, val);}
public Gfobj_fld Make__fld_bool (String key, boolean val) {return new Gfobj_fld_bool(key, val);}
public Gfobj_fld Make__fld_str (String key, String val) {return new Gfobj_fld_str(key, val);}
public Gfobj_fld Make__fld_int (String key, int val) {return new Gfobj_fld_int(key, val);}
public Gfobj_fld Make__fld_long (String key, long val) {return new Gfobj_fld_long(key, val);}
public Gfobj_fld Make__fld_double (String key, double val) {return new Gfobj_fld_double(key, val);}
public Gfobj_fld Make__fld_nde(String key, Gfobj_fld... ary) {
Gfobj_nde nde = Make__nde(Gfobj_nde.New(), ary);
Gfobj_fld_nde rv = new Gfobj_fld_nde(key, nde);
return rv;
}
public Gfobj_fld Make__fld_ary_str(String key, String... ary) {return new Gfobj_fld_ary(key, new Gfo_ary_str(ary));}
public Gfobj_fld Make__fld_ary_int(String key, int... ary) {return new Gfobj_fld_ary(key, new Gfo_ary_int(ary));}
public Gfobj_fld Make__fld_ary_ary(String key, Gfobj_ary... ary) {return new Gfobj_fld_ary(key, new Gfo_ary_ary(ary));}
public Gfobj_fld Make__fld_ary_nde(String key, Gfobj_nde... ary) {return new Gfobj_fld_ary(key, new Gfobj_ary_nde(ary));}
public Gfobj_ary Make__ary_int(int... ary) {return new Gfo_ary_int(ary);}
public Gfobj_fld Make__fld_ary (String key, Object... ary) {return new Gfobj_fld_ary(key, new Gfobj_ary(ary));}
public Gfobj_ary Make__ary (Object... ary) {return new Gfobj_ary(ary);}
public Gfobj_wtr__json_fxt Test__write(Gfobj_grp root, String... lines) {
String[] expd = Json_doc.Make_str_ary_by_apos(lines);
Gftest.Eq__ary(expd, Bry_.Ary(String_.SplitLines_nl(mgr.Write(root).To_str())), "json_write");
return this;
}
public Gfobj_wtr__json_fxt Test__parse(String src, Gfobj_grp expd) {
Gfobj_rdr__json rdr = new Gfobj_rdr__json();
Gfobj_grp actl = rdr.Parse(Bry_.new_u8(Json_doc.Make_str_by_apos(src)));
Gftest.Eq__ary(Bry_.Ary(String_.SplitLines_nl(mgr.Write(expd).To_str())), Bry_.Ary(String_.SplitLines_nl(mgr.Write(actl).To_str())), "json_write");
return this;
}
}

View File

@@ -58,7 +58,7 @@ public class Gfobj_wtr__json_tst {
fxt.Test__write
( fxt.Make__nde
( fxt.Make__fld_str ("k1", "v1")
, fxt.Make__fld_ary_str ("k2", "a1", "a2", "a3")
, fxt.Make__fld_ary ("k2", "a1", "a2", "a3")
, fxt.Make__fld_int ("k3", 3)
)
, "{ 'k1':'v1'"
@@ -76,7 +76,7 @@ public class Gfobj_wtr__json_tst {
fxt.Test__write
( fxt.Make__nde
( fxt.Make__fld_str ("k1", "v1")
, fxt.Make__fld_ary_int ("k2", 1, 2, 3)
, fxt.Make__fld_ary ("k2", 1, 2, 3)
, fxt.Make__fld_int ("k3", 3)
)
, "{ 'k1':'v1'"
@@ -94,7 +94,7 @@ public class Gfobj_wtr__json_tst {
fxt.Test__write
( fxt.Make__nde
( fxt.Make__fld_str ("k1", "v1")
, fxt.Make__fld_ary_nde ("k2"
, fxt.Make__fld_ary ("k2"
, fxt.Make__nde (fxt.Make__fld_str("k21", "v21"))
, fxt.Make__nde (fxt.Make__fld_str("k22", "v22"))
)
@@ -118,9 +118,9 @@ public class Gfobj_wtr__json_tst {
fxt.Test__write
( fxt.Make__nde
( fxt.Make__fld_str ("k1", "v1")
, fxt.Make__fld_ary_ary ("k2"
, fxt.Make__ary_int (1, 2, 3)
, fxt.Make__ary_int (4, 5, 6)
, fxt.Make__fld_ary ("k2"
, fxt.Make__ary (1, 2, 3)
, fxt.Make__ary (4, 5, 6)
)
, fxt.Make__fld_int ("k3", 3)
)
@@ -144,7 +144,7 @@ public class Gfobj_wtr__json_tst {
}
@Test public void Root_ary() {
fxt.Test__write
( fxt.Make__ary_int(1, 2, 3)
( fxt.Make__ary(1, 2, 3)
, "[ 1"
, ", 2"
, ", 3"

View File

@@ -21,11 +21,11 @@ class Gfo_i18n_itm {
public Gfo_i18n_itm(int src, byte[] key, byte[] val, boolean val_fmt_exists, Gfo_i18n_val_cmd val_cmd) {
this.src = src; this.key = key; this.val = val; this.val_fmt_exists = val_fmt_exists; this.val_cmd = val_cmd;
}
public int Src() {return src;} private final int src;
public byte[] Key() {return key;} private final byte[] key;
public byte[] Val() {return val;} private final byte[] val;
public boolean Val_fmt_exists() {return val_fmt_exists;} private final boolean val_fmt_exists;
public Gfo_i18n_val_cmd Val_cmd() {return val_cmd;} private final Gfo_i18n_val_cmd val_cmd;
public int Src() {return src;} private final int src;
public byte[] Key() {return key;} private final byte[] key;
public byte[] Val() {return val;} private final byte[] val;
public boolean Val_fmt_exists() {return val_fmt_exists;} private final boolean val_fmt_exists;
public Gfo_i18n_val_cmd Val_cmd() {return val_cmd;} private final Gfo_i18n_val_cmd val_cmd;
public byte[] Bld_none() {
return val_cmd == null ? val : val_cmd.Process(src, key, val);
}
@@ -38,6 +38,6 @@ class Gfo_i18n_itm {
}
return val_cmd == null ? rv : val_cmd.Process(src, key, rv);
}
private static final Bry_fmtr tmp_fmtr = Bry_fmtr.new_();
private static final Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
private static final Bry_fmtr tmp_fmtr = Bry_fmtr.new_();
private static final Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
}

View File

@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.ios; import gplx.*; import gplx.core.*;
import gplx.core.ios.*;/*IoStream*/
import gplx.core.ios.streams.*;/*IoStream*/
public class Io_buffer_rdr implements Rls_able {
private Io_stream_rdr rdr;
Io_buffer_rdr(Io_stream_rdr rdr, Io_url url, int bfr_len) {
@@ -43,7 +43,7 @@ public class Io_buffer_rdr implements Rls_able {
}
private boolean Bfr_load(int bgn, int len) {
int read = rdr.Read(bfr, bgn, len);
if (read == gplx.core.ios.Io_stream_rdr_.Read_done) {fil_eof = true; return false;}
if (read == gplx.core.ios.streams.Io_stream_rdr_.Read_done) {fil_eof = true; return false;}
fil_pos += read;
bfr_len = bgn + read;
if (read < len) fil_eof = true;
@@ -69,5 +69,5 @@ public class Io_buffer_rdr implements Rls_able {
rv.Bfr_load(0, bfr_len);
return rv;
}
public static final Io_buffer_rdr Null = new Io_buffer_rdr(); Io_buffer_rdr() {}
public static final Io_buffer_rdr Null = new Io_buffer_rdr(); Io_buffer_rdr() {}
}

View File

@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.ios; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.ios.*;
import org.junit.*; import gplx.core.ios.*; import gplx.core.ios.streams.*;
public class Io_buffer_rdr_tst {
@Before public void init() {
Io_mgr.Instance.InitEngine_mem();

View File

@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.ios; import gplx.*; import gplx.core.*;
import gplx.core.ios.streams.*;
public class Io_line_rdr {
public Io_line_rdr (Gfo_usr_dlg usr_dlg, Io_url... urls) {this.usr_dlg = usr_dlg; this.urls = urls; if (urls.length == 0) bfr_state = Bfr_state_end;} Gfo_usr_dlg usr_dlg;
public int Url_idx() {return url_idx;} private int url_idx;
@@ -141,7 +142,7 @@ public class Io_line_rdr {
stream_bry = Bry_.Empty;
else
stream_bry = Bry_.Mid(stream_bry, nl_pos + 1, stream_bry_len);
stream = gplx.core.ios.IoStream_.ary_(stream_bry);
stream = gplx.core.ios.streams.IoStream_.ary_(stream_bry);
}
else {
stream = Io_mgr.Instance.OpenStreamRead(url);

View File

@@ -48,7 +48,7 @@ public class Io_line_rdr_tst {
}
class Io_line_rdr_fxt {
Io_line_rdr rdr;
List_adp lines = List_adp_.new_(); Bry_bfr tmp = Bry_bfr.new_();
List_adp lines = List_adp_.New(); Bry_bfr tmp = Bry_bfr_.New();
public Io_line_rdr_fxt(Io_url... urls) {rdr = new Io_line_rdr(Gfo_usr_dlg_.Test(), urls);}
public Io_line_rdr_fxt Load_len_lines_(int v) {return Load_len_(v * 3);} // 3: 2=##, 1=\n
public Io_line_rdr_fxt Load_len_(int v) {rdr.Load_len_(v); return this;}

View File

@@ -23,9 +23,9 @@ public class Io_sort {
public Io_url[] Split(Gfo_usr_dlg usr_dlg, Io_url_gen src_fil_gen, Io_url_gen trg_fil_gen, Io_line_rdr_key_gen key_gen) {return Split(usr_dlg, src_fil_gen, trg_fil_gen, Io_sort_split_itm_sorter.Instance, key_gen);}
public Io_url[] Split(Gfo_usr_dlg usr_dlg, Io_url_gen src_fil_gen, Io_url_gen trg_fil_gen, ComparerAble row_comparer, Io_line_rdr_key_gen key_gen) {
Io_line_rdr rdr = new Io_line_rdr(usr_dlg, src_fil_gen.Prv_urls()).Load_len_(4 * Io_mgr.Len_kb).Key_gen_(key_gen); // NOTE: do not set load_len to memory_max; only want to load in increments
List_adp rv = List_adp_.new_();
Bry_bfr bfr = Bry_bfr.reset_(Const_bfr_max); int size_cur = 0;
List_adp row_list = List_adp_.new_();
List_adp rv = List_adp_.New();
Bry_bfr bfr = Bry_bfr_.Reset(Const_bfr_max); int size_cur = 0;
List_adp row_list = List_adp_.New();
while (true) {
boolean reading = rdr.Read_next();
int size_row = rdr.Itm_pos_end() - rdr.Itm_pos_bgn();

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.ios; import gplx.*; import gplx.core.*;
public class Io_sort_fil_basic implements Io_sort_cmd { // 123|bgn|end|1
public Io_sort_fil_basic(Gfo_usr_dlg usr_dlg, Io_url_gen url_gen, int flush_len) {this.usr_dlg = usr_dlg; this.url_gen = url_gen; this.flush_len = flush_len;} Io_url_gen url_gen; Bry_bfr bfr = Bry_bfr.new_(); int flush_len; Gfo_usr_dlg usr_dlg;
public Io_sort_fil_basic(Gfo_usr_dlg usr_dlg, Io_url_gen url_gen, int flush_len) {this.usr_dlg = usr_dlg; this.url_gen = url_gen; this.flush_len = flush_len;} Io_url_gen url_gen; Bry_bfr bfr = Bry_bfr_.New(); int flush_len; Gfo_usr_dlg usr_dlg;
public void Sort_bgn() {}
public void Sort_do(Io_line_rdr rdr) {
int bgn = rdr.Itm_pos_bgn(), end = rdr.Itm_pos_end();

View File

@@ -25,7 +25,7 @@ public class Io_sort_misc_tst {
}
private void tst_Io_url_gen_dir(String dir_str, String fmt, int digits, int calls, String... expd) {
Io_url dir = Io_url_.mem_dir_(dir_str);
List_adp actl_list = List_adp_.new_();
List_adp actl_list = List_adp_.New();
Io_url_gen wkr = Io_url_gen_.dir_(dir, fmt, digits);
for (int i = 0; i < calls; i++)
actl_list.Add(wkr.Nxt_url().Raw());

View File

@@ -48,7 +48,7 @@ class Io_sort_fxt {
Tfds.Eq_ary_str(String_.SplitLines_nl(sorted), String_.SplitLines_nl(actl));
}
public String GenRandom(int rows, int pad) {
List_adp list = List_adp_.new_();
List_adp list = List_adp_.New();
for (int i = 0; i < rows; i++)
list.Add(Int_.To_str_pad_bgn_zero(i, pad) + "|");
list.Shuffle();

View File

@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.ios; import gplx.*; import gplx.core.*;
import java.io.InputStream;
import gplx.core.ios.streams.*;
public class Io_stream_rdr_process implements Io_stream_rdr {
private Process process;
private InputStream stream_read;

View File

@@ -16,8 +16,9 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.ios; import gplx.*; import gplx.core.*;
import gplx.core.ios.streams.*;
public class Io_stream_zip_mgr {
private final Bry_bfr bfr = Bry_bfr.reset_(256);
private final Bry_bfr bfr = Bry_bfr_.Reset(256);
private Io_stream_wtr wtr_gzip, wtr_zip, wtr_bzip2;
private Io_stream_rdr rdr_gzip, rdr_zip, rdr_bzip2;
public byte[] Zip(byte type, byte[] val) {

View File

@@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.lists.hashs; import gplx.*; import gplx.core.*; import gplx.core.lists.*;
import gplx.core.primitives.*;
public class Hash_adp__int {
private final Hash_adp hash = Hash_adp_.New();
private final Int_obj_ref tmp_key = Int_obj_ref.New_neg1();
public void Clear() {hash.Clear();}
public Object Get_by(int key) {return hash.Get_by_or_fail(tmp_key.Val_(key));}
public Object Get_by_or_null(int key) {return hash.Get_by(tmp_key.Val_(key));}
public void Add(int key, Object obj) {hash.Add(Int_obj_ref.New(key), obj);}
public void Add(Int_obj_ref key, Object obj) {hash.Add(key, obj);}
public void Add_if_dupe_use_1st(int key, Object obj) {hash.Add_if_dupe_use_1st(Int_obj_ref.New(key), obj);}
public void Add_if_dupe_use_nth(Int_obj_ref key, Object obj) {hash.Add_if_dupe_use_nth(key, obj);}
}

View File

@@ -1,55 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.logs; import gplx.*; import gplx.core.*;
public class Gfo_log_fil {
private final Bry_bfr fil_bfr = Bry_bfr.new_(), msg_bfr = Bry_bfr.new_();
private final String key;
private final Io_url dir;
private final long size_max;
private int file_idx;
private Io_url fil_cur;
private final Gfo_log_fmtr fmtr = new Gfo_log_fmtr();
private final Gfo_log_fil session;
public Gfo_log_fil(Gfo_log_fil session, String key, Io_url dir, long size_max) {
this.session = session;
this.key = key;
this.dir = dir;
this.size_max = size_max;
this.fil_cur = Fil_new();
}
public void Add(String msg, Object... vals) {
fmtr.Add(msg_bfr, msg, vals);
Add_by_bfr(msg_bfr);
msg_bfr.Clear();
}
public void Add_by_bfr(Bry_bfr msg_bfr) {
if (msg_bfr.Len() + fil_bfr.Len() > size_max) {
this.Flush();
fil_cur = Fil_new();
}
fil_bfr.Add_bfr_and_preserve(msg_bfr);
if (session != null) session.Add_by_bfr(msg_bfr);
}
public void Flush() {
Io_mgr.Instance.AppendFilBfr(fil_cur, fil_bfr);
}
private Io_url Fil_new() {
String part = size_max == -1 ? "" : "-" + Int_.To_str(++file_idx);
return dir.OwnerDir().GenSubFil_ary(key, part, ".log");
}
}

View File

@@ -1,58 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.logs; import gplx.*; import gplx.core.*;
import gplx.core.btries.*;
class Gfo_log_fmtr {
private final Btrie_fast_mgr trie = Btrie_fast_mgr.cs()
.Add("~|" , Bry_.new_a7("~|<"))
.Add("|" , Bry_.new_a7("~||"))
.Add("\n" , Bry_.new_a7("~|n"))
.Add("\t" , Bry_.new_a7("~|t"))
;
public void Add(Bry_bfr bfr, String msg, Object... vals) {
Add_bry(bfr, Bry_.new_u8(msg));
int len = vals.length;
for (int i = 0; i < len; ++i) {
bfr.Add_byte(Byte_ascii.Pipe);
byte[] val_bry = Bry_.new_u8(Object_.Xto_str_strict_or_empty(vals[i]));
Add_bry(bfr, val_bry);
}
bfr.Add_byte_nl();
}
private void Add_bry(Bry_bfr bfr, byte[] src) {
if (src == null) return;
int len = src.length; if (len == 0) return;
int pos = 0;
int add_bgn = -1;
while (true) {
if (pos == len) break;
byte b = src[pos];
Object o = trie.Match_bgn_w_byte(b, src, pos, len);
if (o == null) {
if (add_bgn == -1) add_bgn = pos;
}
else {
if (add_bgn != -1) bfr.Add_mid(src, add_bgn, pos);
byte[] repl = (byte[])o;
bfr.Add(repl);
pos = trie.Match_pos();
}
}
if (add_bgn != -1) bfr.Add_mid(src, add_bgn, len);
}
}

View File

@@ -1,55 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.logs; import gplx.*; import gplx.core.*;
public class Gfo_log_mgr {
private final Ordered_hash fil_list = Ordered_hash_.New();
private final Gfo_log_fil session_fil;
private final Io_url dir;
private final long size_dflt = Io_mgr.Len_mb * 2;
public Gfo_log_mgr(Io_url dir) {
this.dir = dir;
this.session_fil = new Gfo_log_fil(null, "session", dir, -1);
}
public Gfo_log_fil Fils__get_or_new(String key) {
Gfo_log_fil rv = (Gfo_log_fil)fil_list.Get_by(key);
if (rv == null) {
rv = new Gfo_log_fil(session_fil, key, dir, size_dflt);
fil_list.Add(key, rv);
}
return rv;
}
public void Msgs__add(String fil_key, String msg, Object... vals) {
Gfo_log_fil fil = (Gfo_log_fil)Fils__get_or_new(fil_key);
fil.Add(msg, vals);
}
}
// class Some_log_cls {
// private final Gfo_log_mgr log_mgr = new Gfo_log_mgr();
// public void Init() {
// }
// private Gfo_log_fil dedicated;
// public void Init_dedicated() {
// dedicated = log_mgr.Fil_get_or_new("parse");
// }
// public void Proc_w_dedicate() {
// dedicated.Add("file download failed", "url", "msg");
// }
// public void Proc_dynamic() {
// log_mgr.Msg_add("parse", "file download failed", "url", "msg");
// }
// }

View File

@@ -32,14 +32,14 @@ public class Gfo_inet_conn_ {
public static void new_prototype_(int v) {new_prototype = v;} private static int new_prototype = Tid__http;
}
class Gfo_inet_conn__mem__hash implements Gfo_inet_conn {
private final Hash_adp hash = Hash_adp_.new_();
private final Hash_adp hash = Hash_adp_.New();
public int Tid() {return Gfo_inet_conn_.Tid__mem__hash;}
public void Clear() {hash.Clear();}
public void Upload_by_bytes(String url, byte[] data) {hash.Add(url, data);}
public byte[] Download_as_bytes_or_null(String url) {return (byte[])hash.Get_by(url);}
}
class Gfo_inet_conn__mem__pile implements Gfo_inet_conn {
private final List_adp pile = List_adp_.new_();
private final List_adp pile = List_adp_.New();
public int Tid() {return Gfo_inet_conn_.Tid__mem__hash;}
public void Clear() {pile.Clear();}
public void Upload_by_bytes(String url, byte[] data) {pile.Add(data);}

View File

@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.net; import gplx.*; import gplx.core.*;
import gplx.core.net.qargs.*;
public class Gfo_url {
public byte[] Raw() {return raw;} private byte[] raw;
public byte Protocol_tid() {return protocol_tid;} private byte protocol_tid;
@@ -34,5 +35,5 @@ public class Gfo_url {
this.anch = anch;
return this;
}
public static final Gfo_url Empty = new Gfo_url().Ctor(Bry_.Empty, Gfo_protocol_itm.Tid_unknown, Bry_.Empty, Bry_.Ary_empty, null, null);
public static final Gfo_url Empty = new Gfo_url().Ctor(Bry_.Empty, Gfo_protocol_itm.Tid_unknown, Bry_.Empty, Bry_.Ary_empty, null, null);
}

View File

@@ -17,10 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.net; import gplx.*; import gplx.core.*;
import gplx.core.primitives.*; import gplx.core.btries.*;
import gplx.core.net.qargs.*;
public class Gfo_url_parser {
private final Btrie_slim_mgr protocols = Btrie_slim_mgr.ci_a7(); // ASCII:url_protocol; EX:"http:", "ftp:", etc
private final Bry_ary segs_ary = new Bry_ary(4), qargs = new Bry_ary(4);
private final Bry_bfr tmp_bfr = Bry_bfr.reset_(500);
private final Btrie_slim_mgr protocols = Btrie_slim_mgr.ci_a7(); // ASCII:url_protocol; EX:"http:", "ftp:", etc
private final Bry_ary segs_ary = new Bry_ary(4), qargs = new Bry_ary(4);
private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(500);
public byte[] Relative_url_protocol_bry() {return Gfo_protocol_itm.Itm_https.Key_w_colon_bry();} // NOTE: https b/c any WMF wiki will now default to WMF; DATE:2015-07-26
public Gfo_url_parser() {
Init_protocols(Gfo_protocol_itm.Ary());
@@ -254,5 +255,5 @@ public class Gfo_url_parser {
qargs.Clear();
segs_ary.Set_at_last(tmp_bfr.To_bry_and_clear());
}
public static final byte[] Bry_double_slash = new byte[] {Byte_ascii.Slash, Byte_ascii.Slash};
public static final byte[] Bry_double_slash = new byte[] {Byte_ascii.Slash, Byte_ascii.Slash};
}

View File

@@ -16,8 +16,9 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.net; import gplx.*; import gplx.core.*;
import gplx.core.net.qargs.*;
class Gfo_url_parser_fxt {
private final Gfo_url_parser parser = new Gfo_url_parser();
private final Gfo_url_parser parser = new Gfo_url_parser();
private Gfo_url actl;
public Gfo_url_parser_fxt Chk_protocol_tid(byte v) {Tfds.Eq_byte(v, actl.Protocol_tid(), "protocol_tid"); return this;}
public Gfo_url_parser_fxt Chk_protocol_bry(String v) {Tfds.Eq_str(v, actl.Protocol_bry(), "protocol_bry"); return this;}
@@ -35,5 +36,5 @@ class Gfo_url_parser_fxt {
parser.Parse_site_fast(site_data, raw_bry, 0, raw_bry.length);
String actl = String_.new_u8(raw_bry, site_data.Site_bgn(), site_data.Site_end());
Tfds.Eq(expd, actl);
} private final Gfo_url_site_data site_data = new Gfo_url_site_data();
} private final Gfo_url_site_data site_data = new Gfo_url_site_data();
}

View File

@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.net; import gplx.*; import gplx.core.*;
import gplx.core.ios.*;
import gplx.core.ios.*; import gplx.core.ios.streams.*;
public interface Http_client_wtr {
void Stream_(Object o);
void Write_bry(byte[] bry);

View File

@@ -16,10 +16,10 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.net; import gplx.*; import gplx.core.*;
import gplx.core.ios.*;
import gplx.core.ios.*; import gplx.core.ios.streams.*;
import java.io.*;
class Http_client_wtr__stream implements Http_client_wtr {
private final byte[] tmp_stream_bry = new byte[1024];
private final byte[] tmp_stream_bry = new byte[1024];
private DataOutputStream stream;
public void Stream_(Object o) {
this.stream = new DataOutputStream((OutputStream)o);

View File

@@ -22,7 +22,7 @@ public class Http_request_parser {
private int type, content_length;
private byte[] url, protocol, host, user_agent, accept, accept_language, accept_encoding, x_requested_with, cookie, referer, content_type, content_type_boundary, connection, pragma, cache_control, origin;
private Http_post_data_hash post_data_hash;
private final Bry_bfr tmp_bfr = Bry_bfr.new_(255);
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(255);
private final Http_server_wtr server_wtr; private final boolean log;
public Http_request_parser(Http_server_wtr server_wtr, boolean log) {this.server_wtr = server_wtr; this.log = log;}
public void Clear() {

View File

@@ -0,0 +1,25 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.net.downloads; import gplx.*; import gplx.core.*; import gplx.core.net.*;
public interface Http_download_wkr {
String Fail_msg();
Http_download_wkr Make_new();
long Checkpoint__load_by_trg_fil(Io_url trg_url);
byte Exec(gplx.core.progs.Gfo_prog_ui prog_ui, String src_str, Io_url trg_url, long expd_size);
void Exec_cleanup();
}

View File

@@ -15,12 +15,7 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
public class Gfobj_ary_ {
public static final byte
Ary_tid__ary = 0
, Ary_tid__nde = 1
, Ary_tid__str = 2
, Ary_tid__int = 3
;
package gplx.core.net.downloads; import gplx.*; import gplx.core.*; import gplx.core.net.*;
public class Http_download_wkr_ {
public static Http_download_wkr Proto = new Http_download_wkr__jre();
}

View File

@@ -0,0 +1,74 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.net.downloads; import gplx.*; import gplx.core.*; import gplx.core.net.*;
import gplx.core.progs.*;
public abstract class Http_download_wkr__base implements Http_download_wkr {
private long expd_size;
private Io_url tmp_url, checkpoint_url;
private long downloaded;
private long checkpoint_interval = 1024 * 1024, checkpoint_nxt = 0;
public String Fail_msg() {return fail_msg;} private String fail_msg;
public abstract Http_download_wkr Make_new();
public byte Exec(gplx.core.progs.Gfo_prog_ui prog_ui, String src_str, Io_url trg_url, long expd_size_val) {
this.downloaded = this.Checkpoint__load_by_trg_fil(trg_url);
this.checkpoint_nxt = downloaded + checkpoint_interval;
this.expd_size = expd_size_val;
this.fail_msg = null;
byte status = this.Exec_hook(prog_ui, src_str, tmp_url, downloaded);
switch (status) {
case Gfo_prog_ui_.Status__done: {
if (expd_size_val != -1) {
long actl_size = Io_mgr.Instance.QueryFil(tmp_url).Size();
if (expd_size != actl_size) {
this.fail_msg = String_.Format("bad size: bad={0} good={1}", actl_size, expd_size);
return Gfo_prog_ui_.Status__fail;
}
}
Io_mgr.Instance.MoveFil_args(tmp_url, trg_url, true).Exec();
this.Exec_cleanup();
break;
}
case Gfo_prog_ui_.Status__suspended:
case Gfo_prog_ui_.Status__fail: {
break;
}
}
return status;
}
protected abstract byte Exec_hook(gplx.core.progs.Gfo_prog_ui prog_ui, String src_str, Io_url trg_url, long downloaded);
public void Exec_cleanup() {
if (tmp_url != null) Io_mgr.Instance.DeleteFil(tmp_url);
if (checkpoint_url != null) Io_mgr.Instance.DeleteFil(checkpoint_url);
}
public long Checkpoint__load_by_trg_fil(Io_url trg_url) {
this.tmp_url = trg_url.GenNewExt(".tmp");
this.checkpoint_url = trg_url.GenNewExt(".checkpoint");
return this.Checkpoint__load();
}
private long Checkpoint__load() {
byte[] data = Io_mgr.Instance.LoadFilBryOrNull(checkpoint_url);
return data == null ? 0 : Long_.parse_or(String_.new_a7(data), 0);
}
public void Checkpoint__save(long new_val) {
if (new_val < checkpoint_nxt) return;
Io_mgr.Instance.SaveFilStr(checkpoint_url, Long_.To_str(new_val));
downloaded = new_val;
checkpoint_nxt += checkpoint_interval;
}
}

View File

@@ -0,0 +1,89 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.net.downloads; import gplx.*; import gplx.core.*; import gplx.core.net.*;
import java.io.*;
import java.net.*;
import gplx.core.progs.*;
public class Http_download_wkr__jre extends Http_download_wkr__base {
public Http_download_wkr Make_new() {return this;}
@Override public byte Exec_hook(Gfo_prog_ui prog_ui, String src_url, Io_url trg_url, long downloaded) {
long prog_data_cur = downloaded;
boolean prog_resumed = prog_data_cur > 0;
// get trg stream first to handle bad paths / permission errors
Io_mgr.Instance.CreateDirIfAbsent(trg_url.OwnerDir());
if (prog_resumed)
Io_mgr.Instance.Truncate_fil(trg_url, downloaded);
File trg_fil = new File(trg_url.Xto_api());
FileOutputStream trg_stream = null;
try {trg_stream = new FileOutputStream(trg_fil.getPath(), prog_resumed);} // pass true for append
catch (FileNotFoundException e) {throw Err_.new_("download_file", "write failed; permission error?", "trg", trg_url, "err", e.toString());}
// open src stream
InputStream src_stream = null;
URL src_url_itm = null;
try {src_url_itm = new URL(src_url);}
catch (MalformedURLException e) {throw Err_.new_("download_file", "bad url", "src", src_url, "err" + e.toString());}
HttpURLConnection src_conn = null;
try {
// open connection
src_conn = (HttpURLConnection)src_url_itm.openConnection();
if (prog_resumed)
src_conn.addRequestProperty("Range", "bytes=" + Long_.To_str(prog_data_cur) + "-");
src_conn.connect();
// check response code
int response_code = src_conn.getResponseCode();
if (prog_resumed) {
if (response_code != HttpURLConnection.HTTP_PARTIAL)
throw Err_.new_("download_file", "server returned non-partial response code", "src", src_url, "code", src_conn.getResponseCode(), "msg", src_conn.getResponseMessage());
}
else {
if (response_code != HttpURLConnection.HTTP_OK)
throw Err_.new_("download_file", "server returned non-OK response code", "src", src_url, "code", src_conn.getResponseCode(), "msg", src_conn.getResponseMessage());
}
src_stream = src_conn.getInputStream();
} catch (Exception e) {
throw Err_.new_("download_file", "src connection failed", "src", src_url, "err",e.toString());
}
// do downloading
try {
long prog_data_end = prog_ui.Prog_data_end();
if (prog_data_end == -1) prog_data_end = src_conn.getContentLength(); // NOTE: may be -1 if server does not report the length
byte data[] = new byte[4096];
int read = 0;
while ((read = src_stream.read(data)) != -1) {
prog_data_cur += read;
trg_stream.write(data, 0, read);
this.Checkpoint__save(prog_data_cur);
if (prog_ui.Prog_notify_and_chk_if_suspended(prog_data_cur, prog_data_end)) return Gfo_prog_ui_.Status__suspended;
}
} catch (Exception e) {
throw Err_.new_("download_file", "downloading failed", "src", src_url, "trg_url", trg_url, "err", e.toString());
}
finally {
try {
if (trg_stream != null) trg_stream.close();
if (src_stream != null) src_stream.close();
} catch (IOException e) {}
if (src_conn != null) src_conn.disconnect();
}
return Gfo_prog_ui_.Status__done;
}
}

View File

@@ -0,0 +1,24 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.net.emails; import gplx.*; import gplx.core.*; import gplx.core.net.*;
public interface Gfo_email_mgr {
void Send(String to, String subject, String body);
}
class Gfo_email_mgr__noop implements Gfo_email_mgr {
public void Send(String to, String subject, String body) {}
}

View File

@@ -0,0 +1,21 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.net.emails; import gplx.*; import gplx.core.*; import gplx.core.net.*;
public class Gfo_email_mgr_ {
public static Gfo_email_mgr Instance = new Gfo_email_mgr__noop();
}

View File

@@ -0,0 +1,22 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.net.emails; import gplx.*; import gplx.core.*; import gplx.core.net.*;
class Gfo_email_mgr__apache implements Gfo_email_mgr {
public void Send(String to, String subject, String body) {
}
}

View File

@@ -15,12 +15,13 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.apps.file_browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*;
public class Xoa_url_enum_itm {
package gplx.core.net.qargs; import gplx.*; import gplx.core.*; import gplx.core.net.*;
public class Gfo_qarg_enum_itm {
private final Hash_adp_bry hash = Hash_adp_bry.cs();
public Xoa_url_enum_itm(byte[] key) {this.key = key;}
public Gfo_qarg_enum_itm(String key) {this.key = Bry_.new_u8(key);}
public Gfo_qarg_enum_itm(byte[] key) {this.key = key;}
public byte[] Key() {return key;} private final byte[] key;
public Xoa_url_enum_itm Add(String key, int val) {
public Gfo_qarg_enum_itm Add(String key, int val) {
hash.Add_bry_int(Bry_.new_u8(key), val);
return this;
}

View File

@@ -15,15 +15,15 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.apps.file_browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*;
public class Xoa_url_enum_mgr {
package gplx.core.net.qargs; import gplx.*; import gplx.core.*; import gplx.core.net.*;
public class Gfo_qarg_enum_mgr {
private final Hash_adp_bry hash = Hash_adp_bry.cs();
public Xoa_url_enum_mgr(Xoa_url_enum_itm... ary) {
public Gfo_qarg_enum_mgr(Gfo_qarg_enum_itm... ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
Xoa_url_enum_itm itm = ary[i];
Gfo_qarg_enum_itm itm = ary[i];
hash.Add_bry_obj(itm.Key(), itm);
}
}
public Xoa_url_enum_itm Get(byte[] key) {return (Xoa_url_enum_itm)hash.Get_by_bry(key);}
public Gfo_qarg_enum_itm Get(byte[] key) {return (Gfo_qarg_enum_itm)hash.Get_by_bry(key);}
}

View File

@@ -15,13 +15,13 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.net; import gplx.*; import gplx.core.*;
package gplx.core.net.qargs; import gplx.*; import gplx.core.*; import gplx.core.net.*;
public class Gfo_qarg_itm {
public Gfo_qarg_itm(byte[] key_bry, byte[] val_bry) {this.key_bry = key_bry; this.val_bry = val_bry;}
public byte[] Key_bry() {return key_bry;} private byte[] key_bry;
public byte[] Val_bry() {return val_bry;} private byte[] val_bry;
public Gfo_qarg_itm Val_bry_(byte[] v) {val_bry = v; return this;}
public static final Gfo_qarg_itm[] Ary_empty = new Gfo_qarg_itm[0];
public static final Gfo_qarg_itm[] Ary_empty = new Gfo_qarg_itm[0];
public static Gfo_qarg_itm new_key_(String key) {return new Gfo_qarg_itm(Bry_.new_u8(key), Bry_.Empty);}
public static Gfo_qarg_itm[] Ary(String... kvs) {
int len = kvs.length;
@@ -38,7 +38,7 @@ public class Gfo_qarg_itm {
}
public static String To_str(Gfo_qarg_itm[] ary) {
int len = ary.length;
Bry_bfr bfr = Bry_bfr.new_();
Bry_bfr bfr = Bry_bfr_.New();
for (int i = 0; i < len; ++i) {
Gfo_qarg_itm itm = ary[i];
bfr.Add(itm.Key_bry()).Add_byte_eq();

View File

@@ -0,0 +1,62 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.net.qargs; import gplx.*; import gplx.core.*; import gplx.core.net.*;
public class Gfo_qarg_mgr {
private final Hash_adp_bry hash = Hash_adp_bry.cs();
public Gfo_qarg_mgr Init(Gfo_qarg_itm[] args) {
hash.Clear();
int len = args.length;
for (int i = 0; i < len; ++i) {
Gfo_qarg_itm arg = args[i];
hash.Add_bry_obj(arg.Key_bry(), arg);
}
return this;
}
public byte[] Read_bry_or_fail(String key) {return Read_bry_or_fail(Bry_.new_u8(key));}
public byte[] Read_bry_or_fail(byte[] key) {byte[] rv = Read_bry_or_null(key); if (rv == null) Fail_when_missing(String_.new_u8(key)); return rv;}
public byte[] Read_bry_or_empty(byte[] key) {return Read_bry_or(key, Bry_.Empty);}
public byte[] Read_bry_or_null(String key) {return Read_bry_or(Bry_.new_u8(key), null);}
public byte[] Read_bry_or_null(byte[] key) {return Read_bry_or(key, null);}
public byte[] Read_bry_or(byte[] key, byte[] or) {
Gfo_qarg_itm arg = (Gfo_qarg_itm)hash.Get_by_bry(key);
return arg == null ? or : arg.Val_bry();
}
public String Read_str_or_fail(String key) {String rv = Read_str_or_null(Bry_.new_u8(key)); if (rv == null) Fail_when_missing(key); return rv;}
public String Read_str_or_null(String key) {return Read_str_or_null(Bry_.new_u8(key));}
public String Read_str_or_null(byte[] key) {
Gfo_qarg_itm arg = (Gfo_qarg_itm)hash.Get_by_bry(key);
return arg == null ? null : String_.new_u8(arg.Val_bry());
}
public int Read_int_or(String key, int or) {return Read_int_or(Bry_.new_u8(key), or);}
public int Read_int_or(byte[] key, int or) {
byte[] val = Read_bry_or(key, null);
return val == null ? or : Int_.parse_or(String_.new_a7(val), or);
}
public int Read_enm_as_int_or(Gfo_qarg_enum_itm enm, int or) {
Gfo_qarg_itm arg = (Gfo_qarg_itm)hash.Get_by_bry(enm.Key());
return arg == null ? or : enm.Get_as_int_or(arg.Val_bry(), or);
}
private void Fail_when_missing(String key) {throw Err_.new_("", "url_arg missing", "key", key);}
// if (url_args.Read_enm(Enm_cmd.Itm) == Enm_cmd.Tid__add) {}
// public int Read_enm_or_neg1(byte[] key) {
// Gfo_qarg_enum_itm enm = enm_mgr.Get(key); if (enm == null) return -1;
// Gfo_qarg_itm arg = (Gfo_qarg_itm)hash.Get_by_bry(key); if (arg == null) return -1;
// return enm.Get_as_int_or(arg.Val_bry(), -1);
// }
}

View File

@@ -15,11 +15,11 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.net; import gplx.*; import gplx.core.*;
package gplx.core.net.qargs; import gplx.*; import gplx.core.*; import gplx.core.net.*;
import gplx.langs.htmls.encoders.*;
public class Gfo_qarg_mgr {
private final List_adp list = List_adp_.new_();
private final Hash_adp hash = Hash_adp_bry.cs();
public class Gfo_qarg_mgr_old {
private final List_adp list = List_adp_.New();
private final Hash_adp hash = Hash_adp_bry.cs();
public int Len() {return list.Count();}
public boolean Match(byte[] key, byte[] val) {
Gfo_qarg_itm arg = (Gfo_qarg_itm)hash.Get_by(key);
@@ -49,7 +49,7 @@ public class Gfo_qarg_mgr {
}
arg.Val_bry_(val);
}
public Gfo_qarg_mgr Load(Gfo_qarg_itm[] ary) {
public Gfo_qarg_mgr_old Load(Gfo_qarg_itm[] ary) {
hash.Clear();
list.Clear();
int len = ary.length;
@@ -72,7 +72,7 @@ public class Gfo_qarg_mgr {
}
public byte[] To_bry() {
int len = list.Count(); if (len == 0) return Bry_.Empty;
Bry_bfr bfr = Bry_bfr.new_();
Bry_bfr bfr = Bry_bfr_.New();
To_bry(bfr, gplx.langs.htmls.encoders.Gfo_url_encoder_.Href, false);
return bfr.To_bry_and_clear();
}

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.core.primitives; import gplx.*; import gplx.core.*;
import gplx.core.brys.*;
public class Bry_cache {
private final Hash_adp hash = Hash_adp_.new_(); private final Bry_obj_ref hash_ref = Bry_obj_ref.New_empty();
private final Hash_adp hash = Hash_adp_.New(); private final Bry_obj_ref hash_ref = Bry_obj_ref.New_empty();
public byte[] Get_or_new(String v) {return Get_or_new(Bry_.new_u8(v));}
public byte[] Get_or_new(byte[] v) {
if (v.length == 0) return Bry_.Empty;
@@ -31,5 +31,5 @@ public class Bry_cache {
else
return ((Bry_obj_ref)rv).Val();
}
public static final Bry_cache Instance = new Bry_cache(); Bry_cache() {}
public static final Bry_cache Instance = new Bry_cache(); Bry_cache() {}
}

View File

@@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.primitives; import gplx.*; import gplx.core.*;
public class Int_pool {
private final List_adp available_list = List_adp_.new_(); private int available_len;
// private final Bry_bfr dbg_bfr = Bry_bfr.new_();
private final List_adp available_list = List_adp_.New(); private int available_len;
// private final Bry_bfr dbg_bfr = Bry_bfr_.New();
private int uid_max = -1;
public void Clear() {
synchronized (available_list) {

View File

@@ -17,10 +17,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.primitives; import gplx.*; import gplx.core.*;
public class Number_parser {
public int Rv_as_int() {return (int)int_val;} private long int_val = 0;
public Decimal_adp Rv_as_dec() {return dec_val == null ? Decimal_adp_.long_(int_val) : dec_val;} private Decimal_adp dec_val = null;
public boolean Has_err() {return has_err;} private boolean has_err;
public boolean Has_frac() {return has_frac;} private boolean has_frac;
public int Rv_as_int() {return (int)num_val;} private long num_val = 0;
public long Rv_as_long() {return num_val;}
public Decimal_adp Rv_as_dec() {return dec_val == null ? Decimal_adp_.long_(num_val) : dec_val;} private Decimal_adp dec_val = null;
public boolean Is_int() {return dec_val == null && (num_val >= Int_.Min_value && num_val <= Int_.Max_value);}
public boolean Has_err() {return has_err;} private boolean has_err;
public boolean Has_frac() {return has_frac;} private boolean has_frac;
public boolean Hex_enabled() {return hex_enabled;} public Number_parser Hex_enabled_(boolean v) {hex_enabled = v; return this;} private boolean hex_enabled;
public Number_parser Ignore_chars_(byte[] v) {this.ignore_chars = v; return this;} private byte[] ignore_chars;
public Number_parser Ignore_space_at_end_y_() {this.ignore_space_at_end = true; return this;} private boolean ignore_space_at_end;
@@ -31,7 +33,7 @@ public class Number_parser {
public Number_parser Parse(byte[] ary, int bgn, int end) {
int loop_bgn = end - 1, loop_end = bgn - 1, exp_multiplier = 1, factor = 10;
long multiplier = 1, frc_multiplier = 1;
int_val = 0; dec_val = null; boolean comma_nil = true;
num_val = 0; dec_val = null; boolean comma_nil = true;
long frc_int = 0;
has_err = false; has_frac = false; boolean has_exp = false, has_neg = false, exp_neg = false, has_plus = false, has_num = false;
boolean input_is_hex = false;
@@ -64,14 +66,14 @@ public class Number_parser {
case Byte_ascii.Num_7:
case Byte_ascii.Num_8:
case Byte_ascii.Num_9:
int_val += (cur - Byte_ascii.Num_0) * multiplier;
num_val += (cur - Byte_ascii.Num_0) * multiplier;
multiplier *= factor;
has_num = true;
break;
case Byte_ascii.Dot:
if (has_frac) return Has_err_y_();
frc_int = int_val;
int_val = 0;
frc_int = num_val;
num_val = 0;
frc_multiplier = multiplier;
multiplier = 1;
has_frac = true;
@@ -99,15 +101,15 @@ public class Number_parser {
case Byte_ascii.Ltr_e:
case Byte_ascii.Ltr_E:
if (input_is_hex) {
int_val += 14 * multiplier; // NOTE: 14=value of e/E
num_val += 14 * multiplier; // NOTE: 14=value of e/E
multiplier *= factor;
has_num = true;
}
else {
if (has_exp) return Has_err_y_();
exp_neg = has_neg;
exp_multiplier = (int)Math_.Pow(10, int_val);
int_val = 0;
exp_multiplier = (int)Math_.Pow(10, num_val);
num_val = 0;
multiplier = 1;
has_exp = true;
has_neg = false;
@@ -120,7 +122,7 @@ public class Number_parser {
case Byte_ascii.Ltr_D:
case Byte_ascii.Ltr_F:
if (input_is_hex) {
int_val += (cur - Byte_ascii.Ltr_A + 10) * multiplier;
num_val += (cur - Byte_ascii.Ltr_A + 10) * multiplier;
multiplier *= factor;
has_num = true;
}
@@ -133,7 +135,7 @@ public class Number_parser {
case Byte_ascii.Ltr_d:
case Byte_ascii.Ltr_f:
if (input_is_hex) {
int_val += (cur - Byte_ascii.Ltr_a + 10) * multiplier;
num_val += (cur - Byte_ascii.Ltr_a + 10) * multiplier;
multiplier *= factor;
has_num = true;
}
@@ -163,7 +165,7 @@ public class Number_parser {
}
if (!has_num) return Has_err_y_(); // handles situations wherein just symbols; EX: "+", ".", "-.", " , " etc.
if (has_frac) {
long full_val = (((int_val * frc_multiplier) + frc_int));
long full_val = (((num_val * frc_multiplier) + frc_int));
if (has_neg) full_val *= -1;
if (has_exp) {
if (exp_neg) frc_multiplier *= exp_multiplier; // divide, so apply to frc
@@ -172,8 +174,12 @@ public class Number_parser {
dec_val = Decimal_adp_.divide_(full_val, frc_multiplier);
}
else {
if (has_neg) int_val *= -1;
if (has_exp) int_val = exp_neg ? int_val / exp_multiplier : int_val * exp_multiplier;
if (has_neg) num_val *= -1;
if (has_exp) {
num_val = exp_neg
? num_val / exp_multiplier
: num_val * exp_multiplier;
}
}
return this;
}

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.core.primitives; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Number_parser_tst {
private final Number_parser_fxt fxt = new Number_parser_fxt();
private final Number_parser_fxt fxt = new Number_parser_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Integer() {
fxt.Test_int("1", 1);
@@ -28,6 +28,9 @@ public class Number_parser_tst {
fxt.Test_int("+1", 1);
fxt.Test_int("00001", 1);
}
@Test public void Long() {
fxt.Test_long("9876543210", 9876543210L);
}
@Test public void Decimal() {
fxt.Test_dec("1.23", Decimal_adp_.parse("1.23"));
fxt.Test_dec("1.023", Decimal_adp_.parse("1.023"));
@@ -69,7 +72,7 @@ public class Number_parser_tst {
}
}
class Number_parser_fxt {
private final Number_parser parser = new Number_parser();
private final Number_parser parser = new Number_parser();
public void Clear() {parser.Clear();}
public void Init_ignore(String chars) {parser.Ignore_chars_(Bry_.new_a7(chars));}
public void Test_int(String raw, int expd) {
@@ -77,6 +80,10 @@ class Number_parser_fxt {
int actl = parser.Parse(raw_bry, 0, raw_bry.length).Rv_as_int();
Tfds.Eq(expd, actl, raw);
}
public void Test_long(String raw, long expd) {
byte[] raw_bry = Bry_.new_a7(raw);
Tfds.Eq(expd, parser.Parse(raw_bry, 0, raw_bry.length).Rv_as_long(), raw);
}
public void Test_dec(String raw, Decimal_adp expd) {
byte[] raw_bry = Bry_.new_a7(raw);
Decimal_adp actl = parser.Parse(raw_bry, 0, raw_bry.length).Rv_as_dec();

View File

@@ -0,0 +1,46 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.progs.rates; import gplx.*; import gplx.core.*; import gplx.core.progs.*;
import gplx.core.lists.rings.*;
public class Gfo_rate_list {
private final Ring__long ring;
public Gfo_rate_list(int size) {
this.ring = new Ring__long(size * 2); // *2 to store both data and time
}
public void Clear() {ring.Clear(); cur_rate = cur_delta = 0;}
public double Cur_rate() {return cur_rate;} private double cur_rate = 0;
public double Cur_delta() {return cur_delta;} private double cur_delta;
public double Add(long data, long time) {
ring.Add(data);
ring.Add(time);
double new_rate = Cur_calc(data, time);
cur_delta = cur_rate == 0 ? new_rate : Math_.Abs_double((new_rate - cur_rate) / cur_rate);
cur_rate = new_rate;
return cur_rate;
}
private double Cur_calc(long cur_data, long cur_time) {
int len = ring.Len();
long data_all = 0;
long time_all = 0;
for (int i = 0; i < len; i += 2) {
data_all += ring.Get_at(i);
time_all += ring.Get_at(i + 1);
}
return data_all / (time_all == 0 ? .001 : time_all);
}
}

View File

@@ -0,0 +1,36 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.progs.rates; import gplx.*; import gplx.core.*; import gplx.core.progs.*;
import org.junit.*; import gplx.core.tests.*;
public class Gfo_rate_list_tst {
private final Gfo_rate_list_fxt fxt = new Gfo_rate_list_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Add__1() {fxt.Add(100, 20).Test(5, 5);}
@Test public void Add__2() {fxt.Add(100, 20).Add(100, 30).Test(4, .20d);}
@Test public void Add__3() {fxt.Add(100, 20).Add(100, 30).Add(100, 50).Test(3, .25d);}
@Test public void Add__4() {fxt.Add(100, 20).Add(100, 30).Add(100, 50).Add(600, 0).Test(9, 2);}
}
class Gfo_rate_list_fxt {
private final Gfo_rate_list list = new Gfo_rate_list(6);
public void Clear() {list.Clear();}
public Gfo_rate_list_fxt Add(long data, long time) {list.Add(data, time); return this;}
public void Test(double expd_rate, double expd_delta) {
Gftest.Eq__double(expd_rate , list.Cur_rate() , "cur_rate");
Gftest.Eq__double(expd_delta, list.Cur_delta() , "cur_delta");
}
}

View File

@@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.progs.rates; import gplx.*; import gplx.core.*; import gplx.core.progs.*;
public class Gfo_rate_mgr {
private final Hash_adp hash = Hash_adp_.New();
private final int dflt_size;
public Gfo_rate_mgr(int dflt_size) {this.dflt_size = dflt_size;}
public void Clear() {hash.Clear();}
public int Len() {return hash.Count();}
public Gfo_rate_list Get_or_new(String k) {
Gfo_rate_list rv = (Gfo_rate_list)hash.Get_by(k);
if (rv == null) {
rv = new Gfo_rate_list(dflt_size);
rv.Add(1024 * 1024, 1); // add default rate of 1 MB per second
hash.Add(k, rv);
}
return rv;
}
public Gfo_rate_mgr Add_new(String key) {
Gfo_rate_list rv = new Gfo_rate_list(dflt_size);
hash.Add(key, rv);
return this;
}
}

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.security.files; import gplx.*; import gplx.core.*; import gplx.core.security.*;
public class Cksum_itm implements gplx.core.brys.Bry_bfr_able {
public Cksum_itm(byte[] hash, Io_url file_url, long file_size) {
this.Hash = hash; this.File_url = file_url; this.File_size = file_size;
}
public final byte[] Hash;
public final Io_url File_url;
public final long File_size;
public void To_bfr(Bry_bfr bfr) {
bfr.Add(Hash).Add_byte_pipe();
bfr.Add_str_u8(File_url.Raw()).Add_byte_pipe();
bfr.Add_long_variable(File_size);
}
}

View File

@@ -0,0 +1,84 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.security.files; import gplx.*; import gplx.core.*; import gplx.core.security.*;
public class Cksum_list {
public Cksum_list(byte type, Cksum_itm[] itms, long itms_size) {
this.Type = type; this.Itms = itms; this.Itms_size = itms_size;
}
public final byte Type;
public final Cksum_itm[] Itms;
public long Itms_size;
public Io_url[] Itms_ary() {
int len = Itms.length;
Io_url[] rv = new Io_url[len];
for (int i = 0; i < len; ++i)
rv[i] = Itms[i].File_url;
return rv;
}
public static Cksum_list Parse_by_fil(Io_url url) {
byte tid = Get_hash_tid_by_ext(url.Ext());
return Cksum_list.Parse(tid, url.OwnerDir(), Io_mgr.Instance.LoadFilBry(url));
}
public static Cksum_list Parse(byte type, Io_url owner_dir, byte[] bry) {
List_adp list = List_adp_.New();
byte[][] lines = Bry_split_.Split_lines(bry);
int len = lines.length;
long itms_size = 0;
for (int i = 0; i < len; ++i) {
byte[] line = lines[i]; // EX: "d41d8cd98f00b204e9800998ecf8427e *file.txt"
// get hash
int space_pos = Bry_find_.Find_fwd(line, Byte_ascii.Space);
if (space_pos == Bry_find_.Not_found) throw Err_.new_("chsum", "checksum line does not have space", "line", line);
byte[] hash = Bry_.Mid(line, 0, space_pos);
// get file
int file_bgn = space_pos + 1;
if (line[file_bgn] == Byte_ascii.Star) ++file_bgn; // ignore leading *; EX: "*file.txt" -> "file.txt"
byte[] file = Bry_.Mid(line, file_bgn);
Io_url file_url = GenSubFil_nest(owner_dir, file);
long file_size = Io_mgr.Instance.QueryFil(file_url).Size();
itms_size += file_size;
// add to list
Cksum_itm itm = new Cksum_itm(hash, file_url, file_size);
list.Add(itm);
}
return new Cksum_list(type, (Cksum_itm[])list.To_ary_and_clear(Cksum_itm.class), itms_size);
}
private static Io_url GenSubFil_nest(Io_url dir, byte[] src) { // split "a/b/c" or "a\b\c" -> [a, b, c]
byte dir_spr = gplx.core.envs.Op_sys.Lnx.Fsys_dir_spr_byte();
int dir_pos = Bry_find_.Find_fwd(src, dir_spr);
if (dir_pos == Bry_find_.Not_found) {
dir_spr = gplx.core.envs.Op_sys.Wnt.Fsys_dir_spr_byte();
dir_pos = Bry_find_.Find_fwd(src, dir_spr);
if (dir_pos == Bry_find_.Not_found)
return dir.GenSubFil(String_.new_u8(src));
}
byte[][] parts = Bry_split_.Split(src, dir_spr);
return dir.GenSubFil_nest(String_.Ary(parts));
}
private static byte Get_hash_tid_by_ext(String ext) {
if (String_.Eq(ext, ".md5")) return Hash_algo_.Tid__md5;
else if (String_.Eq(ext, ".sha1")) return Hash_algo_.Tid__sha1;
else if (String_.Eq(ext, ".sha256")) return Hash_algo_.Tid__sha2_256;
else throw Err_.new_unhandled_default(ext);
}
}

View File

@@ -0,0 +1,50 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.security.files; import gplx.*; import gplx.core.*; import gplx.core.security.*;
import org.junit.*; import gplx.core.tests.*;
public class Cksum_list_tst {
private final Cksum_list_fxt fxt = new Cksum_list_fxt();
@Test public void Basic() {
fxt.Init__file("a.txt").Init__file("ab.txt");
fxt.Test__parse(String_.Concat_lines_nl_skip_last
( "a5e54d1fd7bb69a228ef0dcd2431367e *a.txt"
, "90f15b7ca11bd4c70d9047cd29a80040 *ab.txt"
), 11
, fxt.Make__itm("a5e54d1fd7bb69a228ef0dcd2431367e", "a.txt", 5)
, fxt.Make__itm("90f15b7ca11bd4c70d9047cd29a80040", "ab.txt", 6)
);
}
}
class Cksum_list_fxt {
private final Io_url dir = Io_url_.mem_dir_("mem/dir/");
public Cksum_list_fxt() {
Io_mgr.Instance.InitEngine_mem();
}
public Cksum_list_fxt Init__file(String fil_name) {
Io_url fil_url = dir.GenSubFil(fil_name);
Io_mgr.Instance.SaveFilStr(fil_url, fil_name);
return this;
}
public Cksum_itm Make__itm(String hash, String file_name, long size) {return new Cksum_itm(Bry_.new_u8(hash), dir.GenSubFil(file_name), size);}
public Cksum_list_fxt Test__parse(String raw, long expd_size, Cksum_itm... expd_itms) {
Cksum_list actl_list = Cksum_list.Parse(gplx.core.security.Hash_algo_.Tid__md5, dir, Bry_.new_u8(raw));
Gftest.Eq__long(expd_size, actl_list.Itms_size);
Gftest.Eq__ary(expd_itms, actl_list.Itms);
return this;
}
}

View File

@@ -1,126 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.tests; import gplx.*; import gplx.core.*;
import gplx.core.brys.*;
public class Gftest {
private static final Bry_bfr bfr = Bry_bfr.new_();
public static void Eq__ary(String[] expd, byte[][] actl, String msg_fmt, Object... msg_args) {Eq__ary(Bry_.Ary(expd), actl, msg_fmt, msg_args);}
public static void Eq__ary(Bry_bfr_able[] expd_ary, Bry_bfr_able[] actl_ary) {Eq__ary(expd_ary, actl_ary, null);}
public static void Eq__ary(Bry_bfr_able[] expd_ary, Bry_bfr_able[] actl_ary, String msg_fmt, Object... msg_args) {
Eq__ary(Bry_bfr_able_.To_bry_ary(bfr, expd_ary), Bry_bfr_able_.To_bry_ary(bfr, actl_ary), msg_fmt, msg_args);
}
public static void Eq__ary(byte[][] expd_bry_ary, byte[][] actl_bry_ary, String msg_fmt, Object... msg_args) {
boolean[] failures = Calc__failures(Type_adp_.Tid__bry, expd_bry_ary, actl_bry_ary);
if (failures != null) {
Write_fail_head(bfr, msg_fmt, msg_args);
Write_fail_ary(bfr, failures, Type_adp_.Tid__bry, expd_bry_ary, actl_bry_ary);
throw Err_.new_wo_type(bfr.To_str_and_clear());
}
}
public static void Eq__str(String expd, String actl) {Eq__str(expd, actl, null);}
public static void Eq__str(String expd, String actl, String msg_fmt, Object... msg_args) {
if (String_.Eq(expd, actl)) return;
Write_fail_head(bfr, msg_fmt, msg_args);
bfr.Add_str_a7("expd: ").Add_str_u8(expd).Add_byte_nl();
bfr.Add_str_a7("actl: ").Add_str_u8(actl).Add_byte_nl();
bfr.Add(Bry__line_end);
throw Err_.new_wo_type(bfr.To_str_and_clear());
}
public static void Eq__bry(byte[] expd, byte[] actl) {Eq__bry(expd, actl, null);}
public static void Eq__bry(byte[] expd, byte[] actl, String msg_fmt, Object... msg_args) {
if (Bry_.Eq(expd, actl)) return;
Write_fail_head(bfr, msg_fmt, msg_args);
bfr.Add_str_a7("expd: ").Add(expd).Add_byte_nl();
bfr.Add_str_a7("actl: ").Add(actl).Add_byte_nl();
bfr.Add(Bry__line_end);
throw Err_.new_wo_type(bfr.To_str_and_clear());
}
private static void Write_fail_head(Bry_bfr bfr, String msg_fmt, Object[] msg_args) {
bfr.Add(Bry__line_bgn);
if (msg_fmt != null) {
bfr.Add_str_u8(String_.Format(msg_fmt, msg_args));
bfr.Add(Bry__line_mid);
}
}
private static void Write_fail_ary(Bry_bfr bfr, boolean[] failures, int type_id, Object expd_ary, Object actl_ary) {
int len = failures.length;
int expd_len = Array_.Len(expd_ary);
int actl_len = Array_.Len(actl_ary);
for (int i = 0; i < len; ++i) {
boolean failure = failures[i];
int pad_len = 5 - Int_.DigitCount(i);
bfr.Add_int_pad_bgn(Byte_ascii.Num_0, pad_len, i).Add_byte_colon().Add_byte_space();
Write__itm(bfr, type_id, expd_ary, expd_len, i);
if (failure) {
bfr.Add(Bry__item__eq_n).Add_byte_repeat(Byte_ascii.Space, pad_len - 1);
Write__itm(bfr, type_id, actl_ary, actl_len, i);
}
}
bfr.Add(Bry__line_end);
}
private static void Write__itm(Bry_bfr bfr, int type_id, Object ary, int len, int idx) {
if (idx < len) {
switch (type_id) {
case Type_adp_.Tid__bry: bfr.Add((byte[])Array_.Get_at(ary, idx)); break;
default: throw Err_.new_unhandled_default(type_id);
}
}
else
bfr.Add(Bry__null);
bfr.Add_byte_nl();
}
private static boolean[] Calc__failures(int tid, Object expd_ary, Object actl_ary) {
int expd_len = Array_.Len(expd_ary);
int actl_len = Array_.Len(actl_ary);
int max_len = expd_len > actl_len ? expd_len : actl_len; if (max_len == 0) return null;
boolean[] rv = null;
for (int i = 0; i < max_len; ++i) {
Object expd_obj = i < expd_len ? Array_.Get_at(expd_ary, i) : null;
Object actl_obj = i < actl_len ? Array_.Get_at(actl_ary, i) : null;
boolean eq = false;
switch (tid) {
case Type_adp_.Tid__bry: eq = Bry_.Eq((byte[])expd_obj, (byte[])actl_obj); break;
}
if (!eq) {
if (rv == null) {
rv = new boolean[max_len];
}
rv[i] = true;
}
}
return rv;
}
private static final byte[] Bry__item__eq_n = Bry_.new_a7("!= ") // Bry__item__eq_y = Bry_.new_a7("== "),
, Bry__null = Bry_.new_a7("<<NULL>>")
, Bry__line_bgn = Bry_.new_a7("\n************************************************************************************************\n")
, Bry__line_mid = Bry_.new_a7("\n------------------------------------------------------------------------------------------------\n")
, Bry__line_end = Bry_.new_a7( "________________________________________________________________________________________________")
;
}
/*
package ns;
import org.junit.*; import gplx.core.tests.*;
public class Cls1_tst {
private final Cls1_fxt fxt = new Cls1_fxt();
@Test public void Basic() {}
}
class Cls1_fxt {
private final Cls1 mgr = new Cls1();
public Cls1_fxt Test() {return this;}
}
*/

View File

@@ -19,7 +19,7 @@ package gplx.core.tests; import gplx.*; import gplx.core.*;
import gplx.core.strings.*;
public class Tst_mgr {
public Tst_mgr ThrowError_n_() {throwError = false; return this;} private boolean throwError = true;
public List_adp Results() {return results;} List_adp results = List_adp_.new_();
public List_adp Results() {return results;} List_adp results = List_adp_.New();
public Keyval_hash Vars() {return vars;} Keyval_hash vars = new Keyval_hash();
public Object Vars_get_by_key(String key) {return vars.Get_val_or(key, null);}
public String Vars_get_bry_as_str(String key, int bgn, int end) {
@@ -107,7 +107,7 @@ public class Tst_mgr {
return sb.To_str_and_clear();
}
int Max(int max, String s) {int len = String_.Len(s); return len > max ? len : max;}
public static final Tst_chkr Null_chkr = new Tst_chkr_null();
public static final Tst_chkr Null_chkr = new Tst_chkr_null();
}
class Tst_itm {
public boolean Pass() {return pass;} private boolean pass;

View File

@@ -16,9 +16,9 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.threads; import gplx.*; import gplx.core.*;
public class Gfo_async_cmd_itm implements GfoInvkAble {
private GfoInvkAble invk; private String invk_key; private GfoMsg msg = GfoMsg_.new_cast_("");
public Gfo_async_cmd_itm Init(GfoInvkAble invk, String invk_key, Object... args) {
public class Gfo_async_cmd_itm implements Gfo_invk {
private Gfo_invk invk; private String invk_key; private GfoMsg msg = GfoMsg_.new_cast_("");
public Gfo_async_cmd_itm Init(Gfo_invk invk, String invk_key, Object... args) {
this.invk = invk; this.invk_key = invk_key;
msg.Args_reset();
msg.Clear();
@@ -31,12 +31,12 @@ public class Gfo_async_cmd_itm implements GfoInvkAble {
return this;
}
public void Exec() {
GfoInvkAble_.InvkCmd_msg(invk, invk_key, msg);
Gfo_invk_.Invk_by_msg(invk, invk_key, msg);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_exec)) Exec();
else return GfoInvkAble_.Rv_unhandled;
else return Gfo_invk_.Rv_unhandled;
return this;
} private static final String Invk_exec = "exec";
public static final Gfo_async_cmd_itm[] Ary_empty = new Gfo_async_cmd_itm[0];
public static final Gfo_async_cmd_itm[] Ary_empty = new Gfo_async_cmd_itm[0];
}

View File

@@ -24,7 +24,7 @@ class Gfo_async_cmd_mkr {
// used = (Gfo_async_cmd_itm[])Array_.Resize(used, v);
// ary_len = v;
// }
public Gfo_async_cmd_itm Get(GfoInvkAble invk, String invk_key, Object... args) {
public Gfo_async_cmd_itm Get(Gfo_invk invk, String invk_key, Object... args) {
Gfo_async_cmd_itm rv = new Gfo_async_cmd_itm();
rv.Init(invk, invk_key, args);
return rv;

View File

@@ -17,11 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.threads; import gplx.*; import gplx.core.*;
import gplx.core.primitives.*;
public class Gfo_async_mgr implements GfoInvkAble {
private List_adp queue = List_adp_.new_();
public class Gfo_async_mgr implements Gfo_invk {
private List_adp queue = List_adp_.New();
private Bool_obj_ref running = Bool_obj_ref.n_();
private Gfo_async_cmd_mkr cmd_mkr = new Gfo_async_cmd_mkr();
public void Queue(GfoInvkAble invk, String invk_key, Object... args) {
public void Queue(Gfo_invk invk, String invk_key, Object... args) {
Gfo_async_cmd_itm cmd = cmd_mkr.Get(invk, invk_key, args);
synchronized (queue) {
queue.Add(cmd);
@@ -29,7 +29,7 @@ public class Gfo_async_mgr implements GfoInvkAble {
synchronized (running) {
if (running.Val_n()) {
running.Val_y_();
gplx.core.threads.Thread_adp_.invk_(Invk_run, this, Invk_run).Start();
Thread_adp_.Start_by_key(Invk_run, this, Invk_run);
}
}
}
@@ -52,7 +52,7 @@ public class Gfo_async_mgr implements GfoInvkAble {
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_run)) Run();
else return GfoInvkAble_.Rv_unhandled;
else return Gfo_invk_.Rv_unhandled;
return this;
} private static final String Invk_run = "run";
}

View File

@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.threads; import gplx.*; import gplx.core.*;
public interface Gfo_thread_cmd extends GfoInvkAble {
public interface Gfo_thread_cmd extends Gfo_invk {
void Cmd_ctor();
String Async_key();
int Async_sleep_interval();

View File

@@ -17,12 +17,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.threads; import gplx.*; import gplx.core.*;
import gplx.core.brys.fmtrs.*;
import gplx.gfui.*;
import gplx.gfui.*; import gplx.gfui.kits.core.*;
public class Gfo_thread_cmd_base implements Gfo_thread_cmd {
@gplx.Virtual public String Async_key() {return "undefined";}
public void Cmd_ctor() {}
public Gfo_thread_cmd_base Ctor(Gfo_usr_dlg usr_dlg, Gfui_kit kit) {this.usr_dlg = usr_dlg; this.kit = kit; return this;} protected Gfo_usr_dlg usr_dlg; protected Gfui_kit kit;
public GfoInvkAble Owner() {return owner;} public Gfo_thread_cmd_base Owner_(GfoInvkAble v) {owner = v; return this;} GfoInvkAble owner;
public Gfo_invk Owner() {return owner;} public Gfo_thread_cmd_base Owner_(Gfo_invk v) {owner = v; return this;} Gfo_invk owner;
public Bry_fmtr_eval_mgr Url_eval_mgr() {return url_eval_mgr;} public Gfo_thread_cmd_base Url_eval_mgr_(Bry_fmtr_eval_mgr v) {url_eval_mgr = v; return this;} Bry_fmtr_eval_mgr url_eval_mgr;
public Gfo_thread_cmd Async_next_cmd() {return next_cmd;} public void Async_next_cmd_(Gfo_thread_cmd v) {next_cmd = v;} Gfo_thread_cmd next_cmd;
@gplx.Virtual public int Async_sleep_interval() {return Gfo_thread_cmd_.Async_sleep_interval_1_second;}
@@ -36,7 +36,7 @@ public class Gfo_thread_cmd_base implements Gfo_thread_cmd {
@gplx.Virtual public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_owner)) return owner;
else if (ctx.Match(k, Invk_async_bgn)) Async_bgn();
else return GfoInvkAble_.Rv_unhandled;
else return Gfo_invk_.Rv_unhandled;
return this;
} private static final String Invk_owner = "owner", Invk_async_bgn = "async_bgn";
}

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.threads; import gplx.*; import gplx.core.*;
import gplx.core.brys.fmtrs.*;
import gplx.gfui.*;
import gplx.gfui.*; import gplx.gfui.kits.core.*;
public class Gfo_thread_cmd_download implements Gfo_thread_cmd {
public Gfo_thread_cmd Ctor(Gfo_usr_dlg usr_dlg, Gfui_kit kit) {this.usr_dlg = usr_dlg; this.kit = kit; xrg.Prog_dlg_(usr_dlg); return this;}
public Gfo_thread_cmd_download Init(String prog_fmt_hdr, String src, Io_url trg) {
@@ -25,7 +25,7 @@ public class Gfo_thread_cmd_download implements Gfo_thread_cmd {
xrg.Prog_fmt_hdr_(prog_fmt_hdr).Init(src, trg);
return this;
} String src; protected Gfui_kit kit; Gfo_usr_dlg usr_dlg; Io_url trg;
public GfoInvkAble Owner() {return owner;} public Gfo_thread_cmd_download Owner_(GfoInvkAble v) {owner = v; return this;} GfoInvkAble owner;
public Gfo_invk Owner() {return owner;} public Gfo_thread_cmd_download Owner_(Gfo_invk v) {owner = v; return this;} Gfo_invk owner;
public Bry_fmtr_eval_mgr Url_eval_mgr() {return url_eval_mgr;} public Gfo_thread_cmd_download Url_eval_mgr_(Bry_fmtr_eval_mgr v) {url_eval_mgr = v; return this;} Bry_fmtr_eval_mgr url_eval_mgr;
public void Cmd_ctor() {}
public Gfo_thread_cmd Async_next_cmd() {return next_cmd;} public void Async_next_cmd_(Gfo_thread_cmd v) {next_cmd = v;} Gfo_thread_cmd next_cmd;
@@ -51,7 +51,7 @@ public class Gfo_thread_cmd_download implements Gfo_thread_cmd {
}
public void Async_prog_run(int async_sleep_sum) {}
public boolean Async_running() {return xrg.Prog_running();}
public void Async_run() {Thread_adp_.invk_(gplx.xowa.apps.Xoa_thread_.Key_bldr_download, this, Invk_async_bgn).Start();}
public void Async_run() {Thread_adp_.Start_by_key(gplx.xowa.apps.Xoa_thread_.Key_bldr_download, this, Invk_async_bgn);}
private void Download() {
download_pass = true;
if (!xrg.Exec()) {
@@ -66,7 +66,7 @@ public class Gfo_thread_cmd_download implements Gfo_thread_cmd {
else if (ctx.Match(k, Invk_owner)) return owner;
else if (ctx.Match(k, Invk_src_)) src = m.ReadStr("v");
else if (ctx.Match(k, Invk_trg_)) trg = Bry_fmtr_eval_mgr_.Eval_url(url_eval_mgr, m.ReadBry("v"));
else return GfoInvkAble_.Rv_unhandled;
else return Gfo_invk_.Rv_unhandled;
return this;
} private static final String Invk_async_bgn = "async_bgn", Invk_owner = "owner", Invk_src_ = "src_", Invk_trg_ = "trg_";
static final String GRP_KEY = "gfo.thread.file.download";

View File

@@ -17,13 +17,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.threads; import gplx.*; import gplx.core.*;
import gplx.core.brys.fmtrs.*;
import gplx.gfui.*;
import gplx.gfui.*; import gplx.gfui.kits.core.*;
public class Gfo_thread_cmd_replace implements Gfo_thread_cmd {
public Gfo_thread_cmd Init(Gfo_usr_dlg usr_dlg, Gfui_kit kit, Io_url fil) {
this.usr_dlg = usr_dlg; this.kit = kit; this.fil = fil;
return this;
} Gfui_kit kit; Gfo_usr_dlg usr_dlg; Io_url fil;
public GfoInvkAble Owner() {return owner;} public Gfo_thread_cmd_replace Owner_(GfoInvkAble v) {owner = v; return this;} GfoInvkAble owner;
public Gfo_invk Owner() {return owner;} public Gfo_thread_cmd_replace Owner_(Gfo_invk v) {owner = v; return this;} Gfo_invk owner;
public Bry_fmtr_eval_mgr Url_eval_mgr() {return url_eval_mgr;} public Gfo_thread_cmd_replace Url_eval_mgr_(Bry_fmtr_eval_mgr v) {url_eval_mgr = v; return this;} Bry_fmtr_eval_mgr url_eval_mgr;
public String Async_key() {return KEY;}
public void Cmd_ctor() {}
@@ -48,13 +48,13 @@ public class Gfo_thread_cmd_replace implements Gfo_thread_cmd {
Io_mgr.Instance.SaveFilStr(fil, raw);
usr_dlg.Prog_many(GRP_KEY, "done", "replace completed: ~{0} ~{1}", fil.Raw(), pairs_len);
}
public List_adp pairs = List_adp_.new_();
public List_adp pairs = List_adp_.New();
@gplx.Virtual public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_async_bgn)) Exec_find_replace();
else if (ctx.Match(k, Invk_owner)) return owner;
else if (ctx.Match(k, Invk_fil_)) fil = Bry_fmtr_eval_mgr_.Eval_url(url_eval_mgr, m.ReadBry("v"));
else if (ctx.Match(k, Invk_add)) pairs.Add(Keyval_.new_(m.ReadStr("find"), m.ReadStr("replace")));
else return GfoInvkAble_.Rv_unhandled;
else return Gfo_invk_.Rv_unhandled;
return this;
} private static final String Invk_async_bgn = "async_bgn", Invk_owner = "owner", Invk_fil_ = "fil_", Invk_add = "add";
static final String GRP_KEY = "gfo.thread.file.download";

View File

@@ -17,14 +17,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.threads; import gplx.*; import gplx.core.*;
import gplx.core.brys.fmtrs.*; import gplx.core.envs.*;
import gplx.gfui.*; import gplx.xowa.bldrs.cmds.utils.*;
import gplx.gfui.*; import gplx.gfui.kits.core.*; import gplx.xowa.bldrs.cmds.utils.*;
public class Gfo_thread_cmd_unzip implements Gfo_thread_cmd {
public Gfo_thread_cmd_unzip Init(Gfo_usr_dlg usr_dlg, Gfui_kit kit, Process_adp bzip2_process, Process_adp zip_process, Process_adp gz_process, Io_url src, Io_url trg) {
this.src = src; this.trg = trg; this.kit = kit; this.usr_dlg = usr_dlg;
unzip_wkr = new Xob_unzip_wkr().Init(bzip2_process, zip_process, gz_process).Process_run_mode_(Process_adp.Run_mode_async);
return this;
} private Io_url src, trg; private Gfui_kit kit; private Gfo_usr_dlg usr_dlg; private Xob_unzip_wkr unzip_wkr;
public GfoInvkAble Owner() {return owner;} public Gfo_thread_cmd_unzip Owner_(GfoInvkAble v) {owner = v; return this;} GfoInvkAble owner;
public Gfo_invk Owner() {return owner;} public Gfo_thread_cmd_unzip Owner_(Gfo_invk v) {owner = v; return this;} Gfo_invk owner;
public void Cmd_ctor() {}
@gplx.Virtual public String Async_key() {return KEY;}
public Gfo_thread_cmd Async_next_cmd() {return next_cmd;} public void Async_next_cmd_(Gfo_thread_cmd v) {next_cmd = v;} Gfo_thread_cmd next_cmd;
@@ -102,7 +102,7 @@ public class Gfo_thread_cmd_unzip implements Gfo_thread_cmd {
else if (ctx.Match(k, Invk_rename_dir_)) rename_dir = m.ReadYn("v");
else if (ctx.Match(k, Invk_delete_trg_if_exists_)) delete_trg_if_exists = m.ReadYn("v");
else if (ctx.Match(k, Invk_term_cmd_for_src_)) term_cmd_for_src = Term_cmd_for_src_parse_(m.ReadStr("v"));
else return GfoInvkAble_.Rv_unhandled;
else return Gfo_invk_.Rv_unhandled;
return this;
} private static final String Invk_owner = "owner", Invk_src_ = "src_", Invk_trg_ = "trg_", Invk_rename_dir_ = "rename_dir_", Invk_delete_trg_if_exists_ = "delete_trg_if_exists_", Invk_term_cmd_for_src_ = "term_cmd_for_src_";
private static byte Term_cmd_for_src_parse_(String s) {

View File

@@ -16,9 +16,9 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.threads; import gplx.*; import gplx.core.*;
public class Gfo_thread_pool implements GfoInvkAble {
public class Gfo_thread_pool implements Gfo_invk {
private Object thread_lock = new Object();
private List_adp queue = List_adp_.new_();
private List_adp queue = List_adp_.New();
private GfoMsg run_msg = GfoMsg_.new_cast_(Invk_run_wkr);
private boolean running = false;
public Gfo_usr_dlg Usr_dlg() {return usr_dlg;} public Gfo_thread_pool Usr_dlg_(Gfo_usr_dlg v) {usr_dlg = v; return this;} private Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Noop;
@@ -41,21 +41,21 @@ public class Gfo_thread_pool implements GfoInvkAble {
running = true;
wkr = (Gfo_thread_wkr)List_adp_.Pop_first(queue);
}
Thread_adp_.Run_invk_msg(wkr.Name(), this, run_msg.Clear().Add("v", wkr));
Thread_adp_.Start_by_msg(wkr.Thread__name(), this, run_msg.Clear().Add("v", wkr));
}
private void Run_wkr(Gfo_thread_wkr wkr) {
try {wkr.Exec();}
try {wkr.Thread__exec();}
catch (Exception e) {
usr_dlg.Warn_many("", "", "uncaught exception while running thread; name=~{0} err=~{1}", wkr.Name(), Err_.Message_gplx_full(e));
usr_dlg.Warn_many("", "", "uncaught exception while running thread; name=~{0} err=~{1}", wkr.Thread__name(), Err_.Message_gplx_full(e));
}
finally {
if (wkr.Resume())
if (wkr.Thread__resume())
this.Resume();
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_run_wkr)) Run_wkr((Gfo_thread_wkr)m.ReadObj("v"));
else return GfoInvkAble_.Rv_unhandled;
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_run_wkr = "run_wkr";

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.threads; import gplx.*; import gplx.core.*;
public interface Gfo_thread_wkr {
String Name();
void Exec();
boolean Resume();
String Thread__name();
boolean Thread__resume();
void Thread__exec();
}

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.dbs; import gplx.*;
import gplx.dbs.metas.*; import gplx.dbs.sqls.*; import gplx.dbs.sqls.wtrs.*;
class Db_diff_bldr {
private final Bry_bfr bfr = Bry_bfr.new_();
private final Bry_bfr bfr = Bry_bfr_.New();
private final Sql_schema_wtr sql_bldr = new Sql_schema_wtr();
public Db_diff_bldr() {sql_bldr.Bfr_(bfr);}
public String Compare_db(String src_str, String trg_str) {

View File

@@ -0,0 +1,88 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.bulks; import gplx.*; import gplx.dbs.*;
import gplx.dbs.metas.*;
public class Db_bulk_exec_ {
public static void Insert(Db_bulk_prog prog_wkr, String msg, Dbmeta_fld_itm[] flds, Db_rdr src, Db_stmt trg, Db_conn trg_conn) {
// init
int flds_len = flds.length;
String[] fld_names = Db_bulk_exec_utl_.To_fld_names(flds, flds_len);
int[] fld_types = Db_bulk_exec_utl_.To_fld_types(flds, flds_len);
// loop all rows
Gfo_log_.Instance.Prog(msg);
trg_conn.Txn_bgn("bulk_insert");
try {
while (src.Move_next()) {
// fill insert
trg.Clear();
int row_size = 0;
for (int i = 0; i < flds_len; ++i) {
String fld_name = fld_names[i];
switch (fld_types[i]) {
case Dbmeta_fld_tid.Tid__bool : trg.Val_bool_as_byte (fld_name, src.Read_bool_by_byte (fld_name)); row_size += 1; break;
case Dbmeta_fld_tid.Tid__byte : trg.Val_byte (fld_name, src.Read_byte (fld_name)); row_size += 1; break;
case Dbmeta_fld_tid.Tid__int : trg.Val_int (fld_name, src.Read_int (fld_name)); row_size += 4; break;
case Dbmeta_fld_tid.Tid__long : trg.Val_long (fld_name, src.Read_long (fld_name)); row_size += 8; break;
case Dbmeta_fld_tid.Tid__float : trg.Val_float (fld_name, src.Read_float (fld_name)); row_size += 4; break;
case Dbmeta_fld_tid.Tid__double : trg.Val_double (fld_name, src.Read_double (fld_name)); row_size += 8; break;
case Dbmeta_fld_tid.Tid__str : String src_str = src.Read_str(fld_name); trg.Val_str(fld_name, src_str); row_size += src_str == null ? 0 : String_.Len(src_str); break;
case Dbmeta_fld_tid.Tid__bry : byte[] src_bry = src.Read_bry(fld_name); trg.Val_bry(fld_name, src_bry); row_size += src_bry == null ? 0 : src_bry.length; break;
default : throw Err_.new_unhandled_default(fld_types[i]);
}
}
// exec insert
try {trg.Exec_insert();}
catch (Exception e) {throw Db_bulk_exec_utl_.New_err(e, src, flds_len, fld_names, fld_types);}
// commit and notify if applicable
if (prog_wkr.Prog__insert_and_stop_if_suspended(row_size)) break;
}
}
catch (Exception e) {throw Err_.new_wo_type("dbs.bulk:insert failed", "err", e);}
finally {
trg_conn.Txn_end();
}
}
public static final String Invk__bulk_insert_err = "bulk.insert.err", Invk__bulk_insert_prog = "bulk.insert.prog";
}
class Db_bulk_exec_utl_ {
public static String[] To_fld_names(Dbmeta_fld_itm[] flds, int flds_len) {
String[] rv = new String[flds_len];
for (int i = 0; i < flds_len; ++i)
rv[i] = flds[i].Name();
return rv;
}
public static int[] To_fld_types(Dbmeta_fld_itm[] flds, int flds_len) {
int[] rv = new int[flds_len];
for (int i = 0; i < flds_len; ++i)
rv[i] = flds[i].Type().Tid_ansi();
return rv;
}
public static Err New_err(Exception e, Db_rdr rdr, int flds_len, String[] fld_names, int[] fld_types) {
Object[] args = new Object[(flds_len * 2) + 2];
for (int i = 0; i < flds_len; i += 2) {
args[i ] = fld_names[i];
args[i + 1] = rdr.Read_at(i);
}
args[flds_len - 2] = "err";
args[flds_len - 1] = Err_.Message_gplx_log(e);
return Err_.new_wo_type("dbs.bulk:insert row failed", args);
}
}

View File

@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.brys; import gplx.*; import gplx.core.*;
public interface Bry_bfr_able {
void To_bfr(Bry_bfr bfr);
package gplx.dbs.bulks; import gplx.*; import gplx.dbs.*;
public interface Db_bulk_prog {
boolean Prog__insert_and_stop_if_suspended(int row_size);
}

View File

@@ -0,0 +1,56 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.bulks; import gplx.*; import gplx.dbs.*;
import gplx.dbs.*; import gplx.dbs.metas.*;
public class Db_tbl_copy {
private final Bry_bfr bfr = Bry_bfr_.New();
private final Db_attach_mgr attach_mgr = new Db_attach_mgr();
public void Copy_many(Db_conn src_conn, Db_conn trg_conn, String... tbl_names) {
for (String tbl_name : tbl_names)
Copy_one(src_conn, trg_conn, tbl_name, tbl_name);
}
public void Copy_one(Db_conn src_conn, Db_conn trg_conn, String src_tbl, String trg_tbl) {
Dbmeta_tbl_itm tbl = src_conn.Meta_mgr().Get_by(src_tbl); if (tbl == null) throw Err_.new_wo_type("tbl does not exist", "tbl_name", src_tbl);
trg_conn.Meta_tbl_remake(Dbmeta_tbl_itm.New(trg_tbl, tbl.Flds().To_ary(), tbl.Idxs().To_ary()));
// do copy
attach_mgr.Conn_main_(trg_conn).Conn_others_(new Db_attach_itm("src_db", src_conn));
attach_mgr.Exec_sql(Bld_sql(tbl, src_tbl, trg_tbl));
}
public String Bld_sql(Dbmeta_tbl_itm tbl, String src_tbl, String trg_tbl) {
Dbmeta_fld_mgr flds = tbl.Flds();
int flds_len = flds.Len();
bfr.Add_str_a7("INSERT INTO ").Add_str_a7(trg_tbl).Add_byte_nl();
bfr.Add_byte(Byte_ascii.Paren_bgn);
for (int i = 0; i < flds_len; ++i) {
Dbmeta_fld_itm fld = flds.Get_at(i);
if (i != 0) bfr.Add_str_a7(", ");
bfr.Add_str_a7(fld.Name());
}
bfr.Add_byte(Byte_ascii.Paren_end).Add_byte_nl();
bfr.Add_str_a7("SELECT").Add_byte_nl().Add_byte_space();
for (int i = 0; i < flds_len; ++i) {
Dbmeta_fld_itm fld = flds.Get_at(i);
if (i != 0) bfr.Add_str_a7(", ");
bfr.Add_str_a7(fld.Name());
}
bfr.Add_byte_nl();
bfr.Add_str_a7("FROM <src_db>").Add_str_a7(src_tbl);
return bfr.To_str_and_clear();
}
}

View File

@@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.bulks; import gplx.*; import gplx.dbs.*;
import org.junit.*; import gplx.core.tests.*; import gplx.dbs.metas.*;
public class Db_tbl_copy_tst {
private final Db_tbl_copy_fxt fxt = new Db_tbl_copy_fxt();
@Test public void Basic() {
fxt.Test__bld_sql(fxt.Make_tbl("tbl_1", Dbmeta_fld_itm.new_int("fld_1"), Dbmeta_fld_itm.new_int("fld_2")),
String_.Concat_lines_nl_skip_last
( "INSERT INTO trg"
, "(fld_1, fld_2)"
, "SELECT"
, " fld_1, fld_2"
, "FROM <src_db>src"
));
}
}
class Db_tbl_copy_fxt {
private final Db_tbl_copy mgr = new Db_tbl_copy();
public Dbmeta_tbl_itm Make_tbl(String name, Dbmeta_fld_itm... flds) {return Dbmeta_tbl_itm.New(name, flds);}
public void Test__bld_sql(Dbmeta_tbl_itm tbl, String expd) {
Gftest.Eq__ary__lines(expd, mgr.Bld_sql(tbl, "src", "trg"), "sql");
}
}

View File

@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.dbs.cfgs; import gplx.*; import gplx.dbs.*;
public class Db_cfg_itm {
public Db_cfg_itm(String grp, String key, String val) {this.grp = grp; this.key = key; this.val = val;}
public String Grp() {return grp;} private final String grp;
public String Key() {return key;} private final String key;
public String Grp() {return grp;} private final String grp;
public String Key() {return key;} private final String key;
public String Val() {return val;} public Db_cfg_itm Val_(String v) {val = v; return this;} private String val;
public String To_str_or(String or) {return val == null ? or : val;}
public byte[] To_bry_or(byte[] or) {try {return val == null ? or : Bry_.new_u8(val) ;} catch (Exception e) {throw err_parse(e, Bry_.Cls_val_name);}}
@@ -29,7 +29,7 @@ public class Db_cfg_itm {
public boolean To_yn_or_n() {return To_yn_or(Bool_.N);}
public boolean To_yn_or(boolean or) {try {return val == null ? or : Yn.parse_by_char_or(val, or);} catch (Exception e) {throw err_parse(e, Bool_.Cls_val_name);}}
public DateAdp To_date_or(DateAdp or) {try {return val == null ? or : DateAdp_.parse_gplx(val) ;} catch (Exception e) {throw err_parse(e, DateAdp_.Cls_ref_name);}}
public Guid_adp To_guid_or(Guid_adp or) {try {return val == null ? or : Guid_adp_.parse(val) ;} catch (Exception e) {throw err_parse(e, Guid_adp_.Cls_ref_name);}}
public Guid_adp To_guid_or(Guid_adp or) {try {return val == null ? or : Guid_adp_.Parse(val) ;} catch (Exception e) {throw err_parse(e, Guid_adp_.Cls_ref_name);}}
public boolean To_bool() {Fail_if_null(); try {return Yn.parse(val) ;} catch (Exception e) {throw err_parse(e, Bool_.Cls_val_name);}}
public byte To_byte() {Fail_if_null(); try {return Byte_.parse(val) ;} catch (Exception e) {throw err_parse(e, Byte_.Cls_val_name);}}
public int To_int() {Fail_if_null(); try {return Int_.parse(val) ;} catch (Exception e) {throw err_parse(e, Int_.Cls_val_name);}}
@@ -53,5 +53,5 @@ public class Db_cfg_itm {
public static Db_cfg_itm new_DateAdp (String grp, String key, DateAdp val) {return new Db_cfg_itm(grp , key, val.XtoStr_fmt_yyyyMMdd_HHmmss());}
public static Db_cfg_itm new_guid (String key, Guid_adp val) {return new Db_cfg_itm(Grp_none , key, val.To_str());}
public static Db_cfg_itm new_guid (String grp, String key, Guid_adp val) {return new Db_cfg_itm(grp , key, val.To_str());}
public static final Db_cfg_itm Empty = new Db_cfg_itm("empty", "empty", null);
public static final Db_cfg_itm Empty = new Db_cfg_itm("empty", "empty", null);
}

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.dbs.cfgs; import gplx.*; import gplx.dbs.*;
import gplx.core.primitives.*;
public class Db_cfg_tbl implements Rls_able {
private final String tbl_name; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final String tbl_name; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_grp, fld_key, fld_val;
private Db_stmt stmt_insert, stmt_update, stmt_select;
public Db_conn Conn() {return conn;} private final Db_conn conn;
@@ -72,14 +72,14 @@ public class Db_cfg_tbl implements Rls_able {
if (cur_val == null) this.Insert_str(grp, key, val);
else this.Update_str(grp, key, val);
}
public boolean Select_yn (String grp, String key) {String val = Select_str(grp, key); return Parse_yn (grp, key, val);}
public boolean Select_yn (String grp, String key) {String val = Select_str(grp, key); return Parse_yn (grp, key, val);}
public byte Select_byte (String grp, String key) {String val = Select_str(grp, key); return Parse_byte (grp, key, val);}
public int Select_int (String grp, String key) {String val = Select_str(grp, key); return Parse_int (grp, key, val);}
public long Select_long (String grp, String key) {String val = Select_str(grp, key); return Parse_long (grp, key, val);}
public byte[] Select_bry (String grp, String key) {String val = Select_str(grp, key); return Parse_bry (grp, key, val);}
public DateAdp Select_date (String grp, String key) {String val = Select_str(grp, key); return Parse_date (grp, key, val);}
public Guid_adp Select_guid (String grp, String key) {String val = Select_str(grp, key); return Parse_guid (grp, key, val);}
public boolean Select_yn_or (String grp, String key, boolean or) {String val = Select_str_or(grp, key, null) ; return val == null ? or : Parse_yn (grp, key, val);}
public boolean Select_yn_or (String grp, String key, boolean or) {String val = Select_str_or(grp, key, null) ; return val == null ? or : Parse_yn (grp, key, val);}
public byte Select_byte_or (String grp, String key, byte or) {String val = Select_str_or(grp, key, null) ; return val == null ? or : Parse_byte (grp, key, val);}
public int Select_int_or (String grp, String key, int or) {String val = Select_str_or(grp, key, null) ; return val == null ? or : Parse_int (grp, key, val);}
public long Select_long_or (String grp, String key, long or) {String val = Select_str_or(grp, key, null) ; return val == null ? or : Parse_long (grp, key, val);}
@@ -131,6 +131,6 @@ public class Db_cfg_tbl implements Rls_able {
private long Parse_long (String grp, String key, String val) {try {return Long_.parse(val) ;} catch (Exception e) {throw err_parse(e, grp, key, val, Long_.Cls_val_name);}}
private byte[] Parse_bry (String grp, String key, String val) {try {return Bry_.new_u8(val) ;} catch (Exception e) {throw err_parse(e, grp, key, val, Bry_.Cls_val_name);}}
private DateAdp Parse_date (String grp, String key, String val) {try {return DateAdp_.parse_gplx(val) ;} catch (Exception e) {throw err_parse(e, grp, key, val, DateAdp_.Cls_ref_name);}}
private Guid_adp Parse_guid (String grp, String key, String val) {try {return Guid_adp_.parse(val) ;} catch (Exception e) {throw err_parse(e, grp, key, val, Guid_adp_.Cls_ref_name);}}
private Guid_adp Parse_guid (String grp, String key, String val) {try {return Guid_adp_.Parse(val) ;} catch (Exception e) {throw err_parse(e, grp, key, val, Guid_adp_.Cls_ref_name);}}
private Err err_parse(Exception e, String grp, String key, String val, String type) {return Err_.new_exc(e, "db", "cfg.val is not parseable", "grp", grp, "key", key, "val", val, "type", type);}
}

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.metas.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
public class Schema_update_mgr {
private List_adp cmds = List_adp_.new_();
private List_adp cmds = List_adp_.New();
public void Add(Schema_update_cmd cmd) {cmds.Add(cmd);}
public void Update(Schema_db_mgr schema_mgr, Db_conn conn) {
int cmds_len = cmds.Count();

View File

@@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.percentiles; import gplx.*; import gplx.dbs.*;
class Log_tbl_fmtr {
private final Bry_bfr bfr = Bry_bfr.new_();
private final List_adp itms = List_adp_.new_();
private final Bry_bfr bfr = Bry_bfr_.New();
private final List_adp itms = List_adp_.New();
private Log_fld_itm[] ary;
public Log_tbl_fmtr Add_str(String key, int len) {ary = null; itms.Add(new Log_fld_itm__bry(Type_adp_.Tid__bry, key, len)); return this;}
public Log_tbl_fmtr Add_int(String key, int bgn, int end) {ary = null; itms.Add(new Log_fld_itm__int(Type_adp_.Tid__int, key, bgn, end)); return this;}
@@ -43,8 +43,8 @@ abstract class Log_fld_itm__base implements Log_fld_itm {
public Log_fld_itm__base(int tid, String key, int len) {
this.tid = tid; this.key = key; this.len = len;
}
public int Tid() {return tid;} private final int tid;
public String Key() {return key;} private final String key;
public int Tid() {return tid;} private final int tid;
public String Key() {return key;} private final String key;
public int Len() {return len;} protected int len;
public abstract void Fmt(Bry_bfr bfr, Object val);
}
@@ -64,8 +64,8 @@ class Log_fld_itm__int extends Log_fld_itm__base {
this.bgn = bgn; this.end = end;
this.len = Int_.DigitCount(end);
}
public int Bgn() {return bgn;} private final int bgn;
public int End() {return end;} private final int end;
public int Bgn() {return bgn;} private final int bgn;
public int End() {return end;} private final int end;
@Override public void Fmt(Bry_bfr bfr, Object val) {
int val_int = Int_.cast(val);
String val_str = String_.PadBgn(Int_.To_str(val_int), this.Len(), " ");

View File

@@ -33,16 +33,16 @@ public class Fsdb_db_mgr_ {
}
String domain_str = wiki.Domain_str();
Fsdb_db_mgr rv = null;
rv = load_or_null(Xowd_db_layout.Itm_few, usr_dlg, wiki_dir, wiki, domain_str); if (rv != null) return rv;
rv = load_or_null(Xowd_db_layout.Itm_lot, usr_dlg, wiki_dir, wiki, domain_str); if (rv != null) return rv;
rv = load_or_null(Xowd_db_layout.Itm_all, usr_dlg, wiki_dir, wiki, domain_str); if (rv != null) return rv;
rv = load_or_null(Xow_db_layout.Itm_few, usr_dlg, wiki_dir, wiki, domain_str); if (rv != null) return rv;
rv = load_or_null(Xow_db_layout.Itm_lot, usr_dlg, wiki_dir, wiki, domain_str); if (rv != null) return rv;
rv = load_or_null(Xow_db_layout.Itm_all, usr_dlg, wiki_dir, wiki, domain_str); if (rv != null) return rv;
usr_dlg.Log_many("", "", "fsdb.db_core.none: wiki_dir=~{0} file_dir=~{1}", wiki_dir.Raw(), file_dir.Raw());
return null;
}
private static Fsdb_db_mgr load_or_null(Xowd_db_layout layout, Gfo_usr_dlg usr_dlg, Io_url wiki_dir, Xow_wiki wiki, String domain_str) {
private static Fsdb_db_mgr load_or_null(Xow_db_layout layout, Gfo_usr_dlg usr_dlg, Io_url wiki_dir, Xow_wiki wiki, String domain_str) {
Io_url main_core_url = wiki_dir.GenSubFil(Fsdb_db_mgr__v2_bldr.Main_core_name(layout, domain_str));
if (!Db_conn_bldr.Instance.Exists(main_core_url)) return null;
usr_dlg.Log_many("", "", "fsdb.db_core.v2: type=~{0} url=~{1}", layout.Name(), main_core_url.Raw());
usr_dlg.Log_many("", "", "fsdb.db_core.v2: type=~{0} url=~{1}", layout.Key(), main_core_url.Raw());
Db_conn main_core_conn = Db_conn_bldr.Instance.Get(main_core_url);
if (wiki.Data__core_mgr().Props().Layout_file().Tid_is_all()) {
return new Fsdb_db_mgr__v2(Fsdb_db_mgr__v2.Cfg__layout_file__get(main_core_conn), wiki_dir, new Fsdb_db_file(main_core_url, main_core_conn), new Fsdb_db_file(main_core_url, main_core_conn));

View File

@@ -18,10 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.fsdb; import gplx.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.fsdb.meta.*; import gplx.xowa.files.origs.*; import gplx.xowa.wikis.data.*;
public class Fsdb_db_mgr__v2 implements Fsdb_db_mgr {
private final Xowd_db_layout layout; private final Io_url wiki_dir;
private final Xow_db_layout layout; private final Io_url wiki_dir;
private final Fsdb_db_file file_main_core, file_user_core;
private final Xof_orig_tbl[] orig_tbl_ary;
public Fsdb_db_mgr__v2(Xowd_db_layout layout, Io_url wiki_dir, Fsdb_db_file file_main_core, Fsdb_db_file file_user_core) {
public Fsdb_db_mgr__v2(Xow_db_layout layout, Io_url wiki_dir, Fsdb_db_file file_main_core, Fsdb_db_file file_user_core) {
this.layout = layout; this.wiki_dir = wiki_dir;
this.file_main_core = file_main_core; this.file_user_core = file_user_core;
this.orig_tbl_ary = new Xof_orig_tbl[]
@@ -55,12 +55,12 @@ public class Fsdb_db_mgr__v2 implements Fsdb_db_mgr {
gplx.xowa.wikis.data.Xowd_cfg_tbl_.New(conn).Create_tbl();
return Fsdb_db_mgr__v2_bldr.Make_bin_tbl(new Fsdb_db_file(url, conn));
}
public static Xowd_db_layout Cfg__layout_file__get(Db_conn main_core_conn) {
public static Xow_db_layout Cfg__layout_file__get(Db_conn main_core_conn) {
Db_cfg_tbl cfg_tbl = gplx.xowa.wikis.data.Xowd_cfg_tbl_.New(main_core_conn);
return Xowd_db_layout.get_(cfg_tbl.Select_str_or(gplx.xowa.wikis.Xow_cfg_consts.Grp__bldr_fsdb, Cfg_key__layout_file, Xowd_db_layout.Name_few));
return Xow_db_layout.Get_by_name(cfg_tbl.Select_str_or(gplx.xowa.wikis.Xow_cfg_consts.Grp__bldr_fsdb, Cfg_key__layout_file, Xow_db_layout.Key__few));
}
public static void Cfg__layout_file__set(Db_cfg_tbl cfg_tbl, Xowd_db_layout v) {
cfg_tbl.Insert_str(gplx.xowa.wikis.Xow_cfg_consts.Grp__bldr_fsdb, Cfg_key__layout_file, v.Name());
public static void Cfg__layout_file__set(Db_cfg_tbl cfg_tbl, Xow_db_layout v) {
cfg_tbl.Insert_str(gplx.xowa.wikis.Xow_cfg_consts.Grp__bldr_fsdb, Cfg_key__layout_file, v.Key());
}
private static final String Cfg_key__layout_file = "layout_file";
}

View File

@@ -20,7 +20,7 @@ import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.fsdb.meta.*; import gplx.
import gplx.xowa.*; import gplx.xowa.wikis.data.*; import gplx.xowa.bldrs.infos.*;
public class Fsdb_db_mgr__v2_bldr {
public static Fsdb_db_mgr__v2 Get_or_make(Xow_wiki wiki, boolean delete_if_exists) { // NOTE: must check if file exists else imports with existing v2 dbs will fail; DATE:2015-05-23
Xowd_db_layout layout = wiki.Data__core_mgr().Props().Layout_file();
Xow_db_layout layout = wiki.Data__core_mgr().Props().Layout_file();
String domain_str = wiki.Domain_str();
Io_url wiki_dir = wiki.Fsys_mgr().Root_dir();
String main_core_name = Main_core_name(layout, domain_str);
@@ -38,7 +38,7 @@ public class Fsdb_db_mgr__v2_bldr {
return new Fsdb_db_mgr__v2(layout, wiki_dir, main_core_file, user_core_file);
}
private static Fsdb_db_file Load_core_file(Io_url url) {return new Fsdb_db_file(url, Db_conn_bldr.Instance.Get(url));}
private static Fsdb_db_file Make_core_file_main(Xow_wiki wiki, Io_url main_core_url, String main_core_name, Xowd_db_layout layout) {
private static Fsdb_db_file Make_core_file_main(Xow_wiki wiki, Io_url main_core_url, String main_core_name, Xow_db_layout layout) {
Db_conn conn = layout.Tid_is_all() ? Db_conn_bldr.Instance.Get(main_core_url) : Db_conn_bldr.Instance.New(main_core_url); // if all, use existing (assumes same file name); else, create new
conn.Txn_bgn("fsdb__core_file");
Fsdb_db_file rv = Make_core_file(main_core_url, conn, schema_is_1, Fsm_mnt_mgr.Mnt_idx_main);
@@ -54,7 +54,7 @@ public class Fsdb_db_mgr__v2_bldr {
Fsdb_db_file rv = Make_core_file(user_core_url, conn, schema_is_1, Fsm_mnt_mgr.Mnt_idx_user);
Fsm_bin_tbl dbb_tbl = new Fsm_bin_tbl(conn, schema_is_1, Fsm_mnt_mgr.Mnt_idx_user); dbb_tbl.Insert(0, user_file_name);
Make_bin_tbl(rv);
Make_cfg_data(wiki, main_core_name, rv, Xowd_db_file_.Tid_file_user, -1);
Make_cfg_data(wiki, main_core_name, rv, Xow_db_file_.Tid__file_user, -1);
conn.Txn_end();
return rv;
}
@@ -81,27 +81,27 @@ public class Fsdb_db_mgr__v2_bldr {
Fsd_bin_tbl bin_tbl = new Fsd_bin_tbl(file.Conn(), schema_is_1); bin_tbl.Create_tbl();
return file;
}
public static String Main_core_name(Xowd_db_layout layout, String wiki_domain) {
public static String Main_core_name(Xow_db_layout layout, String wiki_domain) {
switch (layout.Tid()) {
case Xowd_db_layout.Const_all: return Main_core_name_all(wiki_domain);
case Xowd_db_layout.Const_few: return Main_core_name_few(wiki_domain);
case Xowd_db_layout.Const_lot: return Main_core_name_lot(wiki_domain);
case Xow_db_layout.Tid__all: return Main_core_name_all(wiki_domain);
case Xow_db_layout.Tid__few: return Main_core_name_few(wiki_domain);
case Xow_db_layout.Tid__lot: return Main_core_name_lot(wiki_domain);
default: throw Err_.new_unimplemented();
}
}
private static byte Main_core_tid(Xowd_db_layout layout) {
private static byte Main_core_tid(Xow_db_layout layout) {
switch (layout.Tid()) {
case Xowd_db_layout.Const_all: return Xowd_db_file_.Tid_core;
case Xowd_db_layout.Const_few: return Xowd_db_file_.Tid_file_solo;
case Xowd_db_layout.Const_lot: return Xowd_db_file_.Tid_file_core;
case Xow_db_layout.Tid__all: return Xow_db_file_.Tid__core;
case Xow_db_layout.Tid__few: return Xow_db_file_.Tid__file_solo;
case Xow_db_layout.Tid__lot: return Xow_db_file_.Tid__file_core;
default: throw Err_.new_unimplemented();
}
}
public static void Make_cfg_data(Xow_wiki wiki, String file_core_name, Fsdb_db_file file, byte file_tid, int part_id) {
Db_cfg_tbl cfg_tbl = file.Tbl__cfg();
Xowd_db_file core_db = wiki.Data__core_mgr().Db__core();
Xow_db_file core_db = wiki.Data__core_mgr().Db__core();
core_db.Info_session().Save(cfg_tbl);
Xob_info_file info_file = new Xob_info_file(-1, Xowd_db_file_.To_key(file_tid), Xob_info_file.Ns_ids_empty, part_id, Guid_adp_.new_(), 2, file_core_name, file.Url().NameAndExt());
Xob_info_file info_file = new Xob_info_file(-1, Xow_db_file_.To_key(file_tid), Xob_info_file.Ns_ids_empty, part_id, Guid_adp_.New(), 2, file_core_name, file.Url().NameAndExt());
info_file.Save(cfg_tbl);
}
private static String Main_core_name_all(String wiki_domain) {return wiki_domain + ".xowa";} // EX: en.wikipedia.org.xowa

View File

@@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.fsdb.data; import gplx.*; import gplx.fsdb.*;
public class Fsd_bin_itm {
public Fsd_bin_itm(int bin_owner_id, byte bin_owner_tid, int bin_part_id, String bin_data_url, byte[] bin_data) {
this.bin_owner_id = bin_owner_id;
this.bin_owner_tid = bin_owner_tid;
this.bin_part_id = bin_part_id;
this.bin_data_url = bin_data_url;
this.bin_data = bin_data;
}
public int Bin_owner_id() {return bin_owner_id;} private final int bin_owner_id;
public byte Bin_owner_tid() {return bin_owner_tid;} private final byte bin_owner_tid;
public int Bin_part_id() {return bin_part_id;} private final int bin_part_id;
public String Bin_data_url() {return bin_data_url;} private final String bin_data_url;
public byte[] Bin_data() {return bin_data;} private final byte[] bin_data;
public static final int Db_row_size_fixed = (3 * 4); // bin_owner_id, bin_part_id, bin_owner_tid (assume byte saved as int in SQLITE)
}

View File

@@ -17,13 +17,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.fsdb.data; import gplx.*; import gplx.fsdb.*;
import gplx.core.primitives.*; import gplx.core.envs.*;
import gplx.dbs.*; import gplx.core.ios.*;
import gplx.dbs.*; import gplx.core.ios.*; import gplx.core.ios.streams.*;
import gplx.dbs.engines.sqlite.*;
public class Fsd_bin_tbl implements Rls_able {
private final String tbl_name = "fsdb_bin"; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final String fld_owner_id, fld_owner_tid, fld_part_id, fld_data_url, fld_data;
private Db_conn conn; private Db_stmt stmt_insert, stmt_select; private Bry_bfr tmp_bfr;
private final Bool_obj_ref saved_in_parts = Bool_obj_ref.n_();
public class Fsd_bin_tbl implements Rls_able {
private final String fld_owner_id, fld_owner_tid, fld_part_id, fld_data_url, fld_data;
private Db_conn conn; private Db_stmt stmt_insert, stmt_select, stmt_select_itm; private Bry_bfr tmp_bfr;
private final Bool_obj_ref saved_in_parts = Bool_obj_ref.n_();
public Fsd_bin_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;
fld_owner_id = flds.Add_int_pkey ("bin_owner_id");
@@ -33,9 +32,12 @@ public class Fsd_bin_tbl implements Rls_able {
fld_data = flds.Add_bry ("bin_data"); // mediumblob
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private final String tbl_name = "fsdb_bin";
public Dbmeta_fld_list Flds() {return flds;} private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
public void Rls() {
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_select = Db_stmt_.Rls(stmt_select);
stmt_select_itm = Db_stmt_.Rls(stmt_select_itm);
}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Insert_bgn() {conn.Txn_bgn("fsdb_bin__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
@@ -44,7 +46,7 @@ public class Fsd_bin_tbl implements Rls_able {
public void Insert_rdr(int id, byte tid, long bin_len, Io_stream_rdr bin_rdr) {
if (stmt_insert == null) {
stmt_insert = conn.Stmt_insert(tbl_name, flds);
tmp_bfr = Bry_bfr.reset_(Io_mgr.Len_kb);
tmp_bfr = Bry_bfr_.Reset(Io_mgr.Len_kb);
}
byte[] bin_ary = null;
bin_ary = Io_stream_rdr_.Load_all_as_bry(tmp_bfr, bin_rdr);
@@ -78,7 +80,7 @@ public class Fsd_bin_tbl implements Rls_able {
byte[] rv = null;
try {rv = rdr.Read_bry(fld_data);}
catch (Exception e) {
if ( Op_sys.Cur().Tid_is_drd()
if ( Op_sys.Cur().Tid_is_drd() // drd error when selecting large blobs (> 4 MB?)
&& url != null // called by Select_to_url
&& String_.Has(Err_.Message_lang(e), "get field slot from row") // get field slot from row 0 col 0 failed
) {
@@ -93,6 +95,24 @@ public class Fsd_bin_tbl implements Rls_able {
}
finally {rdr.Rls();}
}
public Fsd_bin_itm Select_as_itm(int owner_id) {
if (stmt_select_itm == null) stmt_select_itm = conn.Stmt_select(tbl_name, flds, fld_owner_id);
Db_rdr rdr = stmt_select_itm.Clear().Crt_int(fld_owner_id, owner_id).Exec_select__rls_manual();
try {
if (rdr.Move_next()) {
return new Fsd_bin_itm
( rdr.Read_int(fld_owner_id)
, rdr.Read_byte(fld_owner_tid)
, rdr.Read_int(fld_part_id)
, rdr.Read_str(fld_data_url)
, rdr.Read_bry(fld_data)
);
}
else
return null;
}
finally {rdr.Rls();}
}
public static final byte Owner_tid_fil = 1, Owner_tid_thm = 2;
public static final int Bin_db_id_null = -1, Size_null = -1;
private static final int Part_id_null = -1;

View File

@@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.fsdb.data; import gplx.*; import gplx.fsdb.*;
public class Fsd_dir_itm {
public Fsd_dir_itm(int dir_id, int owner, byte[] name) {this.dir_id = dir_id; this.owner = owner; this.name = name;}
public int Dir_id() {return dir_id;} private final int dir_id;
public int Owner() {return owner;} private final int owner;
public byte[] Name() {return name;} private final byte[] name;
public int Dir_id() {return dir_id;} private final int dir_id;
public int Owner() {return owner;} private final int owner;
public byte[] Name() {return name;} private final byte[] name;
public static final int Owner_root = 0;
public static final Fsd_dir_itm Null = null;
public static final Fsd_dir_itm Null = null;
}

View File

@@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.fsdb.data; import gplx.*; import gplx.fsdb.*;
import gplx.dbs.*;
public class Fsd_dir_tbl implements Rls_able {
private final String tbl_name = "fsdb_dir"; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final String fld_id, fld_owner_id, fld_name;
private final Db_conn conn; private Db_stmt stmt_insert, stmt_update, stmt_select_by_name;
private final String tbl_name = "fsdb_dir"; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_id, fld_owner_id, fld_name;
private final Db_conn conn; private Db_stmt stmt_insert, stmt_update, stmt_select_by_name;
public Fsd_dir_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;
this.fld_id = flds.Add_int_pkey ("dir_id");

View File

@@ -17,17 +17,35 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.fsdb.data; import gplx.*; import gplx.fsdb.*;
public class Fsd_fil_itm {
public int Mnt_id() {return mnt_id;} private int mnt_id;
public int Fil_id() {return fil_id;} private int fil_id;
public int Dir_id() {return dir_id;} private int dir_id;
public int Xtn_id() {return xtn_id;} private int xtn_id;
public int Ext_id() {return ext_id;} private int ext_id;
public byte[] Name() {return name;} private byte[] name;
public int Bin_db_id() {return bin_db_id;} private int bin_db_id;
public long Size() {return size;} private long size;
public String Modified_on() {return modified_on;} private String modified_on;
public String Hash_md5() {return hash_md5;} private String hash_md5;
public Fsd_fil_itm Ctor(int mnt_id, int dir_id, int fil_id, int bin_db_id, byte[] name, int ext_id) {
this.mnt_id = mnt_id; this.dir_id = dir_id; this.fil_id = fil_id; this.bin_db_id = bin_db_id; this.name = name; this.ext_id = ext_id;
return this;
}
public int Mnt_id() {return mnt_id;} private int mnt_id;
public int Fil_id() {return fil_id;} private int fil_id;
public int Dir_id() {return dir_id;} private int dir_id;
public int Bin_db_id() {return bin_db_id;} private int bin_db_id;
public byte[] Name() {return name;} private byte[] name;
public int Ext_id() {return ext_id;} private int ext_id;
public static final Fsd_fil_itm Null = null;
public Fsd_fil_itm Load_by_rdr__full(int mnt_id, int dir_id, int fil_id, int xtn_id, int ext_id, byte[] name, long size, String modified_on, String hash_md5, int bin_db_id) {
this.mnt_id = mnt_id; this.dir_id = dir_id; this.fil_id = fil_id; this.xtn_id = xtn_id; this.ext_id = ext_id;
this.name = name; this.size = size; this.modified_on = modified_on; this.hash_md5 = hash_md5; this.bin_db_id = bin_db_id;
return this;
}
public int Db_row_size() {return Db_row_size_fixed + name.length;}
private static final int Db_row_size_fixed =
(7 * 4) // 6 int fields + 1 byte field
+ 8 // 1 long field
+ 32 // hash_md5
+ 14 // modified_on
;
public static final Fsd_fil_itm Null = null;
public static byte[] Gen_cache_key(Bry_bfr bfr, int dir_id, byte[] name) {
return bfr.Add_int_variable(dir_id).Add_byte_pipe().Add(name).To_bry_and_clear();
}

View File

@@ -18,10 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.fsdb.data; import gplx.*; import gplx.fsdb.*;
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.dbs.engines.sqlite.*;
public class Fsd_fil_tbl implements Rls_able {
private final String tbl_name = "fsdb_fil"; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final String fld_id, fld_owner_id, fld_name, fld_xtn_id, fld_ext_id, fld_size, fld_modified, fld_hash, fld_bin_db_id;
private final String idx_owner;
private Db_conn conn; private Db_stmt stmt_insert, stmt_update, stmt_select_by_name; private int mnt_id;
public final String tbl_name = "fsdb_fil"; public final Dbmeta_fld_list flds = new Dbmeta_fld_list();
public final String fld_id, fld_owner_id, fld_name, fld_xtn_id, fld_ext_id, fld_size, fld_modified, fld_hash, fld_bin_db_id;
private final String idx_owner;
public final Db_conn conn; private Db_stmt stmt_insert, stmt_update, stmt_select_by_name; private int mnt_id;
public Fsd_fil_tbl(Db_conn conn, boolean schema_is_1, int mnt_id) {
this.conn = conn; this.mnt_id = mnt_id;
this.fld_id = flds.Add_int_pkey ("fil_id");
@@ -48,7 +48,10 @@ public class Fsd_fil_tbl implements Rls_able {
}
public void Insert(int id, int owner_id, byte[] name, int xtn_id, int ext_id, long size, int bin_db_id) {
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_insert.Clear()
Insert(stmt_insert, id, owner_id, name, xtn_id, ext_id, size, bin_db_id, String_.Empty, String_.Empty);
}
public void Insert(Db_stmt stmt, int id, int owner_id, byte[] name, int xtn_id, int ext_id, long size, int bin_db_id, String modified_on, String hash_md5) {
stmt.Clear()
.Val_int(fld_id, id)
.Val_int(fld_owner_id, owner_id)
.Val_int(fld_xtn_id, xtn_id)
@@ -56,8 +59,8 @@ public class Fsd_fil_tbl implements Rls_able {
.Val_int(fld_bin_db_id, bin_db_id)
.Val_bry_as_str(fld_name, name)
.Val_long(fld_size, size)
.Val_str(fld_modified, String_.Empty)
.Val_str(fld_hash, String_.Empty)
.Val_str(fld_modified, modified_on)
.Val_str(fld_hash, hash_md5)
.Exec_insert();
}
public void Update(int id, int owner_id, byte[] name, int xtn_id, int ext_id, long size, int bin_db_id) {
@@ -84,7 +87,7 @@ public class Fsd_fil_tbl implements Rls_able {
.Crt_bry_as_str(fld_name, fil_name)
.Exec_select__rls_manual();
try {
return rdr.Move_next() ? new_(mnt_id, rdr) : Fsd_fil_itm.Null;
return rdr.Move_next() ? Load_by_rdr(mnt_id, rdr) : Fsd_fil_itm.Null;
}
finally {rdr.Rls();}
}
@@ -92,14 +95,28 @@ public class Fsd_fil_tbl implements Rls_able {
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, Dbmeta_fld_itm.Str_ary_empty).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
Fsd_fil_itm fil = new_(mnt_id, rdr);
Fsd_fil_itm fil = Load_by_rdr(mnt_id, rdr);
byte[] cache_key = Fsd_fil_itm.Gen_cache_key(key_bfr, fil.Dir_id(), fil.Name());
cache.Add(cache_key, fil);
}
}
finally {rdr.Rls();}
}
private Fsd_fil_itm new_(int mnt_id, Db_rdr rdr) {
public Fsd_fil_itm Load_by_rdr(int mnt_id, Db_rdr rdr) {
return new Fsd_fil_itm().Ctor(mnt_id, rdr.Read_int(fld_owner_id), rdr.Read_int(fld_id), rdr.Read_int(fld_bin_db_id), rdr.Read_bry_by_str(fld_name), rdr.Read_int(fld_ext_id));
}
public Fsd_fil_itm Load_by_rdr__full(int mnt_id, Db_rdr rdr) {
return new Fsd_fil_itm()
.Load_by_rdr__full(mnt_id
, rdr.Read_int(fld_owner_id)
, rdr.Read_int(fld_id)
, rdr.Read_int(fld_xtn_id)
, rdr.Read_int(fld_ext_id)
, rdr.Read_bry_by_str(fld_name)
, rdr.Read_long(fld_size)
, rdr.Read_str(fld_modified)
, rdr.Read_str(fld_hash)
, rdr.Read_int(fld_bin_db_id)
);
}
}

View File

@@ -44,8 +44,16 @@ public class Fsd_thm_itm {
this.w = comp.w; this.h = comp.h; this.time = comp.time; this.page = comp.page;
this.size = comp.size; this.modified = comp.modified; this.hash = comp.hash;
}
public static final Fsd_thm_itm Null = null;
public static final Fsd_thm_itm[] Ary_empty = new Fsd_thm_itm[0];
public int Db_row_size() {return Db_row_size_fixed;}
private static final int Db_row_size_fixed =
(7 * 4) // 7 ints
+ (2 * 8) // 1 long; 1 double
+ 32 // hash_md5
+ 14 // modified_on
;
public static final Fsd_thm_itm Null = null;
public static final Fsd_thm_itm[] Ary_empty = new Fsd_thm_itm[0];
public static Fsd_thm_itm new_() {return new Fsd_thm_itm();} Fsd_thm_itm() {}
}
class Fsdb_thm_itm_sorter implements gplx.core.lists.ComparerAble {
@@ -56,5 +64,5 @@ class Fsdb_thm_itm_sorter implements gplx.core.lists.ComparerAble {
comp = Double_.Compare (lhs.Time() , rhs.Time()); if (comp != CompareAble_.Same) return comp; // sort by increasing time
return Int_.Compare (lhs.Page() , rhs.Page()); // sort by increasing page
}
public static final Fsdb_thm_itm_sorter Instance = new Fsdb_thm_itm_sorter(); Fsdb_thm_itm_sorter() {}
public static final Fsdb_thm_itm_sorter Instance = new Fsdb_thm_itm_sorter(); Fsdb_thm_itm_sorter() {}
}

View File

@@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.fsdb.data; import gplx.*; import gplx.fsdb.*;
import gplx.dbs.*; import gplx.fsdb.meta.*; import gplx.xowa.files.*;
public class Fsd_thm_tbl implements Rls_able {
private final String tbl_name; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final String fld_id, fld_owner_id, fld_w, fld_h, fld_time, fld_page, fld_bin_db_id, fld_size, fld_modified, fld_hash;
private final Db_conn conn; private Db_stmt stmt_insert, stmt_select_by_fil_exact, stmt_select_by_fil_near; private int mnt_id; private boolean schema_thm_page;
public final String tbl_name; public final Dbmeta_fld_list flds = new Dbmeta_fld_list();
public final String fld_id, fld_owner_id, fld_w, fld_h, fld_time, fld_page, fld_bin_db_id, fld_size, fld_modified, fld_hash;
public final Db_conn conn; private Db_stmt stmt_insert, stmt_select_by_fil_exact, stmt_select_by_fil_near; private int mnt_id; private boolean schema_thm_page;
public Fsd_thm_tbl(Db_conn conn, boolean schema_is_1, int mnt_id, boolean schema_thm_page) {
this.conn = conn; this.mnt_id = mnt_id; this.schema_thm_page = schema_thm_page;
this.tbl_name = schema_is_1 ? "fsdb_xtn_thm" : "fsdb_thm";
@@ -54,22 +54,25 @@ public class Fsd_thm_tbl implements Rls_able {
}
public void Insert(int id, int thm_owner_id, int width, int height, double thumbtime, int page, int bin_db_id, long size) {
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_insert.Clear()
this.Insert(stmt_insert, id, thm_owner_id, width, height, thumbtime, page, bin_db_id, size, Modified_null_str, Hash_null);
}
public void Insert(Db_stmt stmt, int id, int thm_owner_id, int width, int height, double thumbtime, int page, int bin_db_id, long size, String modified, String hash_md5) {
stmt.Clear()
.Val_int(fld_id, id)
.Val_int(fld_owner_id, thm_owner_id)
.Val_int(fld_w, width)
.Val_int(fld_h, height);
if (schema_thm_page) {
stmt_insert.Val_double (fld_time, Xof_lnki_time.Db_save_double(thumbtime));
stmt_insert.Val_int (fld_page, Xof_lnki_page.Db_save_int(page));
stmt.Val_double (fld_time, Xof_lnki_time.Db_save_double(thumbtime));
stmt.Val_int (fld_page, Xof_lnki_page.Db_save_int(page));
}
else
stmt_insert.Val_int (fld_time, Xof_lnki_time.Db_save_int(thumbtime));
stmt_insert
stmt.Val_int (fld_time, Xof_lnki_time.Db_save_int(thumbtime));
stmt
.Val_int(fld_bin_db_id, bin_db_id)
.Val_long(fld_size, size)
.Val_str(fld_modified, Modified_null_str)
.Val_str(fld_hash, Hash_null)
.Val_str(fld_modified, modified)
.Val_str(fld_hash, hash_md5)
.Exec_insert();
}
public boolean Select_itm_by_w_exact(int dir_id, int fil_id, Fsd_thm_itm thm) {
@@ -92,7 +95,7 @@ public class Fsd_thm_tbl implements Rls_able {
}
public boolean Select_itm_by_w_near(int dir_id, int fil_id, Fsd_thm_itm thm) {
if (stmt_select_by_fil_near == null) stmt_select_by_fil_near = conn.Stmt_select(tbl_name, flds, fld_owner_id);
List_adp list = List_adp_.new_();
List_adp list = List_adp_.New();
Db_rdr rdr = stmt_select_by_fil_near.Clear().Crt_int(fld_owner_id, fil_id).Exec_select__rls_manual();
try {
while (rdr.Move_next()) {
@@ -104,7 +107,7 @@ public class Fsd_thm_tbl implements Rls_able {
}
finally {rdr.Rls();}
}
private boolean Ctor_by_load(Fsd_thm_itm itm, Db_rdr rdr, int dir_id) {
public boolean Ctor_by_load(Fsd_thm_itm itm, Db_rdr rdr, int dir_id) {
int thm_id = rdr.Read_int(fld_id);
int fil_id = rdr.Read_int(fld_owner_id);
int w = rdr.Read_int(fld_w);
@@ -126,7 +129,7 @@ public class Fsd_thm_tbl implements Rls_able {
itm.Ctor(mnt_id, dir_id, fil_id, thm_id, bin_db_id, w, h, time, page, size, modified, hash);
return true;
}
public static final DateAdp Modified_null = null;
public static final DateAdp Modified_null = null;
public static final String Hash_null = "", Modified_null_str = "";
public static boolean Match_nearest(List_adp list, Fsd_thm_itm thm, boolean schema_thm_page) {
int len = list.Count(); if (len == 0) return Bool_.N;

View File

@@ -34,7 +34,7 @@ public class Fsd_thm_tbl_tst {
}
}
class Fsd_thm_tbl_fxt {
private final List_adp list = List_adp_.new_();
private final List_adp list = List_adp_.New();
public void Clear() {list.Clear();}
public Fsd_thm_itm Make(int w) {
double time = gplx.xowa.files.Xof_lnki_time.Null;

View File

@@ -16,12 +16,12 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.fsdb.meta; import gplx.*; import gplx.fsdb.*;
import gplx.core.primitives.*; import gplx.core.caches.*; import gplx.core.ios.*;
import gplx.core.primitives.*; import gplx.core.caches.*; import gplx.core.ios.*; import gplx.core.ios.streams.*;
import gplx.dbs.*; import gplx.dbs.engines.sqlite.*; import gplx.fsdb.data.*;
public class Fsm_atr_fil {
private final Fsm_mnt_itm mnt_itm; private final int mnt_id;
private final Fsm_mnt_itm mnt_itm; private final int mnt_id;
private Fsd_dir_tbl tbl_dir; private Fsd_fil_tbl tbl_fil; private Fsd_thm_tbl tbl_thm;
private final Gfo_cache_mgr_bry dir_cache = new Gfo_cache_mgr_bry(); private Gfo_cache_mgr_bry fil_cache; private Bry_bfr fil_cache_key_bfr;
private final Gfo_cache_mgr_bry dir_cache = new Gfo_cache_mgr_bry(); private Gfo_cache_mgr_bry fil_cache; private Bry_bfr fil_cache_key_bfr;
public Fsm_atr_fil(Fsm_mnt_itm mnt_itm, int id, String url_rel, Db_conn conn, boolean schema_is_1, boolean schema_thm_page) {
this.mnt_itm = mnt_itm; this.mnt_id = mnt_itm.Id();
this.id = id; this.url_rel = url_rel; this.conn = conn;
@@ -29,9 +29,9 @@ public class Fsm_atr_fil {
this.tbl_fil = new Fsd_fil_tbl(conn, schema_is_1, mnt_id);
this.tbl_thm = new Fsd_thm_tbl(conn, schema_is_1, mnt_id, schema_thm_page);
}
public int Id() {return id;} private final int id;
public String Url_rel() {return url_rel;} private final String url_rel;
public Db_conn Conn() {return conn;} private final Db_conn conn;
public int Id() {return id;} private final int id;
public String Url_rel() {return url_rel;} private final String url_rel;
public Db_conn Conn() {return conn;} private final Db_conn conn;
public Fsd_fil_itm Select_fil_or_null(byte[] dir, byte[] fil) {
int dir_id = Get_dir_id_or_neg1(dir);
return dir_id == Int_.Neg1 ? Fsd_fil_itm.Null : tbl_fil.Select_or_null(dir_id, fil);
@@ -61,7 +61,7 @@ public class Fsm_atr_fil {
}
public void Fil_cache_enabled_y_() {
fil_cache = new Gfo_cache_mgr_bry();
fil_cache_key_bfr = Bry_bfr.reset_(255);
fil_cache_key_bfr = Bry_bfr_.Reset(255);
tbl_fil.Select_all(fil_cache_key_bfr, fil_cache);
}
private int Get_dir_id_or_neg1(byte[] dir_bry) {
@@ -70,7 +70,7 @@ public class Fsm_atr_fil {
Fsd_dir_itm itm = tbl_dir.Select_or_null(dir_bry); // try db
if (itm == Fsd_dir_itm.Null) return -1; // not in db
int dir_id = itm.Dir_id();
dir_cache.Add(dir_bry, Int_obj_ref.new_(dir_id)); // add to mem
dir_cache.Add(dir_bry, Int_obj_ref.New(dir_id)); // add to mem
return dir_id;
}
else
@@ -81,7 +81,7 @@ public class Fsm_atr_fil {
if (rv == -1) {
rv = mnt_itm.Next_id();
tbl_dir.Insert(rv, dir_bry, Fsd_dir_itm.Owner_root);
dir_cache.Add(dir_bry, Int_obj_ref.new_(rv));
dir_cache.Add(dir_bry, Int_obj_ref.New(rv));
}
return rv;
}

View File

@@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.fsdb.meta; import gplx.*; import gplx.fsdb.*;
import gplx.dbs.*; import gplx.dbs.qrys.*;
public class Fsm_atr_tbl {
private final String tbl_name; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final String fld_uid, fld_url;
private final Db_conn conn;
public final String tbl_name; public final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_uid, fld_url;
private final Db_conn conn;
public Fsm_atr_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;
String fld_prefix = "";

View File

@@ -16,25 +16,26 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.fsdb.meta; import gplx.*; import gplx.fsdb.*;
import gplx.core.ios.*; import gplx.dbs.*;
import gplx.core.ios.*; import gplx.core.ios.streams.*; import gplx.dbs.*;
import gplx.fsdb.data.*;
public class Fsm_bin_fil {
private final Fsd_bin_tbl tbl;
private final Fsd_bin_tbl tbl;
public Fsm_bin_fil(boolean schema_is_1, int id, Io_url url, String url_rel, Db_conn conn, long bin_len) {
this.id = id; this.url = url; this.url_rel = url_rel; this.conn = conn; this.bin_len = bin_len;
this.tbl = new Fsd_bin_tbl(conn, schema_is_1);
}
public int Id() {return id;} private final int id;
public int Id() {return id;} private final int id;
public Io_url Url() {return url;} private Io_url url;
public String Url_rel() {return url_rel;} private final String url_rel;
public String Url_rel() {return url_rel;} private final String url_rel;
public long Bin_len() {return bin_len;} public void Bin_len_(long v) {bin_len = v;} private long bin_len;
public Db_conn Conn() {return conn;} private final Db_conn conn;
public boolean Select_to_url(int id, Io_url url) {return tbl.Select_to_url(id, url);}
public Db_conn Conn() {return conn;} private final Db_conn conn;
public boolean Select_to_url(int id, Io_url url) {return tbl.Select_to_url(id, url);}
public Io_stream_rdr Select_as_rdr(int id) {return tbl.Select_as_rdr(id);}
public void Insert(int bin_id, byte owner_tid, long rdr_len, gplx.core.ios.Io_stream_rdr rdr) {
public Fsd_bin_itm Select_as_itm(int id) {return tbl.Select_as_itm(id);}
public void Insert(int bin_id, byte owner_tid, long rdr_len, gplx.core.ios.streams.Io_stream_rdr rdr) {
tbl.Insert_rdr(bin_id, owner_tid, rdr_len, rdr);
Bin_len_(bin_len + rdr_len);
}
public static final Fsm_bin_fil[] Ary_empty = new Fsm_bin_fil[0];
public static final Fsm_bin_fil[] Ary_empty = new Fsm_bin_fil[0];
public static final long Bin_len_null = 0;
}

Some files were not shown because too many files have changed in this diff Show More