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

Refactor: Pull more classes into baselib

This commit is contained in:
gnosygnu
2021-12-19 16:19:19 -05:00
parent 48559edffe
commit 0e80d7ef6d
7999 changed files with 1375876 additions and 1365947 deletions

View File

@@ -13,8 +13,10 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.brys; import gplx.*;
import gplx.objects.strings.AsciiByte;
package gplx.core.brys;
import gplx.types.errs.ErrUtl;
import gplx.types.basics.constants.AsciiByte;
import gplx.types.basics.utls.StringUtl;
public class Bit_ {
public static String ToBitStr(int val) {
boolean[] bits = new boolean[8];
@@ -27,13 +29,13 @@ public class Bit_ {
byte[] rv = new byte[8];
for (int i = 0; i < 8; i++)
rv[i] = bits[i] ? AsciiByte.Num1 : AsciiByte.Num0;
return String_.new_a7(rv);
return StringUtl.NewA7(rv);
}
public static int Get_flag(int i) {return Int_flag_bldr_.Base2_ary[i];}
public static int Shift_lhs(int val, int shift) {return val << shift;}
public static int Shift_rhs(int val, int shift) {return val >> shift;}
public static int Shift_lhs_to_int(int[] shift_ary, int... val_ary) {
int val_len = val_ary.length; if (val_len > shift_ary.length) throw Err_.new_wo_type("vals must be less than shifts", "vals", val_len, "shifts", shift_ary.length);
int val_len = val_ary.length; if (val_len > shift_ary.length) throw ErrUtl.NewArgs("vals must be less than shifts", "vals", val_len, "shifts", shift_ary.length);
int rv = 0;
for (int i = 0; i < val_len; ++i) {
int val = val_ary[i];

View File

@@ -13,7 +13,9 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.brys; import gplx.*; import gplx.core.*;
package gplx.core.brys;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.arrays.IntAryUtl;
import org.junit.*;
public class Bit__tst {
@Before public void init() {fxt.Clear();} private Bit__fxt fxt = new Bit__fxt();
@@ -23,44 +25,44 @@ public class Bit__tst {
tst_XtoBitStr( 2, "00000010");
tst_XtoBitStr( 3, "00000011");
tst_XtoBitStr(255, "11111111");
} void tst_XtoBitStr(int val, String expd) {Tfds.Eq(expd, Bit_.ToBitStr(val));}
@Test public void Shift_lhs() {// simple: shift 1 bit
} void tst_XtoBitStr(int val, String expd) {GfoTstr.EqObj(expd, Bit_.ToBitStr(val));}
@Test public void Shift_lhs() {// simple: shift 1 bit
fxt.Test_shift_lhs(1, 1, 2);
fxt.Test_shift_lhs(2, 1, 4);
fxt.Test_shift_lhs(3, 1, 6);
fxt.Test_shift_lhs(4, 1, 8);
}
@Test public void Shift_rhs() {
@Test public void Shift_rhs() {
fxt.Test_shift_rhs(2, 1, 1);
fxt.Test_shift_rhs(4, 1, 2);
fxt.Test_shift_rhs(6, 1, 3);
fxt.Test_shift_rhs(8, 1, 4);
}
@Test public void Shift_lhs_to_int() {
int[] shift_ary = Int_ary_.New(0, 3, 5);
fxt.Test_shift_lhs_to_int(shift_ary, Int_ary_.New(0, 0, 0), 0);
fxt.Test_shift_lhs_to_int(shift_ary, Int_ary_.New(7, 0, 0), 7); // 1st 3 bits
fxt.Test_shift_lhs_to_int(shift_ary, Int_ary_.New(0, 3, 0), 24); // 2nd 2 bits
fxt.Test_shift_lhs_to_int(shift_ary, Int_ary_.New(0, 0, 1), 32); // 3rd 1 bit
fxt.Test_shift_lhs_to_int(shift_ary, Int_ary_.New(7, 3, 1), 63); // many bits
@Test public void Shift_lhs_to_int() {
int[] shift_ary = IntAryUtl.New(0, 3, 5);
fxt.Test_shift_lhs_to_int(shift_ary, IntAryUtl.New(0, 0, 0), 0);
fxt.Test_shift_lhs_to_int(shift_ary, IntAryUtl.New(7, 0, 0), 7); // 1st 3 bits
fxt.Test_shift_lhs_to_int(shift_ary, IntAryUtl.New(0, 3, 0), 24); // 2nd 2 bits
fxt.Test_shift_lhs_to_int(shift_ary, IntAryUtl.New(0, 0, 1), 32); // 3rd 1 bit
fxt.Test_shift_lhs_to_int(shift_ary, IntAryUtl.New(7, 3, 1), 63); // many bits
}
@Test public void Shift_rhs_to_ary() {
int[] shift_ary = Int_ary_.New(0, 3, 5);
fxt.Test_shift_rhs_to_ary(shift_ary, 0, Int_ary_.New(0, 0, 0));
fxt.Test_shift_rhs_to_ary(shift_ary, 7, Int_ary_.New(7, 0, 0)); // 1st 3 bits
fxt.Test_shift_rhs_to_ary(shift_ary, 24, Int_ary_.New(0, 3, 0)); // 2nd 2 bits
fxt.Test_shift_rhs_to_ary(shift_ary, 32, Int_ary_.New(0, 0, 1)); // 3rd 1 bit
fxt.Test_shift_rhs_to_ary(shift_ary, 63, Int_ary_.New(7, 3, 1)); // many bits
@Test public void Shift_rhs_to_ary() {
int[] shift_ary = IntAryUtl.New(0, 3, 5);
fxt.Test_shift_rhs_to_ary(shift_ary, 0, IntAryUtl.New(0, 0, 0));
fxt.Test_shift_rhs_to_ary(shift_ary, 7, IntAryUtl.New(7, 0, 0)); // 1st 3 bits
fxt.Test_shift_rhs_to_ary(shift_ary, 24, IntAryUtl.New(0, 3, 0)); // 2nd 2 bits
fxt.Test_shift_rhs_to_ary(shift_ary, 32, IntAryUtl.New(0, 0, 1)); // 3rd 1 bit
fxt.Test_shift_rhs_to_ary(shift_ary, 63, IntAryUtl.New(7, 3, 1)); // many bits
}
}
class Bit__fxt {
public void Clear() {}
public void Test_shift_lhs(int val, int shift, int expd) {Tfds.Eq(expd, Bit_.Shift_lhs(val, shift));}
public void Test_shift_rhs(int val, int shift, int expd) {Tfds.Eq(expd, Bit_.Shift_rhs(val, shift));}
public void Test_shift_lhs_to_int(int[] shift_ary, int[] val_ary, int expd) {Tfds.Eq(expd, Bit_.Shift_lhs_to_int(shift_ary, val_ary));}
public void Test_shift_lhs(int val, int shift, int expd) {GfoTstr.EqObj(expd, Bit_.Shift_lhs(val, shift));}
public void Test_shift_rhs(int val, int shift, int expd) {GfoTstr.EqObj(expd, Bit_.Shift_rhs(val, shift));}
public void Test_shift_lhs_to_int(int[] shift_ary, int[] val_ary, int expd) {GfoTstr.EqObj(expd, Bit_.Shift_lhs_to_int(shift_ary, val_ary));}
public void Test_shift_rhs_to_ary(int[] shift_ary, int val, int[] expd_ary) {
int[] actl_ary = Int_ary_.New(0, 0, 0);
int[] actl_ary = IntAryUtl.New(0, 0, 0);
Bit_.Shift_rhs_to_ary(actl_ary, shift_ary, val);
Tfds.Eq_ary(expd_ary, actl_ary);
GfoTstr.EqAry(expd_ary, actl_ary);
}
}

View File

@@ -1,19 +1,20 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.brys; import gplx.*; import gplx.core.*;
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.brys;
import gplx.types.basics.utls.ByteUtl;
import gplx.xowa.htmls.core.hzips.*;
public class Bit_heap_rdr {
private final byte[] hzip_int_bry = new byte[5];
@@ -65,7 +66,7 @@ public class Bit_heap_rdr {
hzip_int_bry[0] = b0;
for (int i = 1; i < full_len; ++i)
hzip_int_bry[i] = Get_byte(8);
return Xoh_hzip_int.To_int_by_bry(hzip_int_bry, bgn_idx, full_len, Byte_.Zero, 256);
return Xoh_hzip_int.To_int_by_bry(hzip_int_bry, bgn_idx, full_len, ByteUtl.Zero, 256);
}
private byte Get_byte_private(int bits, int chk_bits) {
Get_bgn(chk_bits);

View File

@@ -14,13 +14,13 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.brys;
import gplx.Bry_;
import gplx.Tfds;
import gplx.objects.primitives.BoolUtl;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.BryUtl;
import gplx.types.basics.utls.BoolUtl;
import org.junit.Test;
public class Bit_heap_rdr_tst {
private final Bit_heap_rdr_fxt fxt = new Bit_heap_rdr_fxt();
@Test public void Get_bool() {
@Test public void Get_bool() {
fxt.Load(255);
fxt.Test__get_bool(BoolUtl.Y).Test__cur(127, 1, 0);
fxt.Test__get_bool(BoolUtl.Y).Test__cur( 63, 2, 0);
@@ -37,7 +37,7 @@ public class Bit_heap_rdr_tst {
fxt.Test__get_bool(BoolUtl.Y).Test__cur( 1, 2, 0);
fxt.Test__get_bool(BoolUtl.Y).Test__cur( 0, 3, 0);
}
@Test public void Get_byte() {
@Test public void Get_byte() {
fxt.Load(255).Test__get_byte(2, 3).Test__cur(63, 2, 0);
fxt.Load(255, 3);
fxt.Test__get_byte(7, 127);
@@ -46,7 +46,7 @@ public class Bit_heap_rdr_tst {
fxt.Test__get_bool(false);
fxt.Test__get_byte(3, 5);
}
@Test public void Get_int_hzip() {
@Test public void Get_int_hzip() {
fxt.Load(100).Test__get_int_hzip(1, 100).Test__cur(0, 0, 1);
fxt.Load(253, 1, 44).Test__get_int_hzip(1, 300).Test__cur(0, 0, 3);
fxt.Load(0, 100).Test__get_int_hzip(2, 100).Test__cur(0, 0, 2);
@@ -56,26 +56,26 @@ public class Bit_heap_rdr_tst {
class Bit_heap_rdr_fxt {
private final Bit_heap_rdr heap = new Bit_heap_rdr();
public Bit_heap_rdr_fxt Load(int... src) {
byte[] bry = Bry_.New_by_ints(src);
byte[] bry = BryUtl.NewByInts(src);
heap.Load(bry, 0, bry.length);
return this;
}
public Bit_heap_rdr_fxt Test__get_bool(boolean expd) {
Tfds.Eq_bool(expd, heap.Get_bool());
GfoTstr.Eq(expd, heap.Get_bool());
return this;
}
public Bit_heap_rdr_fxt Test__get_byte(int bits, int expd) {
Tfds.Eq_byte((byte)expd, heap.Get_byte(bits));
GfoTstr.EqByte((byte)expd, heap.Get_byte(bits));
return this;
}
public Bit_heap_rdr_fxt Test__get_int_hzip(int reqd, int expd) {
Tfds.Eq_int(expd, heap.Get_int_hzip(reqd));
GfoTstr.Eq(expd, heap.Get_int_hzip(reqd));
return this;
}
public Bit_heap_rdr_fxt Test__cur(int cur_val, int cur_bits, int cur_pos) {
Tfds.Eq_int(cur_val, heap.Cur_val(), "val");
Tfds.Eq_int(cur_bits, heap.Cur_bits(), "bits");
Tfds.Eq_int(cur_pos, heap.Cur_pos(), "pos");
GfoTstr.Eq(cur_val, heap.Cur_val(), "val");
GfoTstr.Eq(cur_bits, heap.Cur_bits(), "bits");
GfoTstr.Eq(cur_pos, heap.Cur_pos(), "pos");
return this;
}
}

View File

@@ -13,19 +13,20 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.brys; import gplx.*; import gplx.core.*;
package gplx.core.brys;
import gplx.types.custom.brys.wtrs.BryWtr;
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 BryWtr hzip_int_bfr = BryWtr.NewAndReset(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 BryWtr Heap() {return heap;} private final BryWtr heap = BryWtr.New();
public void Clear() {heap.Clear(); cur = 0; cur_bits = 0;}
public void Add_bool(boolean v) {
if (v)
cur += Pow_ary[cur_bits];
if (cur_bits == 7) {
heap.Add_byte((byte)cur);
heap.AddByte((byte)cur);
cur = 0;
cur_bits = 0;
}
@@ -35,9 +36,9 @@ public class Bit_heap_wtr {
public void Add_byte(byte val_byte) {
int val_int = val_byte & 0xFF; // PATCH.JAVA:need to convert to unsigned byte
if (cur_bits == 0)
heap.Add_byte(val_byte);
heap.AddByte(val_byte);
else {
heap.Add_byte((byte)(cur + (val_int << cur_bits)));
heap.AddByte((byte)(cur + (val_int << cur_bits)));
this.cur = val_int >> cur_bits;
}
}
@@ -49,7 +50,7 @@ public class Bit_heap_wtr {
this.cur = new_val;
}
else {
heap.Add_byte((byte)new_val);
heap.AddByte((byte)new_val);
this.cur = val >> (8 - cur_bits);
this.cur_bits = total_bits - 8;
}
@@ -57,13 +58,13 @@ public class Bit_heap_wtr {
public void Add_int_hzip(int reqd_len, int val) {
hzip_int.Encode(reqd_len, hzip_int_bfr, val);
int len = hzip_int_bfr.Len();
byte[] hzip_bry = hzip_int_bfr.Bfr();
byte[] hzip_bry = hzip_int_bfr.Bry();
for (int i = 0; i < len; ++i) {
byte b = hzip_bry[i];
Add_byte(8, b & 0xFF); // PATCH.JAVA:need to convert to unsigned byte
}
hzip_int_bfr.Clear();
}
public void Save(Bry_bfr bfr) {}
public void Save(BryWtr bfr) {}
public static final int[] Pow_ary = new int[] {1, 2, 4, 8, 16, 32, 64, 128, 256};
}

View File

@@ -14,35 +14,35 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.brys;
import gplx.Bry_;
import gplx.Tfds;
import gplx.objects.primitives.BoolUtl;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.BryUtl;
import gplx.types.basics.utls.BoolUtl;
import org.junit.Test;
public class Bit_heap_wtr_tst {
private final Bit_heap_wtr_fxt fxt = new Bit_heap_wtr_fxt();
@Test public void Add_bool() {
@Test public void Add_bool() {
fxt.Clear().Add_bool(BoolUtl.Y).Test__vals(1, 1);
fxt.Clear().Add_bool(BoolUtl.N).Test__vals(1, 0);
fxt.Clear().Add_bool(BoolUtl.Y, BoolUtl.Y, BoolUtl.Y, BoolUtl.Y).Test__vals(4, 15);
fxt.Clear().Add_bool(BoolUtl.Y, BoolUtl.N, BoolUtl.N, BoolUtl.Y).Test__vals(4, 9);
fxt.Clear().Add_bool(8, BoolUtl.Y).Test__vals(0, 0, 255);
}
@Test public void Add_byte() {
@Test public void Add_byte() {
fxt.Clear().Add_byte(255).Test__vals(0, 0, 255);
}
@Test public void Add_bool_byte() {
@Test public void Add_bool_byte() {
fxt.Clear().Add_bool(BoolUtl.N).Add_byte(255).Test__vals(1, 127, 254);
fxt.Clear().Add_bool(BoolUtl.Y).Add_byte(255).Test__vals(1, 127, 255);
fxt.Clear().Add_bool(BoolUtl.Y, BoolUtl.Y, BoolUtl.Y, BoolUtl.Y).Add_byte(255).Test__vals(4, 15, 255);
}
@Test public void Add_byte_digits() {
@Test public void Add_byte_digits() {
fxt.Clear().Add_byte(4, 15).Test__vals(4, 15);
fxt.Clear().Add_byte(7, 127).Add_byte(2, 3).Test__vals(1, 1, 255);
fxt.Clear().Add_byte(3, 7).Add_byte(3, 7).Test__vals(6, 63);
fxt.Clear().Add_byte(6, 63).Add_byte(3, 7).Test__vals(1, 1, 255);
fxt.Clear().Add_byte(3, 6).Add_byte(3, 6).Test__vals(6, 54);
}
@Test public void Add_int_hzip() {
@Test public void Add_int_hzip() {
fxt.Clear().Add_int_hzip(1, 100).Test__vals(0, 0, 100);
fxt.Clear().Add_int_hzip(1, 300).Test__vals(0, 0, 253, 1, 44);
fxt.Clear().Add_int_hzip(2, 100).Test__vals(0, 0, 0, 100);
@@ -80,8 +80,8 @@ class Bit_heap_wtr_fxt {
return this;
}
public void Test__vals(int expd_cur_bits, int expd_cur, int... expd_ary) {
Tfds.Eq_int (expd_cur_bits , heap.Cur_bits() , "cur_bits");
Tfds.Eq_int (expd_cur , heap.Cur() , "cur");
Tfds.Eq_ary (Bry_.New_by_ints(expd_ary) , heap.Heap().To_bry() , "heap");
GfoTstr.Eq(expd_cur_bits , heap.Cur_bits() , "cur_bits");
GfoTstr.Eq(expd_cur , heap.Cur() , "cur");
GfoTstr.EqAry(BryUtl.NewByInts(expd_ary) , heap.Heap().ToBry() , "heap");
}
}

View File

@@ -14,7 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.brys;
import gplx.objects.strings.AsciiByte;
import gplx.types.basics.constants.AsciiByte;
public class Bry_bldr {
public byte[] Val() {return val;} private byte[] val;
public Bry_bldr New_256() {return New(256);}

View File

@@ -13,12 +13,13 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.brys; import gplx.*;
import gplx.objects.lists.ComparerAble;
package gplx.core.brys;
import gplx.types.basics.utls.BryUtl;
import gplx.types.commons.lists.ComparerAble;
public class Bry_comparer implements ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
byte[] lhs = (byte[])lhsObj, rhs = (byte[])rhsObj;
return Bry_.Compare(lhs, 0, lhs.length, rhs, 0, rhs.length);
return BryUtl.Compare(lhs, 0, lhs.length, rhs, 0, rhs.length);
}
public static final Bry_comparer Instance = new Bry_comparer(); Bry_comparer() {} // TS.static
}

View File

@@ -13,9 +13,13 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.brys; import gplx.*;
import gplx.objects.lists.CompareAbleUtl;
import gplx.objects.strings.AsciiByte;
package gplx.core.brys;
import gplx.types.basics.utls.BryLni;
import gplx.types.basics.utls.BryUtl;
import gplx.types.custom.brys.BryFind;
import gplx.types.commons.lists.CompareAbleUtl;
import gplx.types.basics.utls.IntUtl;
import gplx.types.basics.constants.AsciiByte;
public class Bry_diff_ {
public static byte[][] Diff_1st_line(byte[] lhs, byte[] rhs) {return Diff_1st(lhs, 0, lhs.length, rhs, 0, rhs.length, AsciiByte.NlBry, AsciiByte.AngleBgnBry, 255);}
public static byte[][] Diff_1st(byte[] lhs, int lhs_bgn, int lhs_end, byte[] rhs, int rhs_bgn, int rhs_end, byte[] stop, byte[] show, int diff_max) {
@@ -29,7 +33,7 @@ public class Bry_diff_ {
if (lhs_byte != rhs_byte) {lhs_idx = rhs_idx = i; break;} // diff; stop iterating
}
if (lhs_idx == -1 && rhs_idx == -1) {
switch (Int_.Compare(lhs_len, rhs_len)) {
switch (IntUtl.Compare(lhs_len, rhs_len)) {
case CompareAbleUtl.Same: return null;
case CompareAbleUtl.Less: lhs_idx = rhs_idx = lhs_len; break;
case CompareAbleUtl.More: lhs_idx = rhs_idx = rhs_len; break;
@@ -41,12 +45,12 @@ public class Bry_diff_ {
}
private static byte[] Get_1st(byte[] stop, byte[] show, byte[] src, int bgn, int end, int diff_max) {
if (bgn == end) return Bry__eos;
int prv_show = Bry_find_.Find_bwd(src, show, bgn , 0); if (prv_show == Bry_find_.Not_found) prv_show = 0;
int prv_stop = Bry_find_.Find_bwd(src, stop, bgn , 0); prv_stop = (prv_stop == Bry_find_.Not_found) ? 0 : prv_stop + 1;
int prv_show = BryFind.FindBwd(src, show, bgn , 0); if (prv_show == BryFind.NotFound) prv_show = 0;
int prv_stop = BryFind.FindBwd(src, stop, bgn , 0); prv_stop = (prv_stop == BryFind.NotFound) ? 0 : prv_stop + 1;
int prv = prv_show > prv_stop ? prv_show : prv_stop;
int nxt = Bry_find_.Find_fwd(src, stop, bgn , end); if (nxt == Bry_find_.Not_found) nxt = end;
int nxt = BryFind.FindFwd(src, stop, bgn , end); if (nxt == BryFind.NotFound) nxt = end;
if (nxt - prv > 255) nxt = prv + diff_max;
return Bry_.Mid(src, prv, nxt);
return BryLni.Mid(src, prv, nxt);
}
private static final byte[] Bry__eos = Bry_.new_a7("<<EOS>>");
private static final byte[] Bry__eos = BryUtl.NewA7("<<EOS>>");
}

View File

@@ -13,31 +13,33 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.brys; import gplx.*;
import gplx.objects.strings.AsciiByte;
package gplx.core.brys;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.BryUtl;
import gplx.types.basics.constants.AsciiByte;
import org.junit.*;
public class Bry_diff_tst {
@Before public void init() {} private final Bry_diff_fxt fxt = new Bry_diff_fxt();
@Test public void Diff_1st() {
@Test public void Diff_1st() {
fxt.Test__diff_1st("a|b|c" , "a|b|c" , null , null);
fxt.Test__diff_1st("a|b|c" , "a|b1|c" , "b" , "b1");
fxt.Test__diff_1st("a|b|" , "a|b|c" , "<<EOS>>" , "c");
fxt.Test__diff_1st("a|b|c" , "a|b|" , "c" , "<<EOS>>");
}
@Test public void Diff_1st_show() {
@Test public void Diff_1st_show() {
fxt.Test__diff_1st("a|b<c>d|e" , "a|b<c>e|e" , "<c>d", "<c>e");
}
}
class Bry_diff_fxt {
public void Test__diff_1st(String lhs, String rhs, String expd_lhs, String expd_rhs) {
byte[] lhs_src = Bry_.new_u8(lhs);
byte[] rhs_src = Bry_.new_u8(rhs);
byte[] lhs_src = BryUtl.NewU8(lhs);
byte[] rhs_src = BryUtl.NewU8(rhs);
byte[][] actl = Bry_diff_.Diff_1st(lhs_src, 0, lhs_src.length, rhs_src, 0, rhs_src.length, AsciiByte.PipeBry, AsciiByte.AngleBgnBry, 255);
if (expd_lhs == null && expd_rhs == null)
Tfds.Eq_true(actl == null, "actl not null");
GfoTstr.EqBoolY(actl == null, "actl not null");
else {
Tfds.Eq_bry(Bry_.new_u8(expd_lhs), actl[0]);
Tfds.Eq_bry(Bry_.new_u8(expd_rhs), actl[1]);
GfoTstr.Eq(BryUtl.NewU8(expd_lhs), actl[0]);
GfoTstr.Eq(BryUtl.NewU8(expd_rhs), actl[1]);
}
}
}

View File

@@ -1,19 +1,20 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.brys; import gplx.*; import gplx.core.*;
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.brys;
import gplx.types.custom.brys.wtrs.BryWtr;
public class Bry_tmp {
public byte[] src;
public int src_bgn;
@@ -26,13 +27,13 @@ public class Bry_tmp {
this.src_end = src_end;
return this;
}
public void Set_by_bfr(Bry_bfr bfr) {
public void Set_by_bfr(BryWtr bfr) {
dirty = true;
src = bfr.To_bry_and_clear();
src = bfr.ToBryAndClear();
src_bgn = 0;
src_end = src.length;
}
public void Add_to_bfr(Bry_bfr bfr) {
bfr.Add_mid(src, src_bgn, src_end);
public void Add_to_bfr(BryWtr bfr) {
bfr.AddMid(src, src_bgn, src_end);
}
}

View File

@@ -1,19 +1,21 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.brys; import gplx.*; import gplx.core.*;
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.brys;
import gplx.types.commons.GfoDate;
import gplx.types.commons.GfoDateUtl;
public class Int_flag_bldr_ {
public static int[] Bld_pow_ary(int... ary) {
int len = ary.length;
@@ -72,10 +74,10 @@ public class Int_flag_bldr_ {
Int_flag_bldr_.To_int_ary(rv, Pow_ary_date_short, v);
rv[0] += 1900;
}
public static DateAdp To_date_short(int v) {
public static GfoDate To_date_short(int v) {
int[] rv = new int[Pow_ary_date_short.length];
To_date_short_int_ary(rv, v);
return DateAdp_.seg_(rv);
return GfoDateUtl.NewBySegs(rv);
}
private static final int[] Pow_ary_date_short = new int[] {1048576, 65536, 2048, 64, 1}; // yndhm -> 12,4,5,5,6
public static final int[] Base2_ary = new int[]

View File

@@ -13,7 +13,10 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.brys; import gplx.*; import gplx.core.*;
package gplx.core.brys;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.commons.GfoDate;
import gplx.types.commons.GfoDateUtl;
import org.junit.*;
public class Int_flag_bldr__tst {
private final Int_flag_bldr__fxt fxt = new Int_flag_bldr__fxt();
@@ -52,21 +55,21 @@ public class Int_flag_bldr__tst {
}
class Int_flag_bldr__fxt {
public int[] Make__ary(int... v) {return v;}
public void Test__bld_pow_ary(int[] seg_ary, int[] expd) {Tfds.Eq_ary_str(expd, Int_flag_bldr_.Bld_pow_ary(seg_ary));}
public void Test__bld_pow_ary(int[] seg_ary, int[] expd) {GfoTstr.EqAry(expd, Int_flag_bldr_.Bld_pow_ary(seg_ary));}
public void Test__to_int(int[] seg_ary, int[] val_ary, int expd) {
int[] pow_ary = Int_flag_bldr_.Bld_pow_ary(seg_ary);
Tfds.Eq(expd, Int_flag_bldr_.To_int(pow_ary, val_ary));
GfoTstr.EqObj(expd, Int_flag_bldr_.To_int(pow_ary, val_ary));
int[] actl_val_ary = Int_flag_bldr_.To_int_ary(pow_ary, expd);
Tfds.Eq_ary(val_ary, actl_val_ary);
GfoTstr.EqAry(val_ary, actl_val_ary);
}
public void Test__to_int_ary(int[] seg_ary, int val, int[] expd) {
int[] pow_ary = Int_flag_bldr_.Bld_pow_ary(seg_ary);
Tfds.Eq_ary_str(expd, Int_flag_bldr_.To_int_ary(pow_ary, val));
GfoTstr.EqAry(expd, Int_flag_bldr_.To_int_ary(pow_ary, val));
}
public void Test__to_int_date_short(String date_str, int expd) {
DateAdp date = DateAdp_.parse_fmt(date_str, "yyyyMMdd HHmm");
int date_int = Int_flag_bldr_.To_int_date_short(date.XtoSegAry());
Tfds.Eq(expd, date_int);
Tfds.Eq(date_str, Int_flag_bldr_.To_date_short(date_int).XtoStr_fmt("yyyyMMdd HHmm"));
GfoDate date = GfoDateUtl.ParseFmt(date_str, "yyyyMMdd HHmm");
int date_int = Int_flag_bldr_.To_int_date_short(date.ToSegAry());
GfoTstr.EqObj(expd, date_int);
GfoTstr.EqObj(date_str, Int_flag_bldr_.To_date_short(date_int).ToStrFmt("yyyyMMdd HHmm"));
}
}

View File

@@ -13,8 +13,13 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.brys.evals; import gplx.*;
import gplx.objects.strings.AsciiByte;
package gplx.core.brys.evals;
import gplx.types.basics.lists.Hash_adp_bry;
import gplx.types.basics.utls.BryLni;
import gplx.types.basics.utls.BryUtl;
import gplx.types.custom.brys.wtrs.BryWtr;
import gplx.types.errs.ErrUtl;
import gplx.types.basics.constants.AsciiByte;
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;
@@ -26,7 +31,7 @@ public class Bry_eval_mgr {
}
public Bry_eval_mgr Add_many(Bry_eval_wkr... ary) {
for (Bry_eval_wkr itm : ary)
hash.Add(Bry_.new_u8(itm.Key()), itm);
hash.Add(BryUtl.NewU8(itm.Key()), itm);
return this;
}
public byte[] Eval(byte[] src) {
@@ -34,7 +39,7 @@ public class Bry_eval_mgr {
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;
BryWtr cur_bfr = null;
int cur_pos = src_bgn;
while (true) {
if (cur_pos == src_end) break;
@@ -42,11 +47,11 @@ public class Bry_eval_mgr {
// 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);}
if (cur_bfr == null) {cur_bfr = BryWtr.New(); cur_bfr.AddMid(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);
if (nxt_pos == src_end) throw ErrUtl.NewArgs("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 "}"
@@ -55,20 +60,20 @@ public class Bry_eval_mgr {
continue;
}
else if (nxt_byte == sym_escape) {
cur_bfr.Add_byte(nxt_byte);
cur_bfr.AddByte(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);
? new Bry_eval_rslt(BryLni.Mid(src, src_bgn, cur_pos), cur_pos + 1)
: new Bry_eval_rslt(cur_bfr.ToBryAndClear(), cur_pos + 1);
}
if (cur_bfr != null) cur_bfr.Add_byte(cur_byte);
if (cur_bfr != null) cur_bfr.AddByte(cur_byte);
++cur_pos;
}
return cur_bfr == null ? null : new Bry_eval_rslt(cur_bfr.To_bry_and_clear(), src_end);
return cur_bfr == null ? null : new Bry_eval_rslt(cur_bfr.ToBryAndClear(), src_end);
}
private byte[] Eval_grp(byte[] src) {
// search for "|" or "}"
@@ -86,15 +91,15 @@ public class Bry_eval_mgr {
// 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 (wkr == null) throw ErrUtl.NewArgs("bry_eval:key not found", "src", src);
BryWtr bfr = BryWtr.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();
return bfr.ToBryAndClear();
}
public static Bry_eval_mgr Dflt() {return new Bry_eval_mgr(AsciiByte.Tilde, AsciiByte.Pipe, AsciiByte.CurlyBgn, AsciiByte.CurlyEnd);}
}

View File

@@ -13,9 +13,13 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.brys.evals; import gplx.*;
import gplx.objects.strings.AsciiByte;
import org.junit.*; import gplx.core.tests.*;
package gplx.core.brys.evals;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.BryUtl;
import gplx.types.custom.brys.wtrs.BryWtr;
import gplx.types.custom.brys.BrySplit;
import gplx.types.basics.constants.AsciiByte;
import org.junit.*;
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");}
@@ -30,20 +34,20 @@ public class Bry_eval_mgr__tst {
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)));
GfoTstr.Eq(BryUtl.NewU8(expd), mgr.Eval(BryUtl.NewU8(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");
public void Resolve(BryWtr rv, byte[] src, int src_bgn, int src_end) {
rv.AddStrA7("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, AsciiByte.Pipe, false);
public void Resolve(BryWtr rv, byte[] src, int src_bgn, int src_end) {
byte[][] ary = BrySplit.Split(src, src_bgn, src_end, AsciiByte.Pipe, false);
for (byte[] itm : ary) {
rv.Add(itm);
}

View File

@@ -13,8 +13,9 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
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);
}
package gplx.core.brys.evals;
import gplx.types.custom.brys.wtrs.BryWtr;
public interface Bry_eval_wkr {
String Key();
void Resolve(BryWtr rv, byte[] src, int args_bgn, int args_end);
}

View File

@@ -13,14 +13,16 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.btries; import gplx.*; import gplx.core.*;
package gplx.core.btries;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.BryUtl;
import org.junit.*;
import gplx.xowa.langs.cases.*;
public class Btrie_u8_mgr_tst {
@Before public void init() {fxt.Clear();} private Btrie_u8_mgr_fxt fxt = new Btrie_u8_mgr_fxt();
@Test public void Ascii() {
fxt.Init_add(Bry_.new_a7("a") , "1");
fxt.Init_add(Bry_.new_a7("abc") , "123");
fxt.Init_add(BryUtl.NewA7("a") , "1");
fxt.Init_add(BryUtl.NewA7("abc") , "123");
fxt.Test_match("a" , "1"); // single.exact
fxt.Test_match("abc" , "123"); // many.exact
fxt.Test_match("ab" , "1"); // single.more
@@ -29,7 +31,7 @@ public class Btrie_u8_mgr_tst {
fxt.Test_match("aBC" , "123"); // upper
}
@Test public void Uft8() {
fxt.Init_add(Bry_.new_u8("aéi") , "1");
fxt.Init_add(BryUtl.NewU8("aéi") , "1");
fxt.Test_match("aéi" , "1"); // exact
fxt.Test_match("aÉi" , "1"); // upper.utf8
fxt.Test_match("AÉI" , "1"); // upper.all
@@ -37,38 +39,38 @@ public class Btrie_u8_mgr_tst {
fxt.Test_match("aei" , null); // no_match
}
@Test public void Uft8_match_pos() {
fxt.Init_add(Bry_.new_u8("aéi") , "1");
fxt.Init_add(BryUtl.NewU8("aéi") , "1");
fxt.Test_match_pos("aAÉI" , 1, "1"); // match at 1
fxt.Test_match_pos("aAÉI" , 0, null); // no_match at 0
}
@Test public void Uft8_asymmetric() {
fxt.Init_add(Bry_.new_u8("İ") , "1");
fxt.Init_add(BryUtl.NewU8("İ") , "1");
fxt.Test_match("İ" , "1"); // exact=y; İ = Bry_.New_by_ints(196,176)
fxt.Test_match("i" , "1"); // lower=y; i = Bry_.New_by_ints(105)
fxt.Test_match("I" , null); // upper=n; I = Bry_.New_by_ints( 73); see Btrie_u8_itm and rv.asymmetric_bry
fxt.Clear();
fxt.Init_add(Bry_.new_u8("i") , "1");
fxt.Init_add(BryUtl.NewU8("i") , "1");
fxt.Test_match("i" , "1"); // exact=y
fxt.Test_match("I" , "1"); // upper=y
fxt.Test_match("İ" , "1"); // utf_8=y; note that "i" matches "İ" b/c hash is case-insensitive and "İ" lower-cases to "i"; DATE:2015-09-07
}
@Test public void Utf8_asymmetric_multiple() { // PURPOSE: problems in original implementation of Hash_adp_bry and uneven source / target counts;
fxt.Init_add(Bry_.new_u8("İİ") , "1");
fxt.Init_add(BryUtl.NewU8("İİ") , "1");
fxt.Test_match("İİ" , "1"); // exact
fxt.Test_match("ii" , "1"); // lower
fxt.Test_match("İi" , "1"); // mixed
fxt.Test_match("" , "1"); // mixed
}
@Test public void Utf8_asymmetric_upper() { // PURPOSE: "İ" and "I" should co-exist; see Btrie_u8_itm and called_by_match
fxt.Init_add(Bry_.new_u8("İ") , "1");
fxt.Init_add(Bry_.new_u8("I") , "1");
fxt.Init_add(BryUtl.NewU8("İ") , "1");
fxt.Init_add(BryUtl.NewU8("I") , "1");
fxt.Test_match("İ" , "1"); // exact
fxt.Test_match("I" , "1"); // exact
fxt.Test_match("i" , "1"); // lower
}
@Test public void Utf8_asymmetric_symbols() { // PURPOSE: test Hash_adp_bry and multi-byte syms (chars that will never be cased)
fxt.Init_add(Bry_.new_u8("a_b") , "1");
fxt.Init_add(BryUtl.NewU8("a_b") , "1");
fxt.Test_match("a_b" , "1"); // exact: len=3
fxt.Test_match("a†b" , null); // diff : len=3
fxt.Test_match("a±b" , null); // diff : len=2
@@ -80,15 +82,15 @@ class Btrie_u8_mgr_fxt {
public void Clear() {
trie = Btrie_u8_mgr.new_(Xol_case_mgr_.U8());
}
public void Init_add(byte[] key, Object val) {trie.Add_obj(key, val);}
public void Init_add(byte[] key, Object val) {trie.AddObj(key, val);}
public void Test_match_pos(String src_str, int bgn_pos, String expd) {
byte[] src = Bry_.new_u8(src_str);
byte[] src = BryUtl.NewU8(src_str);
Object actl = trie.Match_bgn_w_byte(src[bgn_pos], src, bgn_pos, src.length);
Tfds.Eq(expd, actl, src_str);
GfoTstr.EqObj(expd, actl, src_str);
}
public void Test_match(String src_str, String expd) {
byte[] src = Bry_.new_u8(src_str);
byte[] src = BryUtl.NewU8(src_str);
Object actl = trie.Match_bgn_w_byte(src[0], src, 0, src.length);
Tfds.Eq(expd, actl, src_str);
GfoTstr.EqObj(expd, actl, src_str);
}
}

View File

@@ -13,8 +13,10 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.caches; import gplx.*;
import gplx.objects.lists.CompareAble;
package gplx.core.caches;
import gplx.frameworks.objects.Rls_able;
import gplx.types.commons.lists.CompareAble;
import gplx.types.basics.utls.LongUtl;
class Gfo_cache_data implements CompareAble, Rls_able {
private int count = 0;
public Gfo_cache_data(byte[] key, Rls_able val, int size) {
@@ -36,7 +38,7 @@ class Gfo_cache_data implements CompareAble, Rls_able {
}
public int compareTo(Object obj) {
Gfo_cache_data comp = (Gfo_cache_data)obj;
return -Long_.Compare(count, comp.count); // "-" to sort most-recent first
return -LongUtl.Compare(count, comp.count); // "-" to sort most-recent first
}
public void Rls() {
val.Rls();

View File

@@ -13,7 +13,12 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.caches; import gplx.*;
package gplx.core.caches;
import gplx.frameworks.objects.Rls_able;
import gplx.types.basics.lists.List_adp;
import gplx.types.basics.lists.List_adp_;
import gplx.types.basics.lists.Ordered_hash;
import gplx.types.basics.lists.Ordered_hash_;
public class Gfo_cache_mgr {
private final Ordered_hash hash = Ordered_hash_.New_bry();
private final List_adp tmp_delete = List_adp_.New();
@@ -57,7 +62,7 @@ public class Gfo_cache_mgr {
int len = hash.Len();
int list_size = 0;
for (int i = 0; i < len; ++i) {
Gfo_cache_data itm = (Gfo_cache_data)hash.Get_at(i);
Gfo_cache_data itm = (Gfo_cache_data)hash.GetAt(i);
int itm_size = itm.Size();
if (itm_size == 0)
itm_size = 1; // if itm_size remains 0, it will never be added to tmp_delete cache; ISSUE#:561; DATE:2019-09-04
@@ -70,14 +75,14 @@ public class Gfo_cache_mgr {
this.cur_size = list_size;
len = tmp_delete.Len();
for (int i = 0; i < len; ++i) {
Gfo_cache_data itm = (Gfo_cache_data)tmp_delete.Get_at(i);
Gfo_cache_data itm = (Gfo_cache_data)tmp_delete.GetAt(i);
hash.Del(itm.Key());
}
tmp_delete.Clear();
}
public int Test__len() {return hash.Len();}
public Object Test__get_at(int i) {
Gfo_cache_data rv = (Gfo_cache_data)hash.Get_at(i);
Gfo_cache_data rv = (Gfo_cache_data)hash.GetAt(i);
return rv.Val();
}
// NOTE: not called yet

View File

@@ -13,7 +13,11 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.caches; import gplx.*;
package gplx.core.caches;
import gplx.types.basics.lists.List_adp;
import gplx.types.basics.lists.List_adp_;
import gplx.types.basics.lists.Ordered_hash;
import gplx.types.basics.lists.Ordered_hash_;
public class Gfo_cache_mgr_base {
private final Ordered_hash hash = Ordered_hash_.New_bry();
public int Compress_max() {return compress_max;} public void Compress_max_(int v) {compress_max = v;} private int compress_max = 16;
@@ -31,15 +35,15 @@ public class Gfo_cache_mgr_base {
hash.Del(key);
}
public void Compress() {
hash.Sort_by(Gfo_cache_itm_comparer.Touched_asc);
hash.SortBy(Gfo_cache_itm_comparer.Touched_asc);
int del_len = hash.Len() - compress_to;
List_adp del_list = List_adp_.New();
for (int i = 0; i < del_len; i++) {
Gfo_cache_itm_bry itm = (Gfo_cache_itm_bry)hash.Get_at(i);
Gfo_cache_itm_bry itm = (Gfo_cache_itm_bry)hash.GetAt(i);
del_list.Add(itm);
}
for (int i = 0; i < del_len; i++) {
Gfo_cache_itm_bry itm = (Gfo_cache_itm_bry)del_list.Get_at(i);
Gfo_cache_itm_bry itm = (Gfo_cache_itm_bry)del_list.GetAt(i);
hash.Del(itm.Key());
}
}

View File

@@ -13,9 +13,14 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.caches; import gplx.*;
import gplx.core.primitives.*; import gplx.core.envs.*;
import gplx.objects.lists.ComparerAble;
package gplx.core.caches;
import gplx.core.envs.*;
import gplx.libs.files.Io_mgr;
import gplx.types.commons.lists.ComparerAble;
import gplx.types.basics.utls.IntUtl;
import gplx.types.basics.utls.LongUtl;
import gplx.libs.files.Io_url;
import gplx.types.basics.wrappers.BoolRef;
public class Gfo_cache_mgr_bry extends Gfo_cache_mgr_base {
public Object Get_or_null(byte[] key) {return Base_get_or_null(key);}
public void Add(byte[] key, Object val) {Base_add(key, val);}
@@ -26,27 +31,27 @@ class Gfo_cache_itm_bry {
public Object Key() {return key;} private Object key;
public Object Val() {return val;} private Object val;
public long Touched() {return touched;} private long touched;
public Gfo_cache_itm_bry Touched_update() {touched = System_.Ticks(); return this;}
public Gfo_cache_itm_bry Touched_update() {touched = SystemUtl.Ticks(); return this;}
}
class Gfo_cache_itm_comparer implements ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
Gfo_cache_itm_bry lhs = (Gfo_cache_itm_bry)lhsObj;
Gfo_cache_itm_bry rhs = (Gfo_cache_itm_bry)rhsObj;
return Long_.Compare(lhs.Touched(), rhs.Touched());
return LongUtl.Compare(lhs.Touched(), rhs.Touched());
}
public static final Gfo_cache_itm_comparer Touched_asc = new Gfo_cache_itm_comparer(); // TS.static
}
class Io_url_exists_mgr {
private gplx.core.caches.Gfo_cache_mgr_bry cache_mgr = new gplx.core.caches.Gfo_cache_mgr_bry();
public Io_url_exists_mgr() {
cache_mgr.Compress_max_(Int_.Max_value);
cache_mgr.Compress_max_(IntUtl.MaxValue);
}
public boolean Has(Io_url url) {
byte[] url_key = url.RawBry();
Object rv_obj = cache_mgr.Get_or_null(url_key);
if (rv_obj != null) return ((Bool_obj_ref)rv_obj).Val(); // cached val exists; use it
if (rv_obj != null) return ((BoolRef)rv_obj).Val(); // cached val exists; use it
boolean exists = Io_mgr.Instance.ExistsFil(url);
cache_mgr.Add(url_key, Bool_obj_ref.new_(exists));
cache_mgr.Add(url_key, BoolRef.New(exists));
return exists;
}
}

View File

@@ -13,8 +13,11 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.caches; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.tests.*; import gplx.core.envs.*;
package gplx.core.caches;
import gplx.frameworks.objects.Rls_able;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.BryUtl;
import org.junit.*;
public class Gfo_cache_mgr_tst {
@Before public void init() {fxt.Clear();} private final Gfo_cache_mgr_fxt fxt = new Gfo_cache_mgr_fxt();
@Test public void Basic() {
@@ -41,7 +44,7 @@ class Gfo_cache_mgr_fxt {
int len = ary.length;
for (int i = 0; i < len; ++i) {
String itm = ary[i];
byte[] key = Bry_.new_u8(itm);
byte[] key = BryUtl.NewU8(itm);
mgr.Add(key, new Gfo_cache_itm_mock(itm), key.length);
}
return this;
@@ -50,17 +53,17 @@ class Gfo_cache_mgr_fxt {
int len = ary.length;
for (int i = 0; i < len; ++i) {
String itm = ary[i];
mgr.Get_by_key(Bry_.new_u8(itm));
mgr.Get_by_key(BryUtl.NewU8(itm));
}
return this;
}
public Gfo_cache_mgr_fxt Test__cur_size(int expd) {Gftest.Eq__int(expd, mgr.Cur_size(), "cur_size"); return this;}
public Gfo_cache_mgr_fxt Test__cur_size(int expd) {GfoTstr.Eq(expd, mgr.Cur_size(), "cur_size"); return this;}
public Gfo_cache_mgr_fxt Test__itms(String... expd) {
int len = mgr.Test__len();
String[] actl = new String[len];
for (int i = 0; i < len; ++i)
actl[i] = ((Gfo_cache_itm_mock)mgr.Test__get_at(i)).Val();
Gftest.Eq__ary(expd, actl, "itms");
GfoTstr.EqLines(expd, actl, "itms");
return this;
}
}

View File

@@ -14,10 +14,10 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.consoles;
import gplx.Int_;
import gplx.Io_url;
import gplx.String_;
import gplx.objects.primitives.BoolUtl;
import gplx.types.basics.utls.IntUtl;
import gplx.types.basics.utls.StringUtl;
import gplx.libs.files.Io_url;
import gplx.types.basics.utls.BoolUtl;
public class Gfo_cmd_arg_itm {
public Gfo_cmd_arg_itm(int tid, boolean reqd, String key, int val_tid) {this.tid = tid; this.reqd = reqd; this.key = key; this.val_tid = val_tid;}
public int Tid() {return tid;} private final int tid;
@@ -48,10 +48,10 @@ public class Gfo_cmd_arg_itm {
}
}
public boolean Val_as_bool() {return BoolUtl.Cast(val);}
public boolean Val_as_bool_or(boolean or) {return val == null ? or : String_.Eq((String)val, "y");}
public boolean Val_as_bool_or(boolean or) {return val == null ? or : StringUtl.Eq((String)val, "y");}
public String Val_as_str_or(String or) {return val == null ? or : (String)val;}
public String Val_as_str() {return (String)val;}
public int Val_as_int_or(int or) {return val == null ? or : Int_.Parse_or((String)val, or);}
public int Val_as_int_or(int or) {return val == null ? or : IntUtl.ParseOr((String)val, or);}
public Io_url Val_as_url__rel_dir_or(Io_url owner_dir, Io_url or) {return Val_as_url__rel_url_or(BoolUtl.Y, owner_dir, or);}
public Io_url Val_as_url__rel_fil_or(Io_url owner_dir, Io_url or) {return Val_as_url__rel_url_or(BoolUtl.N, owner_dir, or);}
public Io_url Val_as_url__rel_url_or(boolean to_dir, Io_url owner_dir, Io_url or) {return Gfo_cmd_arg_itm_.Val_as_url__rel_url_or(Val_as_str(), to_dir, owner_dir, or);}

View File

@@ -14,11 +14,11 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.consoles;
import gplx.Io_url;
import gplx.Io_url_;
import gplx.String_;
import gplx.types.basics.utls.StringUtl;
import gplx.libs.files.Io_url;
import gplx.libs.files.Io_url_;
import gplx.core.envs.Op_sys;
import gplx.objects.primitives.BoolUtl;
import gplx.types.basics.utls.BoolUtl;
public class Gfo_cmd_arg_itm_ {
public static final int Tid_general = 0, Tid_system = 1;
public static final int Val_tid_string = 0, Val_tid_yn = 1, Val_tid_url = 2, Val_tid_list_string = 3;
@@ -30,14 +30,14 @@ public class Gfo_cmd_arg_itm_ {
public static Io_url Val_as_url__rel_url_or(String raw, boolean to_dir, Io_url owner_dir, Io_url or) {
if (raw == null) return or;
byte val_has_dir = Op_sys.Tid_nil; // if raw is to_dir, use it literally (only checking for closing dir_spr); if it's just a name, assume a simple relative path
if (String_.Has(raw, Op_sys.Lnx.Fsys_dir_spr_str()))
if (StringUtl.Has(raw, Op_sys.Lnx.Fsys_dir_spr_str()))
val_has_dir = Op_sys.Tid_lnx;
else if (String_.Has(raw, Op_sys.Wnt.Fsys_dir_spr_str()))
else if (StringUtl.Has(raw, Op_sys.Wnt.Fsys_dir_spr_str()))
val_has_dir = Op_sys.Tid_wnt;
if (val_has_dir != Op_sys.Tid_nil) {
if (to_dir) { // NOTE: need to do extra logic to guarantee trailing "/"; JAVA:7 apparently strips "/to_dir/" to "/to_dir" when passed in as argument; DATE:2013-03-20
String val_dir_spr = val_has_dir == Op_sys.Tid_lnx ? Op_sys.Lnx.Fsys_dir_spr_str() : Op_sys.Wnt.Fsys_dir_spr_str();
if (!String_.Has_at_end(raw, val_dir_spr))
if (!StringUtl.HasAtEnd(raw, val_dir_spr))
raw += val_dir_spr;
return Io_url_.new_dir_(raw);
}

View File

@@ -13,7 +13,12 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.consoles; import gplx.*;
package gplx.core.consoles;
import gplx.types.basics.lists.List_adp;
import gplx.types.basics.lists.List_adp_;
import gplx.types.basics.lists.Ordered_hash;
import gplx.types.basics.lists.Ordered_hash_;
import gplx.types.basics.utls.StringUtl;
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();
@@ -25,7 +30,7 @@ public class Gfo_cmd_arg_mgr {
public void Clear() {
int len = hash.Len();
for (int i = 0; i < len; ++i) {
Gfo_cmd_arg_itm itm = (Gfo_cmd_arg_itm)hash.Get_at(i);
Gfo_cmd_arg_itm itm = (Gfo_cmd_arg_itm)hash.GetAt(i);
itm.Clear();
}
err_list.Clear();
@@ -40,7 +45,7 @@ public class Gfo_cmd_arg_mgr {
Gfo_cmd_arg_itm arg = (Gfo_cmd_arg_itm)hash.GetByOrNull(k);
return arg != null && arg.Val() != null && arg.Val_as_bool();
}
public Gfo_cmd_arg_itm Get_at(int i) {return (Gfo_cmd_arg_itm)hash.Get_at(i);}
public Gfo_cmd_arg_itm Get_at(int i) {return (Gfo_cmd_arg_itm)hash.GetAt(i);}
public Gfo_cmd_arg_itm Get_by(String key) {return (Gfo_cmd_arg_itm)hash.GetByOrNull(key);}
public void Parse(String[] orig_ary) {
this.Clear();
@@ -50,7 +55,7 @@ public class Gfo_cmd_arg_mgr {
while (true) {
boolean done = orig_idx == orig_len;
String itm = done ? "" : orig_ary[orig_idx++];
boolean itm_is_key = String_.Has_at_bgn(itm, Key_prefix); // has "--" -> is key
boolean itm_is_key = StringUtl.HasAtBgn(itm, Key_prefix); // has "--" -> is key
if ( cur_itm != null // pending itm
&& (itm_is_key || done)) { // cur arg is key ("--key2"), or all done
cur_itm.Val_(Gfo_cmd_arg_mgr_.Parse_ary_to_str(this, cur_itm.Val_tid(), tmp_vals.ToStrAryAndClear()));
@@ -58,7 +63,7 @@ public class Gfo_cmd_arg_mgr {
}
if (done) break;
if (itm_is_key) {
String key = String_.Mid(itm, prefix_len);
String key = StringUtl.Mid(itm, prefix_len);
Object o = hash.GetByOrNull(key); if (o == null) {Errs__add(Gfo_cmd_arg_mgr_.Err__key__unknown , key); continue;}
cur_itm = (Gfo_cmd_arg_itm)o; if (cur_itm.Dirty()) {Errs__add(Gfo_cmd_arg_mgr_.Err__key__duplicate , key); continue;}
}
@@ -71,7 +76,7 @@ public class Gfo_cmd_arg_mgr {
// calc .Reqd and .Dflt
int len = hash.Len();
for (int i = 0; i < len; ++i) {
cur_itm = (Gfo_cmd_arg_itm)hash.Get_at(i);
cur_itm = (Gfo_cmd_arg_itm)hash.GetAt(i);
if (!cur_itm.Dirty()) { // arg not passed
if (cur_itm.Reqd()) // arg required but no value passed; add error
Errs__add(Gfo_cmd_arg_mgr_.Err__val__required, cur_itm.Key());
@@ -83,7 +88,7 @@ public class Gfo_cmd_arg_mgr {
public boolean Errs__exist() {return err_list.Len() > 0;}
public void Errs__add(String key, String val) {err_list.Add(key + ": " + val);}
public String[] Errs__to_str_ary() {return err_list.ToStrAry();}
public Gfo_cmd_arg_itm[] To_ary() {return (Gfo_cmd_arg_itm[])hash.To_ary(Gfo_cmd_arg_itm.class);}
public Gfo_cmd_arg_itm[] To_ary() {return (Gfo_cmd_arg_itm[])hash.ToAry(Gfo_cmd_arg_itm.class);}
private void Reg(Gfo_cmd_arg_itm defn) {hash.Add(defn.Key(), defn);}
public static final String Key_prefix = "--"; private static final int prefix_len = 2;
}

View File

@@ -13,8 +13,10 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.consoles; import gplx.*;
import gplx.objects.primitives.BoolUtl;
package gplx.core.consoles;
import gplx.Yn;
import gplx.types.basics.utls.BoolUtl;
import gplx.types.errs.ErrUtl;
class Gfo_cmd_arg_mgr_ {
public static final String
Err__key__unknown = "unknown key"
@@ -35,7 +37,7 @@ class Gfo_cmd_arg_mgr_ {
return null;
}
return itm_as_int == BoolUtl.YInt;
default: throw Err_.new_unhandled(val_tid);
default: throw ErrUtl.NewUnhandled(val_tid);
}
}
}

View File

@@ -13,10 +13,14 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.consoles; import gplx.*; import gplx.core.*;
package gplx.core.consoles;
import gplx.libs.dlgs.Gfo_usr_dlg;
import gplx.types.basics.utls.ObjectUtl;
import gplx.types.custom.brys.wtrs.BryWtr;
import gplx.types.basics.utls.StringUtl;
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 BryWtr tmp_bfr = BryWtr.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))
@@ -36,58 +40,58 @@ public class Gfo_cmd_arg_mgr_printer {
return true;
}
public String Get_args() {
tmp_bfr.Add_byte_nl();
tmp_bfr.Add_str_a7_w_nl("arguments:");
tmp_bfr.AddByteNl();
tmp_bfr.AddStrA7Nl("arguments:");
String[] orig_ary = arg_mgr.Orig_ary();
int len = orig_ary.length;
if (len == 0) {
tmp_bfr.Add_str_a7_w_nl(" **** NONE ****");
tmp_bfr.Add_str_a7_w_nl(" use --help to show help");
tmp_bfr.AddStrA7Nl(" **** NONE ****");
tmp_bfr.AddStrA7Nl(" use --help to show help");
}
else {
for (int i = 0; i < len; i++) {
String line = String_.Format(" [{0}] = '{1}'", i, orig_ary[i]);
tmp_bfr.Add_str_u8_w_nl(line);
String line = StringUtl.Format(" [{0}] = '{1}'", i, orig_ary[i]);
tmp_bfr.AddStrU8Nl(line);
}
}
return tmp_bfr.To_str_and_clear();
return tmp_bfr.ToStrAndClear();
}
public String Get_fail() {
tmp_bfr.Add_str_a7_w_nl("** error: ");
tmp_bfr.AddStrA7Nl("** error: ");
String[] err_ary = arg_mgr.Errs__to_str_ary();
int len = err_ary.length;
for (int i = 0; i < len; ++i)
tmp_bfr.Add_str_u8_w_nl(" " + err_ary[i]);
tmp_bfr.Add_byte_nl();
tmp_bfr.Add_str_a7_w_nl(String_.Repeat("-", 80));
return tmp_bfr.To_str_and_clear();
tmp_bfr.AddStrU8Nl(" " + err_ary[i]);
tmp_bfr.AddByteNl();
tmp_bfr.AddStrA7Nl(StringUtl.Repeat("-", 80));
return tmp_bfr.ToStrAndClear();
}
public String Get_help(String app_name) {
tmp_bfr.Add_str_a7_w_nl("example:");
tmp_bfr.Add_str_a7(String_.Format(" java -jar {0}.jar", app_name));
tmp_bfr.AddStrA7Nl("example:");
tmp_bfr.AddStrA7(StringUtl.Format(" java -jar {0}.jar", app_name));
int key_max = 0, tid_max = 0;
int len = arg_mgr.Len();
for (int i = 0; i < len; i++) {
Gfo_cmd_arg_itm arg = arg_mgr.Get_at(i); if (arg.Tid() != Gfo_cmd_arg_itm_.Tid_general) continue; // skip header, help
tmp_bfr.Add_str_a7(" ").Add_str_a7(Gfo_cmd_arg_mgr.Key_prefix).Add_str_u8(arg.Key()).Add_str_a7(" ").Add_str_u8(arg.Example());
int key_len = String_.Len(arg.Key()); if (key_len > key_max) key_max = key_len;
int tid_len = String_.Len(String_.Format("[{0}:{1}]", arg.Reqd_str(), arg.Val_tid_str())); if (tid_len > tid_max) tid_max = tid_len;
tmp_bfr.AddStrA7(" ").AddStrA7(Gfo_cmd_arg_mgr.Key_prefix).AddStrU8(arg.Key()).AddStrA7(" ").AddStrU8(arg.Example());
int key_len = StringUtl.Len(arg.Key()); if (key_len > key_max) key_max = key_len;
int tid_len = StringUtl.Len(StringUtl.Format("[{0}:{1}]", arg.Reqd_str(), arg.Val_tid_str())); if (tid_len > tid_max) tid_max = tid_len;
}
tmp_bfr.Add_byte_nl().Add_byte_nl();
tmp_bfr.Add_str_a7_w_nl("detail:");
tmp_bfr.AddByteNl().AddByteNl();
tmp_bfr.AddStrA7Nl("detail:");
for (int i = 0; i < len; i++) {
Gfo_cmd_arg_itm arg = (Gfo_cmd_arg_itm)arg_mgr.Get_at(i);
tmp_bfr.Add_str_a7(" ").Add_str_a7(Gfo_cmd_arg_mgr.Key_prefix)
.Add_str_u8(String_.PadEnd(arg.Key(), key_max + 1, " "))
.Add_str_u8(String_.PadEnd(String_.Format("[{0}:{1}]", arg.Reqd_str(), arg.Val_tid_str()), tid_max, " "));
tmp_bfr.AddStrA7(" ").AddStrA7(Gfo_cmd_arg_mgr.Key_prefix)
.AddStrU8(StringUtl.PadEnd(arg.Key(), key_max + 1, " "))
.AddStrU8(StringUtl.PadEnd(StringUtl.Format("[{0}:{1}]", arg.Reqd_str(), arg.Val_tid_str()), tid_max, " "));
if (arg.Dflt() != null) {
String dflt_val = Object_.Xto_str_strict_or_null_mark(arg.Dflt());
tmp_bfr.Add_str_u8(String_.Format(" default={0}", dflt_val));
String dflt_val = ObjectUtl.ToStrOrNullMark(arg.Dflt());
tmp_bfr.AddStrU8(StringUtl.Format(" default={0}", dflt_val));
}
tmp_bfr.Add_byte_nl();
tmp_bfr.AddByteNl();
if (arg.Note() != null)
tmp_bfr.Add_str_a7(" ").Add_str_u8(arg.Note()).Add_byte_nl();
tmp_bfr.AddStrA7(" ").AddStrU8(arg.Note()).AddByteNl();
}
return tmp_bfr.To_str_and_clear();
return tmp_bfr.ToStrAndClear();
}
}

View File

@@ -14,17 +14,17 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.consoles;
import gplx.Gfo_usr_dlg;
import gplx.Gfo_usr_dlg_;
import gplx.Gfo_usr_dlg__gui_mock;
import gplx.Io_url;
import gplx.Io_url_;
import gplx.String_;
import gplx.Tfds;
import gplx.libs.dlgs.Gfo_usr_dlg;
import gplx.libs.dlgs.Gfo_usr_dlg_;
import gplx.libs.dlgs.Gfo_usr_dlg__gui_mock;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.StringUtl;
import gplx.libs.files.Io_url;
import gplx.libs.files.Io_url_;
import gplx.core.envs.Op_sys;
import gplx.core.tests.Tst_chkr;
import gplx.core.tests.Tst_mgr;
import gplx.objects.primitives.BoolUtl;
import gplx.types.basics.utls.BoolUtl;
import org.junit.Before;
import org.junit.Test;
public class Gfo_cmd_arg_mgr_tst {
@@ -101,23 +101,23 @@ class Gfo_cmd_arg_mgr_fxt {
tst_mgr.Tst_ary("", expd, actl);
return this;
}
public Gfo_cmd_arg_mgr_fxt Test_errs_none() {return Test_errs(String_.Ary_empty);}
public Gfo_cmd_arg_mgr_fxt Test_errs_none() {return Test_errs(StringUtl.AryEmpty);}
public Gfo_cmd_arg_mgr_fxt Test_errs(String... expd) {
String[] actl = mgr.Errs__to_str_ary();
int len = actl.length;
for (int i = 0; i < len; ++i) { // extract key part; EX: "unknown key: abc" -> unknown key
actl[i] = String_.GetStrBefore(actl[i], ":");
actl[i] = StringUtl.GetStrBefore(actl[i], ":");
}
Tfds.Eq_ary_str(expd, actl);
GfoTstr.EqLines(expd, actl);
return this;
}
public Gfo_cmd_arg_mgr_fxt Test_write(String... expd) {
Tfds.Eq_ary_str(expd, ((Gfo_usr_dlg__gui_mock)usr_dlg.Gui_wkr()).Msgs().ToStrAryAndClear());
GfoTstr.EqLines(expd, ((Gfo_usr_dlg__gui_mock)usr_dlg.Gui_wkr()).Msgs().ToStrAryAndClear());
return this;
}
public void Test_val_as_url_rel_dir_or(String root_dir, String dir_spr, String val, String expd) {
Io_url actl = Make_arg("key").Val_(val).Val_as_url__rel_dir_or(Io_url_.new_dir_(root_dir).GenSubDir("dir"), null);
Tfds.Eq(expd, actl.Raw());
GfoTstr.EqObj(expd, actl.Raw());
}
}
class Gfo_cmd_itm_chkr implements Tst_chkr {

View File

@@ -13,7 +13,9 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.data_stores; import gplx.*;
package gplx.core.data_stores;
import gplx.types.basics.lists.Hash_adp;
import gplx.types.basics.lists.Hash_adp_;
public class Gfo_data_store {
private final Hash_adp hash = Hash_adp_.New();
public Gfo_data_itm Get_or_null(String key) {

View File

@@ -1,25 +1,26 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.enums; import gplx.*; import gplx.core.*;
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.enums;
import gplx.types.commons.GfoGuid;
class Gfo_enum_grp {
// private Ordered_hash itms = Ordered_hash_.New();
public Gfo_enum_grp(Guid_adp uid, String key, int id, String name, int sort, String xtn) {
public Gfo_enum_grp(GfoGuid uid, String key, int id, String name, int sort, String xtn) {
this.uid = uid; this.key = key; this.id = id; this.name = name; this.sort = sort; this.xtn = xtn;
}
public Guid_adp Uid() {return uid;} private Guid_adp uid;
public GfoGuid Uid() {return uid;} private GfoGuid uid;
public String Key() {return key;} private String key;
public int Id() {return id;} private int id;
public String Name() {return name;} private String name;
@@ -27,10 +28,10 @@ class Gfo_enum_grp {
public String Xtn() {return xtn;} private String xtn;
}
class Gfo_enum_itm {
public Gfo_enum_itm(Guid_adp uid, String key, int id, String name, int sort, String xtn) {
public Gfo_enum_itm(GfoGuid uid, String key, int id, String name, int sort, String xtn) {
this.uid = uid; this.key = key; this.id = id; this.name = name; this.sort = sort; this.xtn = xtn;
}
public Guid_adp Uid() {return uid;} private Guid_adp uid;
public GfoGuid Uid() {return uid;} private GfoGuid uid;
public String Key() {return key;} private String key;
public int Id() {return id;} private int id;
public String Name() {return name;} private String name;

View File

@@ -14,7 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.flds;
import gplx.objects.strings.AsciiByte;
import gplx.types.basics.constants.AsciiByte;
public class Gfo_fld_base {
public byte Row_dlm() {return row_dlm;} public Gfo_fld_base Row_dlm_(byte v) {row_dlm = v; return this;} protected byte row_dlm = AsciiByte.Nl;
public byte Fld_dlm() {return fld_dlm;} public Gfo_fld_base Fld_dlm_(byte v) {fld_dlm = v; return this;} protected byte fld_dlm = AsciiByte.Pipe;

View File

@@ -13,11 +13,18 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.flds; import gplx.*;
import gplx.core.encoders.*;
import gplx.objects.strings.AsciiByte;
package gplx.core.flds;
import gplx.core.encoders.Base85_;
import gplx.types.basics.utls.BryLni;
import gplx.types.basics.utls.BryUtl;
import gplx.types.custom.brys.wtrs.BryWtr;
import gplx.types.errs.ErrUtl;
import gplx.types.basics.constants.AsciiByte;
import gplx.types.commons.GfoDate;
import gplx.types.commons.GfoDateUtl;
import gplx.types.basics.utls.StringUtl;
public class Gfo_fld_rdr extends Gfo_fld_base {
private Bry_bfr bfr = Bry_bfr_.New();
private BryWtr bfr = BryWtr.New();
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;
@@ -26,15 +33,15 @@ public class Gfo_fld_rdr extends Gfo_fld_base {
public int Row_idx() {return row_idx;} private int row_idx;
public void Ini(byte[] data, int pos) {this.data = data; this.data_len = data.length; this.pos = pos;}
public String Read_str_simple() {Move_next_simple(); return String_.new_u8(data, fld_bgn, fld_end);}
public byte[] Read_bry_simple() {Move_next_simple(); return Bry_.Mid(data, fld_bgn, fld_end);} // was Mid_by_len???; 20120915
public String Read_str_simple() {Move_next_simple(); return StringUtl.NewU8(data, fld_bgn, fld_end);}
public byte[] Read_bry_simple() {Move_next_simple(); return BryLni.Mid(data, fld_bgn, fld_end);} // was Mid_by_len???; 20120915
public int Read_int_base85_lenN(int len) {fld_bgn = pos; fld_end = pos + len - 1 ; pos = pos + len + 1 ; return Base85_.To_int_by_bry(data, fld_bgn, fld_end);}
public int Read_int_base85_len5() {fld_bgn = pos; fld_end = pos + 4 ; pos = pos + 6 ; return Base85_.To_int_by_bry(data, fld_bgn, fld_end);}
public int Read_int() {Move_next_simple(); return Bry_.To_int_or(data, fld_bgn, fld_end, -1);}
public byte Read_int_as_byte() {Move_next_simple(); return (byte)Bry_.To_int_or(data, fld_bgn, fld_end, -1);}
public int Read_int() {Move_next_simple(); return BryUtl.ToIntOr(data, fld_bgn, fld_end, -1);}
public byte Read_int_as_byte() {Move_next_simple(); return (byte)BryUtl.ToIntOr(data, fld_bgn, fld_end, -1);}
public byte Read_byte() {Move_next_simple(); return data[fld_bgn];}
public double Read_double() {Move_next_simple(); return Bry_.To_double(data, fld_bgn, fld_end);}
public DateAdp Read_dte() {// NOTE: fmt = yyyyMMdd HHmmss.fff
public double Read_double() {Move_next_simple(); return BryUtl.ToDouble(data, fld_bgn, fld_end);}
public GfoDate Read_dte() {// NOTE: fmt = yyyyMMdd HHmmss.fff
int y = 0, M = 0, d = 0, H = 0, m = 0, s = 0, f = 0;
if (pos < data_len && data[pos] == row_dlm) {++pos; ++row_idx; fld_idx = 0;} fld_bgn = pos;
y += (data[fld_bgn + 0] - AsciiByte.Num0) * 1000;
@@ -54,10 +61,10 @@ public class Gfo_fld_rdr extends Gfo_fld_base {
f += (data[fld_bgn + 16] - AsciiByte.Num0) * 100;
f += (data[fld_bgn + 17] - AsciiByte.Num0) * 10;
f += (data[fld_bgn + 18] - AsciiByte.Num0);
if (data[fld_bgn + 19] != fld_dlm) throw Err_.new_wo_type("csv date is invalid", "txt", String_.new_u8__by_len(data, fld_bgn, 20));
if (data[fld_bgn + 19] != fld_dlm) throw ErrUtl.NewArgs("csv date is invalid", "txt", StringUtl.NewU8ByLen(data, fld_bgn, 20));
fld_end = pos + 20;
pos = fld_end + 1; ++fld_idx;
return DateAdp_.new_(y, M, d, H, m, s, f);
return GfoDateUtl.New(y, M, d, H, m, s, f);
}
public void Move_next_simple() {
if (pos < data_len) {
@@ -78,17 +85,17 @@ public class Gfo_fld_rdr extends Gfo_fld_base {
return;
}
}
throw Err_.new_wo_type("fld_dlm failed", "fld_dlm", (char)fld_dlm, "bgn", fld_bgn);
throw ErrUtl.NewArgs("fld_dlm failed", "fld_dlm", (char)fld_dlm, "bgn", fld_bgn);
}
public String Read_str_escape() {Move_next_escaped(bfr); return String_.new_u8(bfr.To_bry_and_clear());}
public byte[] Read_bry_escape() {Move_next_escaped(bfr); return bfr.To_bry_and_clear();}
public String Read_str_escape() {Move_next_escaped(bfr); return StringUtl.NewU8(bfr.ToBryAndClear());}
public byte[] Read_bry_escape() {Move_next_escaped(bfr); return bfr.ToBryAndClear();}
public void Move_1() {++pos;}
public void Move_next_escaped() {Move_next_escaped(bfr); bfr.Clear();}
public int Move_next_simple_fld() {
Move_next_simple();
return fld_end;
}
public int Move_next_escaped(Bry_bfr trg) {
public int Move_next_escaped(BryWtr trg) {
//if (pos < data_len && data[pos] == row_dlm) {++pos; ++row_idx; fld_idx = 0;} // REMOVE:20120919: this will fail for empty fields at end of line; EX: "a|\n"; intent was probably to auto-advance to new row, but this intent should be explicit
fld_bgn = pos;
boolean quote_on = false;
@@ -100,11 +107,11 @@ public class Gfo_fld_rdr extends Gfo_fld_base {
}
else if (b == escape_dlm) {
++i;
// if (i == data_len) throw Err_.new_wo_type("escape char at end of String");
// if (i == data_len) throw ErrUtl.NewArgs("escape char at end of String");
b = data[i];
byte escape_val = decode_regy[b];
if (escape_val == AsciiByte.Null) {trg.Add_byte(escape_dlm).Add_byte(b);} //throw Err_.new_fmt_("unknown escape key: key={0}", data[i]);
else trg.Add_byte(escape_val);
if (escape_val == AsciiByte.Null) {trg.AddByte(escape_dlm).AddByte(b);} //throw Err_.new_fmt_("unknown escape key: key={0}", data[i]);
else trg.AddByte(escape_val);
}
else if (b == AsciiByte.Null) {
trg.Add(Bry_nil);
@@ -113,7 +120,7 @@ public class Gfo_fld_rdr extends Gfo_fld_base {
quote_on = !quote_on;
}
else
trg.Add_byte(b);
trg.AddByte(b);
}
return -1;
}
@@ -121,5 +128,5 @@ public class Gfo_fld_rdr extends Gfo_fld_base {
public Gfo_fld_rdr Ctor_sql() {return (Gfo_fld_rdr)super.Ctor_sql_base();}
public static Gfo_fld_rdr xowa_() {return new Gfo_fld_rdr().Ctor_xdat();}
public static Gfo_fld_rdr sql_() {return new Gfo_fld_rdr().Ctor_sql();}
private static final byte[] Bry_nil = Bry_.new_a7("\\0");
private static final byte[] Bry_nil = BryUtl.NewA7("\\0");
}

View File

@@ -13,9 +13,11 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.flds; import gplx.*; import gplx.core.*;
package gplx.core.flds;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.BryUtl;
import gplx.types.custom.brys.wtrs.BryWtr;
import org.junit.*;
import gplx.core.ios.*;
public class Gfo_fld_rdr_tst {
Gfo_fld_rdr_fxt fxt = new Gfo_fld_rdr_fxt();
@Test public void Read_int() {fxt.ini_xdat().Raw_("123|") .tst_Read_int(123);}
@@ -37,18 +39,18 @@ public class Gfo_fld_rdr_tst {
}
class Gfo_fld_rdr_fxt {
Gfo_fld_rdr rdr = new Gfo_fld_rdr(); Gfo_fld_wtr wtr = Gfo_fld_wtr.xowa_();
public Gfo_fld_rdr_fxt Raw_(String v) {rdr.Data_(Bry_.new_u8(v)); return this;}
public Gfo_fld_rdr_fxt Raw_(String v) {rdr.Data_(BryUtl.NewU8(v)); return this;}
public Gfo_fld_rdr_fxt ini_xdat() {rdr.Ctor_xdat(); return this;}
public Gfo_fld_rdr_fxt ini_sql() {rdr.Ctor_sql(); return this;}
public Gfo_fld_rdr_fxt tst_Read_int(int expd) {Tfds.Eq(expd, rdr.Read_int()); return this;}
public Gfo_fld_rdr_fxt tst_Read_double(double expd) {Tfds.Eq(expd, rdr.Read_double()); return this;}
public Gfo_fld_rdr_fxt tst_Read_str_simple(String expd) {Tfds.Eq(expd, rdr.Read_str_simple()); return this;}
public Gfo_fld_rdr_fxt tst_Read_str_escape(String expd) {Tfds.Eq(expd, rdr.Read_str_escape()); return this;}
public Gfo_fld_rdr_fxt tst_Read_int(int expd) {GfoTstr.EqObj(expd, rdr.Read_int()); return this;}
public Gfo_fld_rdr_fxt tst_Read_double(double expd) {GfoTstr.EqObj(expd, rdr.Read_double()); return this;}
public Gfo_fld_rdr_fxt tst_Read_str_simple(String expd) {GfoTstr.EqObj(expd, rdr.Read_str_simple()); return this;}
public Gfo_fld_rdr_fxt tst_Read_str_escape(String expd) {GfoTstr.EqObj(expd, rdr.Read_str_escape()); return this;}
public Gfo_fld_rdr_fxt tst_Write_str_escape(String val, String expd) {
byte[] bry = Bry_.new_u8(val);
byte[] bry = BryUtl.NewU8(val);
wtr.Bfr_(bfr);
wtr.Write_bry_escape_fld(bry);
Tfds.Eq(expd, bfr.To_str());
GfoTstr.EqObj(expd, bfr.ToStr());
return this;
} private Bry_bfr bfr = Bry_bfr_.New();
} private BryWtr bfr = BryWtr.New();
}

View File

@@ -13,40 +13,31 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.flds; import gplx.*;
import gplx.core.ios.*; import gplx.core.encoders.*;
import gplx.objects.strings.AsciiByte;
package gplx.core.flds;
import gplx.core.ios.Io_url_gen;
import gplx.libs.files.Io_mgr;
import gplx.libs.ios.IoConsts;
import gplx.types.custom.brys.wtrs.BryWtr;
import gplx.types.basics.constants.AsciiByte;
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 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;}
public Gfo_fld_wtr Write_int_fixed_fld(int v, int len) {bfr.Add_int_fixed(v, len); bfr.Add_byte(fld_dlm); return this;}
public Gfo_fld_wtr Write_double_fld(double v) {bfr.Add_double(v); bfr.Add_byte(fld_dlm); return this;}
public Gfo_fld_wtr Write_byte_fld(byte v) {bfr.Add_byte(v); bfr.Add_byte(fld_dlm); return this;}
public Gfo_fld_wtr Write_bry_escape_fld(byte[] val) {Write_bry_escape(val, 0, val.length); bfr.Add_byte(fld_dlm); return this;}
public Gfo_fld_wtr Write_bry_escape_fld(byte[] val, int bgn, int end) {Write_bry_escape(val, bgn, end); bfr.Add_byte(fld_dlm); return this;}
public Gfo_fld_wtr Write_dlm_row() { bfr.Add_byte(row_dlm); return this;}
public Gfo_fld_wtr Write_dlm_fld() { bfr.Add_byte(fld_dlm); return this;}
public Gfo_fld_wtr Write_int_base85_lenN_row(int v, int len) {bfr.Add_base85(v, len); bfr.Add_byte(row_dlm); return this;}
public Gfo_fld_wtr Write_int_base85_len5_row(int v) {bfr.Add_base85(v, Base85_.Len_int); bfr.Add_byte(row_dlm); return this;}
public Gfo_fld_wtr Write_bry_escape_row(byte[] val) {Write_bry_escape(val, 0, val.length); bfr.Add_byte(row_dlm); return this;}
public Gfo_fld_wtr Write_bry_escape_row(byte[] val, int bgn, int end) {Write_bry_escape(val, bgn, end); bfr.Add_byte(row_dlm); return this;}
public Gfo_fld_wtr Write_double_row(double v) {bfr.Add_double(v); bfr.Add_byte(row_dlm); return this;}
public BryWtr Bfr() {return bfr;} public Gfo_fld_wtr Bfr_(BryWtr v) {bfr = v; return this;} BryWtr bfr;
public Gfo_fld_wtr() {this.bfr = BryWtr.New();}
public Gfo_fld_wtr Write_byte_fld(byte v) {bfr.AddByte(v); bfr.AddByte(fld_dlm); return this;}
public Gfo_fld_wtr Write_bry_escape_fld(byte[] val) {Write_bry_escape(val, 0, val.length); bfr.AddByte(fld_dlm); return this;}
public Gfo_fld_wtr Write_dlm_row() { bfr.AddByte(row_dlm); return this;}
Gfo_fld_wtr Write_bry_escape(byte[] val, int bgn, int end) {
for (int i = bgn; i < end; i++) {
byte b = val[i];
byte escape_val = encode_regy[b & 0xFF]; // PATCH.JAVA:need to convert to unsigned byte
if (escape_val == AsciiByte.Null) bfr.Add_byte(b);
else {bfr.Add_byte(escape_dlm); bfr.Add_byte(escape_val);}
if (escape_val == AsciiByte.Null) bfr.AddByte(b);
else {bfr.AddByte(escape_dlm); bfr.AddByte(escape_val);}
}
return this;
}
public Gfo_fld_wtr Rls() {bfr.Rls(); return this;}
public Io_url_gen Fil_gen() {return fil_gen;} public Gfo_fld_wtr Fil_gen_(Io_url_gen v) {fil_gen = v; return this;} Io_url_gen fil_gen;
public int Bfr_max() {return bfr_max;} public Gfo_fld_wtr Bfr_max_(int v) {bfr_max = v; return this;} private int bfr_max = Io_mgr.Len_mb;
public int Bfr_max() {return bfr_max;} public Gfo_fld_wtr Bfr_max_(int v) {bfr_max = v; return this;} private int bfr_max = IoConsts.LenMB;
public boolean Flush_needed(int v) {return bfr.Len() + v > bfr_max;}
public void Flush() {
if (Fil_gen().Cur_url() == null) fil_gen.Nxt_url();

View File

@@ -13,12 +13,17 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.gfobjs; import gplx.*;
package gplx.core.gfobjs;
import gplx.libs.files.Io_url;
import gplx.libs.files.Io_url_;
import gplx.types.basics.lists.Ordered_hash;
import gplx.types.basics.lists.Ordered_hash_;
import gplx.types.errs.ErrUtl;
public class Gfobj_nde implements Gfobj_grp {
private Ordered_hash subs;
public byte Grp_tid() {return Gfobj_grp_.Grp_tid__nde;}
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_at(int i) {return subs == null ? null : (Gfobj_fld)subs.GetAt(i);}
public Gfobj_fld Get_by(String k) {return subs == null ? null : (Gfobj_fld)subs.GetByOrNull(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();}
@@ -28,19 +33,19 @@ public class Gfobj_nde implements Gfobj_grp {
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());
default: throw ErrUtl.NewUnhandled(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());
default: throw ErrUtl.NewUnhandled(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 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));}

View File

@@ -1,106 +1,104 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.gfobjs;
import gplx.Err_;
import gplx.Io_mgr;
import gplx.Io_url;
import gplx.langs.jsons.Json_ary;
import gplx.langs.jsons.Json_doc;
import gplx.langs.jsons.Json_itm;
import gplx.langs.jsons.Json_itm_;
import gplx.langs.jsons.Json_itm_bool;
import gplx.langs.jsons.Json_itm_decimal;
import gplx.langs.jsons.Json_itm_int;
import gplx.langs.jsons.Json_itm_long;
import gplx.langs.jsons.Json_itm_str;
import gplx.langs.jsons.Json_kv;
import gplx.langs.jsons.Json_nde;
import gplx.langs.jsons.Json_parser;
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;
}
}
}
}
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.gfobjs;
import gplx.langs.jsons.Json_ary;
import gplx.langs.jsons.Json_doc;
import gplx.langs.jsons.Json_itm;
import gplx.langs.jsons.Json_itm_;
import gplx.langs.jsons.Json_itm_bool;
import gplx.langs.jsons.Json_itm_decimal;
import gplx.langs.jsons.Json_itm_int;
import gplx.langs.jsons.Json_itm_long;
import gplx.langs.jsons.Json_itm_str;
import gplx.langs.jsons.Json_kv;
import gplx.langs.jsons.Json_nde;
import gplx.langs.jsons.Json_parser;
import gplx.libs.files.Io_mgr;
import gplx.libs.files.Io_url;
import gplx.types.errs.ErrUtl;
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().ToDouble()); 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 ErrUtl.NewUnhandled(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

@@ -13,13 +13,13 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.tests.*;
import gplx.langs.jsons.*;
package gplx.core.gfobjs;
import gplx.types.basics.utls.StringUtl;
import org.junit.*;
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
fxt.Test__parse(StringUtl.ConcatLinesNlSkipLast
( "{ 'k1':true"
, ", 'k2':123"
, ", 'k3':9876543210"
@@ -37,8 +37,8 @@ public class Gfobj_rdr__json_tst {
, fxt.Make__fld_str ("k6", "abc")
));
}
@Test public void Nested() {
fxt.Test__parse(String_.Concat_lines_nl_skip_last
@Test public void Nested() {
fxt.Test__parse(StringUtl.ConcatLinesNlSkipLast
( "{ 'a1':'1a'"
, ", 'a2':"
, " { 'b1':'1b'"
@@ -59,8 +59,8 @@ public class Gfobj_rdr__json_tst {
, fxt.Make__fld_ary ("a3", 1, 2, 3)
));
}
@Test public void Array() {
fxt.Test__parse(String_.Concat_lines_nl_skip_last
@Test public void Array() {
fxt.Test__parse(StringUtl.ConcatLinesNlSkipLast
( "["
, " [1, 2, 3]"
, ", ['a', 'b', 'c']"

View File

@@ -13,13 +13,18 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
import gplx.langs.jsons.*;
package gplx.core.gfobjs;
import gplx.langs.jsons.Json_wtr;
import gplx.libs.files.Io_mgr;
import gplx.libs.files.Io_url;
import gplx.types.custom.brys.wtrs.BryWtr;
import gplx.types.basics.utls.ClassUtl;
import gplx.types.errs.ErrUtl;
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 BryWtr 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());
@@ -37,7 +42,7 @@ public class Gfobj_wtr__json {
wtr.Doc_ary_end();
break;
default:
throw Err_.new_unhandled_default(root.Grp_tid());
throw ErrUtl.NewUnhandled(root.Grp_tid());
}
return this;
}
@@ -58,7 +63,7 @@ public class Gfobj_wtr__json {
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());
default: throw ErrUtl.NewUnhandled(itm.Fld_tid());
}
}
private void Write_ary(Gfobj_ary ary) {
@@ -66,13 +71,13 @@ public class Gfobj_wtr__json {
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_.Type_by_obj(sub_itm);
if (Type_.Eq(sub_itm_type, Gfobj_ary.class)) {
Class<?> sub_itm_type = ClassUtl.TypeByObj(sub_itm);
if (ClassUtl.Eq(sub_itm_type, Gfobj_ary.class)) {
wtr.Ary_bgn_ary();
Write_ary((Gfobj_ary)sub_itm);
wtr.Ary_end();
}
else if (Type_.Eq(sub_itm_type, Gfobj_nde.class)) {
else if (ClassUtl.Eq(sub_itm_type, Gfobj_nde.class)) {
wtr.Nde_bgn_ary();
Write_nde((Gfobj_nde)sub_itm);
wtr.Nde_end();

View File

@@ -13,8 +13,11 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
import gplx.core.tests.*; import gplx.langs.jsons.*;
package gplx.core.gfobjs;
import gplx.langs.jsons.*;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.BryUtl;
import gplx.types.basics.utls.StringUtl;
public class Gfobj_wtr__json_fxt {
protected final Gfobj_wtr__json mgr = new Gfobj_wtr__json();
public Gfobj_nde Make__nde(Gfobj_fld... ary) {return Make__nde(Gfobj_nde.New(), ary);}
@@ -40,13 +43,13 @@ public class Gfobj_wtr__json_fxt {
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");
GfoTstr.EqLines(expd, StringUtl.SplitLinesNl(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");
Gfobj_grp actl = rdr.Parse(BryUtl.NewU8(Json_doc.Make_str_by_apos(src)));
GfoTstr.EqLines(BryUtl.Ary(StringUtl.SplitLinesNl(mgr.Write(expd).To_str())), BryUtl.Ary(StringUtl.SplitLinesNl(mgr.Write(actl).To_str())), "json_write");
return this;
}
}

View File

@@ -1,23 +1,24 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.intls.ucas; import gplx.*; import gplx.core.*; import gplx.core.intls.*;
import java.util.Locale;
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.intls.ucas;
import com.ibm.icu.text.CollationKey;
import com.ibm.icu.text.Collator;
import com.ibm.icu.text.RuleBasedCollator;
import gplx.types.errs.ErrUtl;
import java.util.Locale;
class Uca_collator__icu__4_8 implements Uca_collator {
private Collator collator;
public void Init(String locale, boolean numeric_ordering) {
@@ -27,7 +28,7 @@ class Uca_collator__icu__4_8 implements Uca_collator {
// NOTE: delaying cast to RuleBasedCollator b/c Collator.getInstance may return a non-RuleBasedCollator and don't want cast to fail if numeric_ordering is false
((RuleBasedCollator)collator).setNumericCollation(true);
}
} catch (Exception e) {throw Err_.new_wo_type("collator init failed", "err", Err_.Message_lang(e));}
} catch (Exception e) {throw ErrUtl.NewArgs("collator init failed", "err", ErrUtl.Message(e));}
}
public byte[] Get_sortkey(String s) {
CollationKey key = collator.getCollationKey(s);

View File

@@ -13,8 +13,11 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.intls.ucas; import gplx.*;
import gplx.objects.strings.AsciiByte;
package gplx.core.intls.ucas;
import gplx.types.basics.strings.unicodes.Utf8Utl;
import gplx.types.basics.utls.BryUtl;
import gplx.types.basics.constants.AsciiByte;
import gplx.types.basics.lists.Hash_adp_bry;
public class Uca_ltr_extractor {
private final boolean numeric;
private final byte[] numeric_heading;
@@ -22,12 +25,12 @@ public class Uca_ltr_extractor {
public Uca_ltr_extractor(boolean numeric) {
this.numeric = numeric;
if (numeric) {
numeric_heading = Bry_.new_a7("0-9");
numeric_heading = BryUtl.NewA7("0-9");
// create hash of "0", "1", "2", ...
numeric_hash = Hash_adp_bry.cs();
for (int i = 0; i < 10; ++i) {
byte[] digit_bry = Bry_.new_by_int(AsciiByte.Num0 + i);
byte[] digit_bry = BryUtl.NewByInt(AsciiByte.Num0 + i);
numeric_hash.Add(digit_bry, digit_bry);
}
}
@@ -39,8 +42,8 @@ public class Uca_ltr_extractor {
public byte[] Get_1st_ltr(byte[] bry) {
// NOTE: this is simplified and only does numeric logic; MW code loads up all ICU chars via first-letters-root.ser, adds custom chars, sorts them, and then does a binary search to find it; REF:IcuCollation.php!getFirstLetter
int bry_len = bry.length;
if (bry_len == 0) return Bry_.Empty;
byte[] rv = gplx.core.intls.Utf8_.Get_char_at_pos_as_bry(bry, 0);
if (bry_len == 0) return BryUtl.Empty;
byte[] rv = Utf8Utl.GetCharAtPosAsBry(bry, 0);
if (numeric) {
if (numeric_hash.Has(rv))
rv = numeric_heading;

View File

@@ -14,9 +14,9 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.ios;
import gplx.objects.arrays.ArrayUtl;
import gplx.objects.lists.CompareAbleUtl;
import gplx.objects.lists.ComparerAble;
import gplx.types.basics.utls.ArrayUtl;
import gplx.types.commons.lists.CompareAbleUtl;
import gplx.types.commons.lists.ComparerAble;
class BinaryHeap_Io_line_rdr {
public BinaryHeap_Io_line_rdr(ComparerAble comparer) {this.comparer = comparer;} ComparerAble comparer;
Io_line_rdr[] ary = Ary_empty; int ary_len = 0, ary_max = 0;

View File

@@ -13,7 +13,13 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.ios; import gplx.*; import gplx.core.*;
package gplx.core.ios;
import gplx.libs.dlgs.Gfo_usr_dlg_;
import gplx.libs.files.Io_mgr;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.StringUtl;
import gplx.libs.files.Io_url;
import gplx.libs.files.Io_url_;
import org.junit.*;
public class BinaryHeap_Io_line_rdr_tst {
BinaryHeap_Io_line_rdr_fxt fxt = new BinaryHeap_Io_line_rdr_fxt();
@@ -40,9 +46,9 @@ class BinaryHeap_Io_line_rdr_fxt {
String[] actl = new String[file_total];
for (int i = 0; i < actl.length; i++) {
Io_line_rdr bfr = heap.Pop();
actl[i] = String_.new_u8(bfr.Bfr(), 0, bfr.Bfr_len());
actl[i] = StringUtl.NewU8(bfr.Bfr(), 0, bfr.Bfr_len());
}
Tfds.Eq_ary_str(expd, actl);
GfoTstr.EqLines(expd, actl);
return this;
}
}

View File

@@ -13,15 +13,21 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.ios; import gplx.*; import gplx.core.*;
import gplx.core.ios.streams.*;/*IoStream*/
package gplx.core.ios;
import gplx.libs.files.Io_mgr;
import gplx.frameworks.objects.Rls_able;
import gplx.core.ios.streams.Io_stream_rdr;
import gplx.types.errs.ErrUtl;
import gplx.libs.files.Io_url;
import gplx.libs.files.Io_url_;
import gplx.types.basics.utls.StringUtl;
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) {
this.rdr = rdr; this.url = url;
if (bfr_len <= 0) throw Err_.new_wo_type("bfr_len must be > 0", "bfr_len", bfr_len);
if (bfr_len <= 0) throw ErrUtl.NewArgs("bfr_len must be > 0", "bfr_len", bfr_len);
bfr = new byte[bfr_len]; this.bfr_len = bfr_len;
IoItmFil fil = Io_mgr.Instance.QueryFil(url); if (!fil.Exists()) throw Err_.new_wo_type("fil does not exist", "url", url);
IoItmFil fil = Io_mgr.Instance.QueryFil(url); if (!fil.Exists()) throw ErrUtl.NewArgs("fil does not exist", "url", url);
fil_len = fil.Size();
fil_pos = 0;
fil_eof = false;
@@ -34,7 +40,7 @@ public class Io_buffer_rdr implements Rls_able {
public boolean Fil_eof() {return fil_eof;} private boolean fil_eof;
public boolean Bfr_load_all() {return Bfr_load(0, bfr_len);}
public boolean Bfr_load_from(int bfr_pos) {
if (bfr_pos < 0 || bfr_pos > bfr_len) throw Err_.new_wo_type("invalid bfr_pos", "bfr_pos", bfr_pos, "bfr_len", bfr_len);
if (bfr_pos < 0 || bfr_pos > bfr_len) throw ErrUtl.NewArgs("invalid bfr_pos", "bfr_pos", bfr_pos, "bfr_len", bfr_len);
for (int i = bfr_pos; i < bfr_len; i++) // shift end of bfr to bgn; EX: bfr[10] and load_from(8); [8] -> [0]; [9] -> [1];
bfr[i - bfr_pos] = bfr[i];
return Bfr_load(bfr_len - bfr_pos, bfr_pos); // fill rest of bfr; EX: [2]... will come from file
@@ -57,8 +63,8 @@ public class Io_buffer_rdr implements Rls_able {
bfr_len = -1;
if (rdr != null) rdr.Rls();
}
@gplx.Internal protected void Dump_to_file(int bgn, int len, String url_str, String msg) { // DBG:
String text = String_.new_u8__by_len(bfr, bgn, len);
public void Dump_to_file(int bgn, int len, String url_str, String msg) { // DBG:
String text = StringUtl.NewU8ByLen(bfr, bgn, len);
Io_mgr.Instance.AppendFilStr(Io_url_.new_any_(url_str), msg + text + "\n");
}
public static Io_buffer_rdr new_(Io_stream_rdr rdr, int bfr_len) {

View File

@@ -13,8 +13,14 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.ios; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.ios.*; import gplx.core.ios.streams.*;
package gplx.core.ios;
import gplx.libs.files.Io_mgr;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.StringUtl;
import gplx.libs.files.Io_url;
import gplx.libs.files.Io_url_;
import org.junit.*;
import gplx.core.ios.streams.*;
public class Io_buffer_rdr_tst {
@Before public void init() {
Io_mgr.Instance.InitEngine_mem();
@@ -54,9 +60,9 @@ public class Io_buffer_rdr_tst {
Io_buffer_rdr_tst tst_Bfr(String... expdAry) {
String[] actlAry = new String[rdr.Bfr_len()];
for (int i = 0; i < actlAry.length; i++)
actlAry[i] = String_.new_u8(rdr.Bfr(), i, i + 1);
Tfds.Eq_ary(expdAry, actlAry);
actlAry[i] = StringUtl.NewU8(rdr.Bfr(), i, i + 1);
GfoTstr.EqLines(expdAry, actlAry);
return this;
}
Io_buffer_rdr_tst tst_ReadDone(boolean expd) {Tfds.Eq(expd, rdr.Fil_eof()); return this;}
Io_buffer_rdr_tst tst_ReadDone(boolean expd) {GfoTstr.EqObj(expd, rdr.Fil_eof()); return this;}
}

View File

@@ -13,18 +13,19 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.ios; import gplx.*; import gplx.core.*;
import gplx.core.tests.*;
public class Io_fil_chkr implements Tst_chkr {
public Io_fil_chkr(Io_url url, String data) {this.expd_url = url; this.expd_data = data;}
public Io_url Expd_url() {return expd_url;} public Io_fil_chkr Expd_url_(Io_url v) {expd_url = v; return this;} Io_url expd_url;
public String Expd_data() {return expd_data;} public Io_fil_chkr Expd_data_(String v) {expd_data = v; return this;} private String expd_data;
public Class<?> TypeOf() {return gplx.core.ios.Io_fil.class;}
public int Chk(Tst_mgr mgr, String path, Object actl) {
gplx.core.ios.Io_fil fil = (gplx.core.ios.Io_fil)actl;
int rv = 0;
rv += mgr.Tst_val(expd_url == null, path, "url", expd_url, fil.Url());
rv += mgr.Tst_val(expd_data == null, path, "data", expd_data, fil.Data());
return rv;
}
}
package gplx.core.ios;
import gplx.core.tests.*;
import gplx.libs.files.Io_url;
public class Io_fil_chkr implements Tst_chkr {
public Io_fil_chkr(Io_url url, String data) {this.expd_url = url; this.expd_data = data;}
public Io_url Expd_url() {return expd_url;} public Io_fil_chkr Expd_url_(Io_url v) {expd_url = v; return this;} Io_url expd_url;
public String Expd_data() {return expd_data;} public Io_fil_chkr Expd_data_(String v) {expd_data = v; return this;} private String expd_data;
public Class<?> TypeOf() {return gplx.core.ios.Io_fil.class;}
public int Chk(Tst_mgr mgr, String path, Object actl) {
gplx.core.ios.Io_fil fil = (gplx.core.ios.Io_fil)actl;
int rv = 0;
rv += mgr.Tst_val(expd_url == null, path, "url", expd_url, fil.Url());
rv += mgr.Tst_val(expd_data == null, path, "data", expd_data, fil.Data());
return rv;
}
}

View File

@@ -13,11 +13,17 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.ios; import gplx.*;
package gplx.core.ios;
import gplx.core.ios.streams.*;
import gplx.objects.arrays.ArrayUtl;
import gplx.objects.lists.CompareAbleUtl;
import gplx.objects.strings.AsciiByte;
import gplx.libs.dlgs.Gfo_usr_dlg;
import gplx.libs.files.Io_mgr;
import gplx.types.basics.utls.ArrayUtl;
import gplx.types.basics.utls.BryLni;
import gplx.types.basics.utls.BryUtl;
import gplx.types.custom.brys.BryFind;
import gplx.types.commons.lists.CompareAbleUtl;
import gplx.types.basics.constants.AsciiByte;
import gplx.libs.files.Io_url;
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;
@@ -44,8 +50,8 @@ public class Io_line_rdr {
public Io_line_rdr_key_gen Key_gen() {return key_gen;} public Io_line_rdr Key_gen_(Io_line_rdr_key_gen v) {key_gen = v; return this;} Io_line_rdr_key_gen key_gen = Io_line_rdr_key_gen_.first_pipe;
public void Truncate(int pos) {
this.Read_next();
int end = Bry_find_.Find_fwd(bfr, AsciiByte.Null); if (end == -1) end = bfr.length;
bfr = Bry_.Mid(bfr, pos, end);
int end = BryFind.FindFwd(bfr, AsciiByte.Null); if (end == -1) end = bfr.length;
bfr = BryLni.Mid(bfr, pos, end);
bfr_len = bfr.length;
bfr_last_read = 0;
}
@@ -89,7 +95,7 @@ public class Io_line_rdr {
return false;
}
while (true) {
int compare = Bry_.Compare(ttl, 0, ttl.length, bfr, key_pos_bgn, key_pos_end);
int compare = BryUtl.Compare(ttl, 0, ttl.length, bfr, key_pos_bgn, key_pos_end);
if (compare == CompareAbleUtl.Same) { // eq; return true and move fwd; EX: "BA" and "BA"
return true;
}
@@ -138,11 +144,11 @@ public class Io_line_rdr {
if (file_skip_line0) {
byte[] stream_bry = Io_mgr.Instance.LoadFilBry(url);
int stream_bry_len = stream_bry.length;
int nl_pos = Bry_find_.Find_fwd(stream_bry, AsciiByte.Nl, 0, stream_bry_len);
if (nl_pos == Bry_find_.Not_found)
stream_bry = Bry_.Empty;
int nl_pos = BryFind.FindFwd(stream_bry, AsciiByte.Nl, 0, stream_bry_len);
if (nl_pos == BryFind.NotFound)
stream_bry = BryUtl.Empty;
else
stream_bry = Bry_.Mid(stream_bry, nl_pos + 1, stream_bry_len);
stream_bry = BryLni.Mid(stream_bry, nl_pos + 1, stream_bry_len);
stream = gplx.core.ios.streams.IoStream_.ary_(stream_bry);
}
else {

View File

@@ -14,7 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.ios;
import gplx.objects.strings.AsciiByte;
import gplx.types.basics.constants.AsciiByte;
public class Io_line_rdr_key_gen_ {
public static final Io_line_rdr_key_gen first_pipe = new Io_line_rdr_key_gen_first(AsciiByte.Pipe);
public static final Io_line_rdr_key_gen last_pipe = new Io_line_rdr_key_gen_last(AsciiByte.Pipe);

View File

@@ -13,8 +13,18 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.ios; import gplx.*;
import gplx.objects.strings.AsciiByte;
package gplx.core.ios;
import gplx.libs.dlgs.Gfo_usr_dlg_;
import gplx.libs.files.Io_mgr;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.BryUtl;
import gplx.types.custom.brys.wtrs.BryWtr;
import gplx.types.basics.constants.AsciiByte;
import gplx.types.basics.lists.List_adp;
import gplx.types.basics.lists.List_adp_;
import gplx.types.basics.utls.StringUtl;
import gplx.libs.files.Io_url;
import gplx.libs.files.Io_url_;
import org.junit.*; import gplx.core.envs.*;
public class Io_line_rdr_tst {
Io_line_rdr_fxt fxt;
@@ -47,35 +57,35 @@ 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(); BryWtr tmp = BryWtr.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;}
public Io_line_rdr_fxt File_lines_(int count) {
for (int i = 0; i < count; i++)
tmp.Add_int_fixed(i, 2).Add_byte_nl();
Io_mgr.Instance.SaveFilBry(rdr.Urls()[0], tmp.To_bry_and_clear());
tmp.AddIntFixed(i, 2).AddByteNl();
Io_mgr.Instance.SaveFilBry(rdr.Urls()[0], tmp.ToBryAndClear());
return this;
}
// public Io_url[] Src_fils() {return src_fils;} public Io_line_rdr_fxt Src_fils_(Io_url[] v) {src_fils = v; return this;} Io_url[] src_fils;
public Io_line_rdr_fxt tst_Match(String match, String expd) {
rdr.Key_gen_(Io_line_rdr_key_gen_.first_pipe);
boolean match_v = rdr.Match(Bry_.new_u8(match));
String actl = match_v ? String_.new_u8(rdr.Bfr(), rdr.Key_pos_bgn(), rdr.Key_pos_end()) : "";
Tfds.Eq(expd, actl);
boolean match_v = rdr.Match(BryUtl.NewU8(match));
String actl = match_v ? StringUtl.NewU8(rdr.Bfr(), rdr.Key_pos_bgn(), rdr.Key_pos_end()) : "";
GfoTstr.EqObj(expd, actl);
return this;
}
public Io_line_rdr_fxt File_lines_pipe_(int count) {
for (int i = 0; i < count; i++)
tmp.Add_int_fixed(i, 2).Add_byte(AsciiByte.Pipe).Add_byte_nl();
Io_mgr.Instance.SaveFilBry(rdr.Urls()[0], tmp.To_bry_and_clear());
tmp.AddIntFixed(i, 2).AddByte(AsciiByte.Pipe).AddByteNl();
Io_mgr.Instance.SaveFilBry(rdr.Urls()[0], tmp.ToBryAndClear());
return this;
}
public Io_line_rdr_fxt File_lines_(int fil_idx, int bgn, int end) {
for (int i = bgn; i < end; i++)
tmp.Add_int_fixed(i, 2).Add_byte_nl();
Io_mgr.Instance.SaveFilBry(rdr.Urls()[fil_idx], tmp.To_bry_and_clear());
tmp.AddIntFixed(i, 2).AddByteNl();
Io_mgr.Instance.SaveFilBry(rdr.Urls()[fil_idx], tmp.ToBryAndClear());
return this;
}
public Io_line_rdr_fxt Clear() {rdr.Clear(); return this;}
@@ -85,11 +95,11 @@ class Io_line_rdr_fxt {
expd[i] = expd[i] + Op_sys.Lnx.Nl_str();
for (int i = 0; i < count; i++) {
if (rdr.Read_next())
lines.Add(String_.new_u8(rdr.Bfr(), rdr.Itm_pos_bgn(), rdr.Itm_pos_end()));
lines.Add(StringUtl.NewU8(rdr.Bfr(), rdr.Itm_pos_bgn(), rdr.Itm_pos_end()));
else
break;
}
Tfds.Eq_ary_str(expd, lines.ToStrAry());
GfoTstr.EqLines(expd, lines.ToStrAry());
return this;
}
}

View File

@@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.ios; import gplx.*; import gplx.core.*;
public interface Io_make_cmd extends Io_sort_cmd {
Io_sort_cmd Make_dir_(Io_url v);
}
package gplx.core.ios;
import gplx.libs.files.Io_url;
public interface Io_make_cmd extends Io_sort_cmd {
Io_sort_cmd Make_dir_(Io_url v);
}

View File

@@ -13,16 +13,23 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.ios; import gplx.*;
package gplx.core.ios;
import gplx.core.envs.*;
import gplx.objects.lists.ComparerAble;
import gplx.libs.dlgs.Gfo_usr_dlg;
import gplx.libs.files.Io_mgr;
import gplx.libs.ios.IoConsts;
import gplx.types.custom.brys.wtrs.BryWtr;
import gplx.types.commons.lists.ComparerAble;
import gplx.libs.files.Io_url;
import gplx.types.basics.lists.List_adp;
import gplx.types.basics.lists.List_adp_;
public class Io_sort {
public Io_sort Memory_max_(int v) {memory_max = v; return this;} private int memory_max = Io_mgr.Len_kb;
public Io_sort Memory_max_(int v) {memory_max = v; return this;} private int memory_max = IoConsts.LenKB;
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
Io_line_rdr rdr = new Io_line_rdr(usr_dlg, src_fil_gen.Prv_urls()).Load_len_(4 * IoConsts.LenKB).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;
BryWtr bfr = BryWtr.NewAndReset(Const_bfr_max); int size_cur = 0;
List_adp row_list = List_adp_.New();
while (true) {
boolean reading = rdr.Read_next();
@@ -35,17 +42,17 @@ public class Io_sort {
usr_dlg.Prog_one(GRP_KEY, "write", "writing chunk: ~{0}", trg_url.Raw());
Split_flush(trg_url, row_list, memory_max, bfr, rv);
row_list.ResizeBounds(16); // MEM: resize bounds manually; note that each Flush-set may have widely disparately #of rows (EX: 1 row with a million pages vs. 1 million rows with 1 page)
size_new = size_row; System_.Garbage_collect();
size_new = size_row; SystemUtl.Garbage_collect();
if (!reading) break;
}
row_list.Add(new Io_sort_split_itm(rdr));
size_cur = size_new;
}
rdr.Rls(); bfr.Rls(); System_.Garbage_collect();
rdr.Rls(); bfr.Rls(); SystemUtl.Garbage_collect();
return (Io_url[])rv.ToAry(Io_url.class);
}
public void Merge(Gfo_usr_dlg usr_dlg, Io_url[] src_ary, ComparerAble comparer, Io_line_rdr_key_gen key_gen, Io_sort_cmd cmd) {
BinaryHeap_Io_line_rdr heap = load_(usr_dlg, src_ary, comparer, key_gen, memory_max); if (heap.Len() == 0) return;//throw Err_.new_wo_type(ArrayUtl.To_str(src_ary));
BinaryHeap_Io_line_rdr heap = load_(usr_dlg, src_ary, comparer, key_gen, memory_max); if (heap.Len() == 0) return;//throw ErrUtl.NewArgs(ArrayUtl.To_str(src_ary));
Io_line_rdr stream = null;
cmd.Sort_bgn();
while (true) {
@@ -64,13 +71,13 @@ public class Io_sort {
cmd.Sort_end();
heap.Rls();
}
private static void Split_flush(Io_url url, List_adp list, int max, Bry_bfr tmp, List_adp url_list) {
private static void Split_flush(Io_url url, List_adp list, int max, BryWtr tmp, List_adp url_list) {
int len = list.Len();
for (int i = 0; i < len; i++) {
Io_sort_split_itm itm = (Io_sort_split_itm)list.Get_at(i);
Io_sort_split_itm itm = (Io_sort_split_itm)list.GetAt(i);
int add_len = itm.Row_end() - itm.Row_bgn();
if ((tmp.Len() + add_len) > Const_bfr_max) Io_mgr.Instance.AppendFilBfr(url, tmp);
tmp.Add_mid(itm.Bfr(), itm.Row_bgn(), itm.Row_end());
tmp.AddMid(itm.Bfr(), itm.Row_bgn(), itm.Row_end());
itm.Rls();
}
Io_mgr.Instance.AppendFilBfr(url, tmp);
@@ -92,6 +99,6 @@ public class Io_sort {
}
return rv;
}
static final int Const_bfr_max = Io_mgr.Len_mb;
static final int Const_bfr_max = IoConsts.LenMB;
static final String GRP_KEY = "xowa.bldr.io_sort";
}

View File

@@ -1,26 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.ios; import gplx.*; import gplx.core.*;
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.ios;
import gplx.libs.dlgs.Gfo_usr_dlg;
import gplx.libs.files.Io_mgr;
import gplx.types.custom.brys.wtrs.BryWtr;
import gplx.libs.files.Io_url;
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; BryWtr bfr = BryWtr.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();
if (bfr.Len() + (end - bgn) > flush_len) Flush();
bfr.Add_mid(rdr.Bfr(), bgn, end);
bfr.AddMid(rdr.Bfr(), bgn, end);
}
public void Sort_end() {
Flush();
@@ -29,7 +33,7 @@ public class Io_sort_fil_basic implements Io_sort_cmd { // 123|bgn|end|1
private void Flush() {
Io_url url = url_gen.Nxt_url();
usr_dlg.Prog_one(GRP_KEY, "make", "making: ~{0}", url.NameAndExt());
Io_mgr.Instance.SaveFilBry(url, bfr.Bfr(), bfr.Len());
Io_mgr.Instance.SaveFilBry(url, bfr.Bry(), bfr.Len());
bfr.Clear();
}
static final String GRP_KEY = "xowa.bldr.io_sort";

View File

@@ -13,7 +13,15 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.ios; import gplx.*;
package gplx.core.ios;
import gplx.libs.dlgs.Gfo_usr_dlg_;
import gplx.libs.files.Io_mgr;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.BryUtl;
import gplx.libs.files.Io_url;
import gplx.libs.files.Io_url_;
import gplx.types.basics.lists.List_adp;
import gplx.types.basics.lists.List_adp_;
import org.junit.*;
public class Io_sort_misc_tst {
@Before public void init() {
@@ -30,7 +38,7 @@ public class Io_sort_misc_tst {
String[] actl = actl_list.ToStrAry();
for (int i = 0; i < expd.length; i++)
expd[i] = dir_str + expd[i];
Tfds.Eq_ary_str(expd, actl);
GfoTstr.EqLines(expd, actl);
}
@Test public void Io_line_rdr_comparer_all() {
tst_Io_line_rdr_fld_comparer(-1, "a", "b");
@@ -40,8 +48,8 @@ public class Io_sort_misc_tst {
tst_Io_line_rdr_fld_comparer( 1, "ab", "a");
}
private void tst_Io_line_rdr_fld_comparer(int expd, String lhs_str, String rhs_str) {
byte[] lhs = Bry_.new_u8(lhs_str), rhs = Bry_.new_u8(rhs_str);
Tfds.Eq(expd, Bry_.Compare(lhs, 0, lhs.length, rhs, 0, rhs.length));
byte[] lhs = BryUtl.NewU8(lhs_str), rhs = BryUtl.NewU8(rhs_str);
GfoTstr.EqObj(expd, BryUtl.Compare(lhs, 0, lhs.length, rhs, 0, rhs.length));
}
Io_line_rdr new_Io_line_rdr(String url_str, String text) {
Io_url url = Io_url_.mem_fil_(url_str);

View File

@@ -13,12 +13,13 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.ios; import gplx.*;
import gplx.objects.lists.ComparerAble;
package gplx.core.ios;
import gplx.types.basics.utls.BryUtl;
import gplx.types.commons.lists.ComparerAble;
public class Io_sort_split_itm_sorter implements ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
Io_sort_split_itm lhs = (Io_sort_split_itm)lhsObj, rhs = (Io_sort_split_itm)rhsObj;
return Bry_.Compare(lhs.Bfr(), lhs.Key_bgn(), lhs.Key_end(), rhs.Bfr(), rhs.Key_bgn(), rhs.Key_end());
return BryUtl.Compare(lhs.Bfr(), lhs.Key_bgn(), lhs.Key_end(), rhs.Bfr(), rhs.Key_bgn(), rhs.Key_end());
}
public static final Io_sort_split_itm_sorter Instance = new Io_sort_split_itm_sorter(); Io_sort_split_itm_sorter() {} // TS.static
}

View File

@@ -13,8 +13,21 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.ios; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.strings.*;
package gplx.core.ios;
import gplx.libs.dlgs.Gfo_usr_dlg;
import gplx.libs.dlgs.Gfo_usr_dlg_;
import gplx.libs.files.Io_mgr;
import gplx.libs.ios.IoConsts;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.lists.List_adp;
import gplx.types.basics.lists.List_adp_;
import gplx.types.basics.utls.IntUtl;
import gplx.types.basics.utls.StringUtl;
import gplx.libs.files.Io_url;
import gplx.libs.files.Io_url_;
import gplx.types.commons.String_bldr;
import gplx.types.commons.String_bldr_;
import org.junit.*;
public class Io_sort_tst {
Io_sort_fxt fxt = new Io_sort_fxt();
@Test public void ExternalSort() {
@@ -23,7 +36,7 @@ public class Io_sort_tst {
}
}
class Io_sort_fxt {
Io_sort externalSort = new Io_sort().Memory_max_(Io_mgr.Len_kb);
Io_sort externalSort = new Io_sort().Memory_max_(IoConsts.LenKB);
String_bldr sb = String_bldr_.new_();
public Io_sort_fxt Clear() {Io_mgr.Instance.InitEngine_mem(); return this;}
public Io_sort_fxt Memory_max_(int v) {externalSort.Memory_max_(v); return this;}
@@ -39,26 +52,26 @@ class Io_sort_fxt {
Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Test();
Io_url_gen src_fil_gen = Io_url_gen_.fil_(src_url);
Io_url[] tmp_url_ary = externalSort.Split(usr_dlg, src_fil_gen, Io_url_gen_.dir_(src_url.OwnerDir()), Io_line_rdr_key_gen_.first_pipe);
Io_sort_fil_basic cmd = new Io_sort_fil_basic(usr_dlg, Io_url_gen_.fil_(trg_url), Io_mgr.Len_kb);
Io_sort_fil_basic cmd = new Io_sort_fil_basic(usr_dlg, Io_url_gen_.fil_(trg_url), IoConsts.LenKB);
externalSort.Merge(usr_dlg, tmp_url_ary, Io_sort_split_itm_sorter.Instance, Io_line_rdr_key_gen_.first_pipe, cmd);
String actl = Io_mgr.Instance.LoadFilStr(trg_url);
Tfds.Eq_ary_str(String_.SplitLines_nl(sorted), String_.SplitLines_nl(actl));
GfoTstr.EqLines(StringUtl.SplitLinesNl(sorted), StringUtl.SplitLinesNl(actl));
}
public String GenRandom(int rows, int pad) {
List_adp list = List_adp_.New();
for (int i = 0; i < rows; i++)
list.Add(Int_.To_str_pad_bgn_zero(i, pad) + "|");
list.Add(IntUtl.ToStrPadBgnZero(i, pad) + "|");
list.Shuffle();
for (int i = 0; i < rows; i++) {
String itm = (String)list.Get_at(i);
sb.Add(itm).Add_char_nl();
String itm = (String)list.GetAt(i);
sb.Add(itm).AddCharNl();
}
return sb.To_str_and_clear();
return sb.ToStrAndClear();
}
public String GenOrdered(int rows, int pad) {
for (int i = 0; i < rows; i++)
sb.Add(Int_.To_str_pad_bgn_zero(i, pad) + "|" + "\n");
return sb.To_str_and_clear();
sb.Add(IntUtl.ToStrPadBgnZero(i, pad) + "|" + "\n");
return sb.ToStrAndClear();
}
}

View File

@@ -1,21 +1,24 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.ios; import gplx.*; import gplx.core.*;
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.ios;
import java.io.InputStream;
import gplx.core.ios.streams.*;
import gplx.types.errs.ErrUtl;
import gplx.types.basics.utls.StringUtl;
import gplx.libs.files.Io_url;
public class Io_stream_rdr_process implements Io_stream_rdr {
private Process process;
private InputStream stream_read;
@@ -31,13 +34,13 @@ public class Io_stream_rdr_process implements Io_stream_rdr {
pb.redirectErrorStream(false);
try {process = pb.start();}
catch (Exception e) {
throw Err_.new_exc(e, "core", "process init failed", "args", String_.AryXtoStr(process_args));
throw ErrUtl.NewArgs(e, "process init failed", "args", StringUtl.AryToStr(process_args));
}
stream_read = process.getInputStream();
return this;
}
public void Open_mem(byte[] v) {throw Err_.new_unimplemented();}
public Object Under() {throw Err_.new_unimplemented();}
public void Open_mem(byte[] v) {throw ErrUtl.NewUnimplemented();}
public Object Under() {throw ErrUtl.NewUnimplemented();}
public int Read(byte[] bry, int bgn, int len) {
try {
@@ -53,15 +56,15 @@ public class Io_stream_rdr_process implements Io_stream_rdr {
if (rv >= len) break;
}
return rv;
} catch (Exception e) {throw Err_.new_exc(e, "io", "process read failed", "bgn", bgn, "len", len);}
} catch (Exception e) {throw ErrUtl.NewArgs(e, "process read failed", "bgn", bgn, "len", len);}
}
public long Skip(long len) {
try {return stream_read.skip(len);}
catch (Exception e) {throw Err_.new_exc(e, "io", "process skip failed", "len", len);}
catch (Exception e) {throw ErrUtl.NewArgs(e, "process skip failed", "len", len);}
}
public void Rls() {
try {stream_read.close();}
catch (Exception e) {throw Err_.new_exc(e, "io", "process rls failed");}
catch (Exception e) {throw ErrUtl.NewArgs(e, "process rls failed");}
process.destroy();
}
public static Io_stream_rdr_process new_(Io_url process_exe, Io_url stream_url, String... process_args) {return new Io_stream_rdr_process(process_exe, stream_url, process_args);}

View File

@@ -1,20 +1,26 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.ios; import gplx.*; import gplx.core.*;
import gplx.core.ios.streams.*;
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.ios;
import gplx.core.ios.streams.Io_stream_rdr;
import gplx.core.ios.streams.Io_stream_rdr_;
import gplx.core.ios.streams.Io_stream_tid_;
import gplx.core.ios.streams.Io_stream_wtr;
import gplx.core.ios.streams.Io_stream_wtr_;
import gplx.types.custom.brys.wtrs.BryWtr;
import gplx.types.errs.ErrUtl;
public class Io_stream_zip_mgr {
private Io_stream_wtr wtr__gzip, wtr__zip, wtr__bzip2, wtr__xz;
public byte[] Zip(byte type, byte[] val) {
@@ -28,17 +34,17 @@ public class Io_stream_zip_mgr {
if (type == Io_stream_tid_.Tid__raw) return val;
Io_stream_rdr rdr = Rdr(type);
rdr.Open_mem(val);
return Io_stream_rdr_.Load_all_as_bry(Bry_bfr_.New(), rdr);
return Io_stream_rdr_.Load_all_as_bry(BryWtr.New(), rdr);
}
private Io_stream_wtr Wtr(byte type) {
Bry_bfr bfr = Bry_bfr_.New();
BryWtr bfr = BryWtr.New();
switch (type) {
case Io_stream_tid_.Tid__gzip: if (wtr__gzip == null) wtr__gzip = Io_stream_wtr_.New_by_mem(bfr, Io_stream_tid_.Tid__gzip); return wtr__gzip.Open();
case Io_stream_tid_.Tid__zip: if (wtr__zip == null) wtr__zip = Io_stream_wtr_.New_by_mem(bfr, Io_stream_tid_.Tid__zip); return wtr__zip.Open();
case Io_stream_tid_.Tid__bzip2: if (wtr__bzip2 == null) wtr__bzip2 = Io_stream_wtr_.New_by_mem(bfr, Io_stream_tid_.Tid__bzip2); return wtr__bzip2.Open();
case Io_stream_tid_.Tid__xz: if (wtr__xz == null) wtr__xz = Io_stream_wtr_.New_by_mem(bfr, Io_stream_tid_.Tid__xz); return wtr__xz.Open();
case Io_stream_tid_.Tid__raw:
default: throw Err_.new_unhandled(type);
default: throw ErrUtl.NewUnhandled(type);
}
}
private Io_stream_rdr Rdr(byte type) { // TS.MEM: DATE:2016-07-12
@@ -48,7 +54,7 @@ public class Io_stream_zip_mgr {
case Io_stream_tid_.Tid__bzip2: return Io_stream_rdr_.New_by_tid(Io_stream_tid_.Tid__bzip2);
case Io_stream_tid_.Tid__xz: return Io_stream_rdr_.New_by_tid(Io_stream_tid_.Tid__xz);
case Io_stream_tid_.Tid__raw:
default: throw Err_.new_unhandled(type);
default: throw ErrUtl.NewUnhandled(type);
}
}
}

View File

@@ -13,10 +13,11 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.ios; import gplx.*; import gplx.core.*;
package gplx.core.ios;
import gplx.libs.files.Io_url;
public interface Io_url_gen {
Io_url Cur_url();
Io_url Nxt_url();
Io_url[] Prv_urls();
void Del_all();
}
Io_url Cur_url();
Io_url Nxt_url();
Io_url[] Prv_urls();
void Del_all();
}

View File

@@ -1,40 +1,44 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.ios; import gplx.*; import gplx.core.*;
public class Io_url_gen_ {
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.ios;
import gplx.libs.files.Io_mgr;
import gplx.types.basics.utls.IntUtl;
import gplx.types.basics.utls.StringUtl;
import gplx.libs.files.Io_url;
public class Io_url_gen_ {
public static Io_url_gen dir_(Io_url v) {return new Io_url_gen_dir(v);}
public static Io_url_gen dir_(Io_url v, String fmt, int digits) {return new Io_url_gen_dir(v).Fmt_(fmt).Fmt_digits_(digits);}
public static Io_url_gen fil_(Io_url v) {return new Io_url_gen_fil(v);}
}
class Io_url_gen_dir implements Io_url_gen {
class Io_url_gen_dir implements Io_url_gen {
public String Fmt() {return fmt;} public Io_url_gen_dir Fmt_(String v) {fmt = v; return this;} private String fmt = "{0}.csv";
public int Fmt_digits() {return fmt_digits;} public Io_url_gen_dir Fmt_digits_(int v) {fmt_digits = v; return this;} private int fmt_digits = 10;
public Io_url Cur_url() {return cur_url;} Io_url cur_url;
public Io_url Nxt_url() {cur_url = dir.GenSubFil(String_.Format(fmt, Int_.To_str_pad_bgn_zero(idx++, fmt_digits))); return cur_url;} private int idx = 0;
public Io_url Nxt_url() {cur_url = dir.GenSubFil(StringUtl.Format(fmt, IntUtl.ToStrPadBgnZero(idx++, fmt_digits))); return cur_url;} private int idx = 0;
public Io_url[] Prv_urls() {
Io_url[] rv = new Io_url[idx];
for (int i = 0; i < idx; i++) {
rv[i] = dir.GenSubFil(String_.Format(fmt, Int_.To_str_pad_bgn_zero(i, fmt_digits)));
rv[i] = dir.GenSubFil(StringUtl.Format(fmt, IntUtl.ToStrPadBgnZero(i, fmt_digits)));
}
return rv;
}
public void Del_all() {if (Io_mgr.Instance.ExistsDir(dir)) Io_mgr.Instance.DeleteDirDeep(dir);}
public Io_url_gen_dir(Io_url dir) {this.dir = dir;} Io_url dir;
}
class Io_url_gen_fil implements Io_url_gen {
class Io_url_gen_fil implements Io_url_gen {
public Io_url Cur_url() {return cur_url;} Io_url cur_url;
public Io_url Nxt_url() {return cur_url;}
public Io_url[] Prv_urls() {return new Io_url[]{cur_url};}

View File

@@ -13,10 +13,11 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.lists; import gplx.*;
import gplx.objects.lists.CompareAbleUtl;
import gplx.objects.lists.ComparerAble;
import gplx.objects.lists.ComparerAbleUtl;
package gplx.core.lists;
import gplx.types.errs.ErrUtl;
import gplx.types.commons.lists.CompareAbleUtl;
import gplx.types.commons.lists.ComparerAble;
import gplx.types.commons.lists.ComparerAbleUtl;
public class Binary_heap {
private final ComparerAble comparer;
private boolean is_max;
@@ -29,7 +30,7 @@ public class Binary_heap {
this.size = 0;
}
public Object Get() {
if (size == 0) throw Err_.new_wo_type("heap is empty");
if (size == 0) throw ErrUtl.NewArgs("heap is empty");
return heap[0];
}
public void Add(Object val) {
@@ -45,7 +46,7 @@ public class Binary_heap {
}
public Object Pop() {return Pop(0);}
public Object Pop(int idx) {
if (size == 0) throw Err_.new_wo_type("heap is empty");
if (size == 0) throw ErrUtl.NewArgs("heap is empty");
Object val = heap[idx];
heap[idx] = heap[size -1];
size--;

View File

@@ -14,11 +14,11 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.lists;
import gplx.core.primitives.Int_obj_val;
import gplx.types.basics.wrappers.IntVal;
import gplx.core.tests.Gftest;
import gplx.objects.lists.CompareAbleUtl;
import gplx.objects.lists.ComparerAble;
import gplx.objects.primitives.BoolUtl;
import gplx.types.commons.lists.CompareAbleUtl;
import gplx.types.commons.lists.ComparerAble;
import gplx.types.basics.utls.BoolUtl;
import org.junit.Test;
public class Binary_heap_tst {
private final Binary_heap_fxt fxt = new Binary_heap_fxt();
@@ -43,13 +43,13 @@ class Binary_heap_fxt implements ComparerAble {
}
public void Exec__add(int... ary) {
for (int i : ary)
heap.Add(new Int_obj_val(i));
heap.Add(new IntVal(i));
}
public void Test__pop(int... expd) {
int len = expd.length;
int[] actl = new int[len];
for (int i = 0; i < len; i++)
actl[i] = ((Int_obj_val)heap.Pop()).Val();
Gftest.Eq__ary(expd, actl, "heaps don't match");
actl[i] = ((IntVal)heap.Pop()).Val();
Gftest.EqAry(expd, actl, "heaps don't match");
}
}

View File

@@ -13,11 +13,14 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.lists; import gplx.*;
import gplx.core.primitives.*;
package gplx.core.lists;
import gplx.types.basics.utls.BryUtl;
import gplx.types.basics.lists.Ordered_hash;
import gplx.types.basics.lists.Ordered_hash_;
import gplx.types.basics.wrappers.IntRef;
public class HashByInt {
private final Ordered_hash hash = Ordered_hash_.New();
private final Int_obj_ref tmp_key = Int_obj_ref.New_neg1();
private final IntRef tmp_key = IntRef.NewNeg1();
public void Clear() {
hash.Clear();
}
@@ -25,25 +28,25 @@ public class HashByInt {
return hash.Len();
}
public Object Get_at_or_null(int idx) {
HashByIntItem item = (HashByIntItem)hash.Get_at(idx);
HashByIntItem item = (HashByIntItem)hash.GetAt(idx);
return item.val;
}
public Object Get_by_or_fail(int key) {
synchronized (tmp_key) {
HashByIntItem item = (HashByIntItem)hash.GetByOrFail(tmp_key.Val_(key));
HashByIntItem item = (HashByIntItem)hash.GetByOrFail(tmp_key.ValSet(key));
return item.val;
}
}
public Object Get_by_or_null(int key) {
synchronized (tmp_key) {
HashByIntItem item = (HashByIntItem)hash.GetByOrNull(tmp_key.Val_(key));
HashByIntItem item = (HashByIntItem)hash.GetByOrNull(tmp_key.ValSet(key));
return item == null ? null : item.val;
}
}
public HashByInt Add_as_bry(int key, String val) {return Add(key, Bry_.new_u8(val));}
public HashByInt Add_as_bry(int key, String val) {return Add(key, BryUtl.NewU8(val));}
public HashByInt Add(int key, Object val) {
HashByIntItem item = new HashByIntItem(key, val);
hash.Add(Int_obj_ref.New(key), item);
hash.Add(IntRef.New(key), item);
return this;
}
public HashByInt Clone() {
@@ -51,7 +54,7 @@ public class HashByInt {
int len = hash.Len();
for (int i = 0; i < len; i++) {
HashByIntItem item = (HashByIntItem)hash.Get_at(i);
HashByIntItem item = (HashByIntItem)hash.GetAt(i);
rv.Add(item.key, item.val);
}
return rv;

View File

@@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.lists; import gplx.*; import gplx.core.*;
package gplx.core.lists;
import gplx.types.errs.ErrUtl;
public class Queue_adp {
private int count;
private Queue_itm head;
@@ -38,7 +39,7 @@ public class Queue_adp {
return rv;
}
public Object Peek() {
if (head == null) throw Err_.new_wo_type("queue is empty");
if (head == null) throw ErrUtl.NewArgs("queue is empty");
Queue_itm rv = head;
return rv.Data();
}

View File

@@ -13,8 +13,10 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.lists; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.tests.*;
package gplx.core.lists;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.errs.ErrUtl;
import org.junit.Test;
public class Queue_adp_tst {
private final Queue_adp_fxt fxt = new Queue_adp_fxt();
@Test public void Empty() {
@@ -23,10 +25,9 @@ public class Queue_adp_tst {
fxt.Test__dequeue(null, -1);
pass = false;
} catch (Exception e) {
Err_.Noop(e);
return;
}
if (pass) throw Err_.new_wo_type("empty should have failed");
if (pass) throw ErrUtl.NewArgs("empty should have failed");
}
@Test public void Add_1() {
fxt.Exec__enqueue("a");
@@ -53,7 +54,7 @@ class Queue_adp_fxt {
private final Queue_adp queue = new Queue_adp();
public void Exec__enqueue(String s) {queue.Enqueue(s);}
public void Test__dequeue(String expd_data, int expd_len) {
Gftest.Eq__str(expd_data, (String)queue.Dequeue());
Gftest.Eq__int(expd_len , queue.Count());
GfoTstr.Eq(expd_data, (String)queue.Dequeue());
GfoTstr.Eq(expd_len , queue.Count());
}
}

View File

@@ -13,8 +13,10 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.lists; import gplx.*;
import gplx.objects.lists.CompareAbleUtl;
package gplx.core.lists;
import gplx.types.commons.lists.CompareAbleUtl;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.IntUtl;
class StatRng_fxt { // UNUSED:useful for stat processing
StatRng rng;
public StatRng_fxt ini_(int lo_ary_len, int hi_ary_len, int... slot_hi_ary) {
@@ -26,13 +28,13 @@ class StatRng_fxt { // UNUSED:useful for stat processing
int val = vals[i];
rng.Assign(val, val);
}
Tfds.Eq(expd_count, rng.Count, "Count");
Tfds.Eq(expd_lo, rng.Lo, "Lo");
Tfds.Eq(expd_hi, rng.Hi, "Hi");
Tfds.Eq_float(expd_avg, rng.Avg());
Tfds.Eq_ary(expd_lo_ary, XtoIntAry(rng.Lo_ary), "Lo_ary");
Tfds.Eq_ary(expd_hi_ary, XtoIntAry(rng.Hi_ary), "Hi_ary");
Tfds.Eq_ary(expd_slots, XtoIntAry(rng.Slot_ary), "Slots");
GfoTstr.EqObj(expd_count, rng.Count, "Count");
GfoTstr.EqObj(expd_lo, rng.Lo, "Lo");
GfoTstr.EqObj(expd_hi, rng.Hi, "Hi");
GfoTstr.EqFloat(expd_avg, rng.Avg());
GfoTstr.EqAry(expd_lo_ary, XtoIntAry(rng.Lo_ary), "Lo_ary");
GfoTstr.EqAry(expd_hi_ary, XtoIntAry(rng.Hi_ary), "Hi_ary");
GfoTstr.EqAry(expd_slots, XtoIntAry(rng.Slot_ary), "Slots");
return this;
}
int[] XtoIntAry(StatItm[] ary) {
@@ -57,8 +59,8 @@ class StatRng_fxt { // UNUSED:useful for stat processing
}
class StatRng {
// public String Key;
public int Lo = Int_.Max_value;
public int Hi = Int_.Min_value;
public int Lo = IntUtl.MaxValue;
public int Hi = IntUtl.MinValue;
public long Sum = 0;
public int Count = 0;
public float Avg() {return Sum / Count;}
@@ -72,21 +74,21 @@ class StatRng {
public int Slot_ary_len;
public StatRng(int lo_ary_len, int hi_ary_len, int... slot_hi_ary) {
this.Lo_ary_len = lo_ary_len;
this.Lo_ary_bound = Int_.Max_value;
this.Lo_ary = NewBoundAry(lo_ary_len, Int_.Max_value);
this.Lo_ary_bound = IntUtl.MaxValue;
this.Lo_ary = NewBoundAry(lo_ary_len, IntUtl.MaxValue);
this.Hi_ary_len = hi_ary_len;
this.Hi_ary_bound = Int_.Min_value;
this.Hi_ary = NewBoundAry(hi_ary_len, Int_.Min_value);
this.Hi_ary_bound = IntUtl.MinValue;
this.Hi_ary = NewBoundAry(hi_ary_len, IntUtl.MinValue);
if (slot_hi_ary != null && slot_hi_ary.length > 0) {
Slot_ary_len = slot_hi_ary.length + 1; // + 1 to hold max value
Slot_ary = new StatRng[Slot_ary_len];
int slot_lo = Int_.Min_value;
int slot_lo = IntUtl.MinValue;
for (int i = 0; i < Slot_ary_len - 1; i++) {
int slot_hi = slot_hi_ary[i];
Slot_ary[i] = NewSlot(slot_lo, slot_hi);
slot_lo = slot_hi;
}
Slot_ary[Slot_ary_len - 1] = NewSlot(slot_lo, Int_.Max_value);
Slot_ary[Slot_ary_len - 1] = NewSlot(slot_lo, IntUtl.MaxValue);
}
}
public void Assign(Object key, int val) {
@@ -103,21 +105,21 @@ class StatRng {
}
}
if (val < Lo_ary_bound) {
Lo_ary_bound = CalcCutoff(Lo_ary, CompareAbleUtl.More, Int_.Min_value, key, val);
Lo_ary_bound = CalcCutoff(Lo_ary, CompareAbleUtl.More, IntUtl.MinValue, key, val);
}
if (val > Hi_ary_bound) {
Hi_ary_bound = CalcCutoff(Hi_ary, CompareAbleUtl.Less, Int_.Max_value, key, val);
Hi_ary_bound = CalcCutoff(Hi_ary, CompareAbleUtl.Less, IntUtl.MaxValue, key, val);
}
}
int CalcCutoff(StatItm[] ary, int comp, int bgn_bound, Object key, int val) {
int new_bound = bgn_bound;
for (int i = 0; i < ary.length; i++) {
StatItm itm = ary[i];
if (Int_.Compare(itm.Val, val) == comp) {
if (IntUtl.Compare(itm.Val, val) == comp) {
itm = new StatItm(key, val);
ary[i] = itm;
}
if (Int_.Compare(itm.Val, new_bound) == comp) new_bound = itm.Val;
if (IntUtl.Compare(itm.Val, new_bound) == comp) new_bound = itm.Val;
}
return new_bound;
}

View File

@@ -13,16 +13,18 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.lists.binary_searches; import gplx.*;
import gplx.objects.lists.CompareAble;
import gplx.objects.lists.CompareAbleUtl;
package gplx.core.lists.binary_searches;
import gplx.types.custom.brys.BryFind;
import gplx.types.commons.lists.CompareAble;
import gplx.types.commons.lists.CompareAbleUtl;
import gplx.types.basics.lists.List_adp_;
public class Binary_search_ {
public static int Search(CompareAble[] ary , CompareAble val) {return Search(new Binary_search_grp__ary(ary) , new Binary_search_cmp__comparable(val));}
public static int Search(Object[] ary , Binary_comparer comparer, Object val) {return Search(new Binary_search_grp__ary(ary), new Binary_search_cmp__comparer(comparer, val));}
private static int Search(Binary_search_grp grp, Binary_search_cmp cmp) {
int grp_len = grp.Len();
if (grp_len == 1) return 0; // if 1 item, return 0;
if (grp_len == 0) return Bry_find_.Not_found; // if 0 item, return -1
if (grp_len == 0) return BryFind.NotFound; // if 0 item, return -1
// init
int interval = grp_len / 2;
@@ -58,6 +60,6 @@ public class Binary_search_ {
else if (pos > pos_last) pos = pos_last;
pos_prv = pos;
}
return Bry_find_.Not_found; // should only occur if (a) ary's 0th slot is not ""; or (b) some unknown error
return BryFind.NotFound; // should only occur if (a) ary's 0th slot is not ""; or (b) some unknown error
}
}

View File

@@ -13,8 +13,11 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.lists.binary_searches; import gplx.*; import gplx.core.*; import gplx.core.lists.*;
import org.junit.*; import gplx.core.primitives.*;
package gplx.core.lists.binary_searches;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.IntUtl;
import gplx.types.basics.wrappers.StringVal;
import org.junit.*;
public class Binary_search__tst {
private final Binary_search__fxt fxt = new Binary_search__fxt();
@Test public void Basic() {
@@ -33,21 +36,21 @@ public class Binary_search__tst {
@Test public void Catpage() {
String[] ary = new String[25];
for (int i = 0; i < 25; ++i)
ary[i] = Int_.To_str_pad_bgn_zero(i, 2);
ary[i] = IntUtl.ToStrPadBgnZero(i, 2);
fxt.Init__ary(ary);
fxt.Test__binary_search("10", 10); // was 9
}
}
class Binary_search__fxt {
private String_obj_val[] ary;
private StringVal[] ary;
public void Init__ary(String... v) {
int ary_len = v.length;
ary = new String_obj_val[ary_len];
ary = new StringVal[ary_len];
for (int i = 0; i < ary_len; i++)
ary[i] = String_obj_val.new_(v[i]);
ary[i] = StringVal.New(v[i]);
}
public void Test__binary_search(String val, int expd) {
int actl = Binary_search_.Search(ary, String_obj_val.new_(val));
Tfds.Eq(expd, actl, val);
int actl = Binary_search_.Search(ary, StringVal.New(val));
GfoTstr.EqObj(expd, actl, val);
}
}

View File

@@ -14,7 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.lists.binary_searches;
import gplx.objects.lists.CompareAble;
import gplx.types.commons.lists.CompareAble;
interface Binary_search_cmp {
int Compare(Object comp);
}

View File

@@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.lists.binary_searches; import gplx.*; import gplx.core.*; import gplx.core.lists.*;
package gplx.core.lists.binary_searches;
import gplx.types.basics.lists.List_adp;
interface Binary_search_grp {
int Len();
Object Get_at(int i);
@@ -28,5 +29,5 @@ class Binary_search_grp__list implements Binary_search_grp {
private final List_adp list;
public Binary_search_grp__list(List_adp list) {this.list = list;}
public int Len() {return list.Len();}
public Object Get_at(int i) {return list.Get_at(i);}
public Object Get_at(int i) {return list.GetAt(i);}
}

View File

@@ -13,9 +13,10 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.lists.caches; import gplx.*;
import gplx.objects.lists.CompareAbleUtl;
import gplx.objects.lists.ComparerAble;
package gplx.core.lists.caches;
import gplx.types.commons.lists.CompareAbleUtl;
import gplx.types.commons.lists.ComparerAble;
import gplx.types.basics.utls.LongUtl;
class Mru_cache_itm {
private final long time_bgn;
private long time_dirty;
@@ -65,7 +66,7 @@ class Mru_cache_itm_comparer implements ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
Mru_cache_itm lhs = (Mru_cache_itm)lhsObj;
Mru_cache_itm rhs = (Mru_cache_itm)rhsObj;
int rv = Long_.Compare(Score(lhs), Score(rhs));
int rv = LongUtl.Compare(Score(lhs), Score(rhs));
return rv == 0
? CompareAbleUtl.Compare_obj(lhs.Key(), rhs.Key())
: rv;

View File

@@ -14,24 +14,25 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.lists.caches;
import gplx.Bry_bfr;
import gplx.Bry_bfr_;
import gplx.Datetime_now;
import gplx.Hash_adp;
import gplx.Hash_adp_;
import gplx.Io_mgr;
import gplx.Object_;
import gplx.Ordered_hash;
import gplx.Ordered_hash_;
import gplx.core.envs.SystemUtl;
import gplx.libs.ios.IoConsts;
import gplx.types.custom.brys.wtrs.BryWtr;
import gplx.types.commons.GfoDateNow;
import gplx.types.basics.lists.Hash_adp;
import gplx.types.basics.lists.Hash_adp_;
import gplx.libs.files.Io_mgr;
import gplx.types.basics.utls.ObjectUtl;
import gplx.types.basics.lists.Ordered_hash;
import gplx.types.basics.lists.Ordered_hash_;
import gplx.core.lists.Sorted_hash;
import gplx.core.logs.Gfo_log_wtr;
import gplx.objects.primitives.BoolUtl;
import gplx.types.basics.utls.BoolUtl;
public class Mru_cache_mgr {
private final Mru_cache_time_mgr time_mgr;
private final Gfo_log_wtr log_wtr;
private final Hash_adp key_hash = Hash_adp_.New();
private final Sorted_hash val_hash;
private final Bry_bfr log_bfr = Bry_bfr_.New_w_size(255);
private final BryWtr log_bfr = BryWtr.NewWithSize(255);
private final Mru_cache_itm_comparer comparer;
private final Ordered_hash dirty = Ordered_hash_.New();
private long cache_max, cache_size, compress_size;
@@ -64,7 +65,7 @@ public class Mru_cache_mgr {
public void Compress(long val_size) {
int dirty_len = dirty.Len();
for (int i = 0; i < dirty_len; i++) {
Mru_cache_itm dirty_itm = (Mru_cache_itm)dirty.Get_at(i);
Mru_cache_itm dirty_itm = (Mru_cache_itm)dirty.GetAt(i);
val_hash.Del(dirty_itm);
dirty_itm.Update();
val_hash.Add(dirty_itm, dirty_itm);
@@ -94,13 +95,13 @@ public class Mru_cache_mgr {
}
private void Write(boolean write_time, Mru_cache_itm itm) {
// 20180625_112443.506|Q2|123uses|10ms|1234bytes\n
if (write_time) log_bfr.Add_dte_under(Datetime_now.Get_force()).Add_byte_pipe();
log_bfr.Add_str_u8(Object_.Xto_str_strict_or_null_mark(itm.Key()));
log_bfr.Add_byte_pipe().Add_long_fixed(comparer.Score(itm), 10);
log_bfr.Add_byte_pipe().Add_long_variable(itm.Size());
log_bfr.Add_byte_pipe().Add_long_variable(itm.Time_dif());
log_bfr.Add_byte_pipe().Add_long_variable(itm.Used());
log_bfr.Add_byte_nl();
if (write_time) log_bfr.AddDateUnderline(GfoDateNow.GetForce()).AddBytePipe();
log_bfr.AddStrU8(ObjectUtl.ToStrOrNullMark(itm.Key()));
log_bfr.AddBytePipe().AddLongFixed(comparer.Score(itm), 10);
log_bfr.AddBytePipe().AddLongVariable(itm.Size());
log_bfr.AddBytePipe().AddLongVariable(itm.Time_dif());
log_bfr.AddBytePipe().AddLongVariable(itm.Used());
log_bfr.AddByteNl();
}
public void Clear() {
key_hash.Clear();
@@ -110,10 +111,10 @@ public class Mru_cache_mgr {
cache_size = 0;
}
public static Mru_cache_mgr New_by_mb_secs(Gfo_log_wtr log_wtr, long cache_max_in_mb, long compress_size, long used_weight_in_secs) {
return new Mru_cache_mgr(new Mru_cache_time_mgr__clock(), log_wtr, Io_mgr.Len_mb * cache_max_in_mb, Io_mgr.Len_mb * compress_size, gplx.core.envs.System_.Ticks__per_second * used_weight_in_secs);
return new Mru_cache_mgr(new Mru_cache_time_mgr__clock(), log_wtr, IoConsts.LenMB * cache_max_in_mb, IoConsts.LenMB * compress_size, SystemUtl.Ticks__per_second * used_weight_in_secs);
}
// TEST
public Object[] Values_array() {return val_hash.Values_array();}
@gplx.Internal protected static Mru_cache_mgr New_test(Mru_cache_time_mgr time_mgr, Gfo_log_wtr log_wtr, long cache_max, long compress_size, long used_weight) {return new Mru_cache_mgr(time_mgr, log_wtr, cache_max, compress_size, used_weight);}
public static Mru_cache_mgr New_test(Mru_cache_time_mgr time_mgr, Gfo_log_wtr log_wtr, long cache_max, long compress_size, long used_weight) {return new Mru_cache_mgr(time_mgr, log_wtr, cache_max, compress_size, used_weight);}
}

View File

@@ -13,8 +13,10 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.lists.caches; import gplx.*; import gplx.core.*; import gplx.core.lists.*;
import org.junit.*; import gplx.core.tests.*;
package gplx.core.lists.caches;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.ObjectUtl;
import org.junit.*;
public class Mru_cache_mgr_tst {
private final Mru_cache_mgr_fxt fxt = new Mru_cache_mgr_fxt();
@Before public void init() {
@@ -78,9 +80,9 @@ class Mru_cache_mgr_fxt {
int actl_len = actl_objs.length;
String[] actl = new String[actl_len];
for (int i = 0; i < actl_len; i++) {
actl[i] = Object_.Xto_str_strict_or_null(((Mru_cache_itm)actl_objs[i]).Val());
actl[i] = ObjectUtl.ToStrOrNull(((Mru_cache_itm)actl_objs[i]).Val());
}
Gftest.Eq__ary(expd, actl);
GfoTstr.EqLines(expd, actl);
}
}
class Mru_cache_time_mgr__mock implements Mru_cache_time_mgr {

View File

@@ -13,10 +13,11 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.lists.caches; import gplx.*; import gplx.core.*; import gplx.core.lists.*;
interface Mru_cache_time_mgr {
long Now();
}
class Mru_cache_time_mgr__clock implements Mru_cache_time_mgr {
public long Now() {return gplx.core.envs.System_.Ticks();}
}
package gplx.core.lists.caches;
import gplx.core.envs.SystemUtl;
interface Mru_cache_time_mgr {
long Now();
}
class Mru_cache_time_mgr__clock implements Mru_cache_time_mgr {
public long Now() {return SystemUtl.Ticks();}
}

View File

@@ -13,9 +13,16 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.logs; import gplx.*; import gplx.core.*;
package gplx.core.logs;
import gplx.libs.dlgs.Gfo_usr_dlg_;
import gplx.libs.files.Io_mgr;
import gplx.libs.ios.IoConsts;
import gplx.types.custom.brys.wtrs.BryWtr;
import gplx.types.basics.utls.IntUtl;
import gplx.types.basics.utls.StringUtl;
import gplx.libs.files.Io_url;
public class Gfo_log_wtr {
private final Bry_bfr bfr = Bry_bfr_.New();
private final BryWtr bfr = BryWtr.New();
private final int bfr_max;
private final int fil_max;
private final Io_url fil_dir;
@@ -31,16 +38,16 @@ public class Gfo_log_wtr {
this.fil_idx_places = fil_idx_places;
}
public Io_url Fil_dir() {return fil_dir;}
public void Write(Bry_bfr add) {
public void Write(BryWtr add) {
int add_len = add.Len();
if (bfr.Len() + add_len > bfr_max)
Flush();
bfr.Add_bfr_and_clear(add);
bfr.AddBfrAndClear(add);
}
public void Flush() {
if (fil_idx == -1 || bfr.Len() + fil_len > fil_max) {
fil_idx++;
fil_url = fil_dir.GenSubFil(String_.Format(fil_fmt, Int_.To_str_pad_bgn_zero(fil_idx, fil_idx_places)));
fil_url = fil_dir.GenSubFil(StringUtl.Format(fil_fmt, IntUtl.ToStrPadBgnZero(fil_idx, fil_idx_places)));
fil_len = 0;
}
fil_len += bfr.Len();
@@ -49,6 +56,6 @@ public class Gfo_log_wtr {
}
public static Gfo_log_wtr New_dflt(String sub_dir, String file_fmt) {
return new Gfo_log_wtr(Io_mgr.Len_mb, 10 * Io_mgr.Len_mb, Gfo_usr_dlg_.Instance.Log_wkr().Session_dir().GenSubDir(sub_dir), file_fmt, 4);
return new Gfo_log_wtr(IoConsts.LenMB, 10 * IoConsts.LenMB, Gfo_usr_dlg_.Instance.Log_wkr().Session_dir().GenSubDir(sub_dir), file_fmt, 4);
}
}

View File

@@ -13,7 +13,11 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net; import gplx.*;
package gplx.core.net;
import gplx.types.basics.lists.Hash_adp;
import gplx.types.basics.lists.Hash_adp_;
import gplx.types.basics.lists.List_adp;
import gplx.types.basics.lists.List_adp_;
public class Gfo_inet_conn_ {
public static final int Tid__http = 1, Tid__mem__hash = 2, Tid__mem__pile = 3;
public static Gfo_inet_conn new_http() {return new Gfo_inet_conn__http();}
@@ -41,5 +45,5 @@ class Gfo_inet_conn__mem__pile implements Gfo_inet_conn {
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);}
public byte[] Download_as_bytes_or_null(String url) {return (byte[])List_adp_.Pop_last(pile);}
public byte[] Download_as_bytes_or_null(String url) {return (byte[])List_adp_.PopLast(pile);}
}

View File

@@ -13,15 +13,17 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net; import gplx.*; import gplx.core.*;
import gplx.core.ios.*;
class Gfo_inet_conn__http implements Gfo_inet_conn {
private final IoEngine_xrg_downloadFil downloader = IoEngine_xrg_downloadFil.new_("", Io_url_.Empty);
public int Tid() {return Gfo_inet_conn_.Tid__http;}
public void Clear() {throw Err_.new_unsupported();}
public void Upload_by_bytes(String url, byte[] data) {throw Err_.new_unsupported();}
public byte[] Download_as_bytes_or_null(String url) {
try {return downloader.Exec_as_bry(url);}
catch (Exception e) {Err_.Noop(e); return null;}
}
}
package gplx.core.net;
import gplx.core.ios.*;
import gplx.libs.files.Io_url_;
import gplx.types.errs.ErrUtl;
class Gfo_inet_conn__http implements Gfo_inet_conn {
private final IoEngine_xrg_downloadFil downloader = IoEngine_xrg_downloadFil.new_("", Io_url_.Empty);
public int Tid() {return Gfo_inet_conn_.Tid__http;}
public void Clear() {throw ErrUtl.NewUnsupported();}
public void Upload_by_bytes(String url, byte[] data) {throw ErrUtl.NewUnsupported();}
public byte[] Download_as_bytes_or_null(String url) {
try {return downloader.Exec_as_bry(url);}
catch (Exception e) {return null;}
}
}

View File

@@ -13,21 +13,26 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net; import gplx.*;
import gplx.objects.strings.AsciiByte;
package gplx.core.net;
import gplx.types.basics.utls.BryLni;
import gplx.types.basics.utls.BryUtl;
import gplx.types.basics.constants.AsciiByte;
import gplx.types.basics.lists.Ordered_hash;
import gplx.types.basics.lists.Ordered_hash_;
import gplx.types.basics.utls.StringUtl;
public class Gfo_protocol_itm {
public Gfo_protocol_itm(byte tid, String text) {
this.tid = tid;
this.text_bry = Bry_.new_u8(text);
this.text_bry = BryUtl.NewU8(text);
this.text_str = text;
int text_len = text_bry.length;
for (int i = 0; i < text_len; i++) {
if (text_bry[i] == AsciiByte.Colon) {
this.key_wo_colon_bry = Bry_.Mid(text_bry, 0, i);
this.key_wo_colon_bry = BryLni.Mid(text_bry, 0, i);
this.key_w_colon_bry_len = i;
this.key_wo_colon_str = String_.new_u8(key_wo_colon_bry);
this.key_w_colon_bry = Bry_.Mid(text_bry, 0, i + 1);
this.key_w_colon_str = String_.new_u8(key_w_colon_bry);
this.key_wo_colon_str = StringUtl.NewU8(key_wo_colon_bry);
this.key_w_colon_bry = BryLni.Mid(text_bry, 0, i + 1);
this.key_w_colon_str = StringUtl.NewU8(key_w_colon_bry);
this.text_ends_w_colon = i == text_len - 1;
break;
}
@@ -104,10 +109,10 @@ public class Gfo_protocol_itm {
, Itm_geo = new_(Tid_geo , "geo:")
;
public static final String Str_file = "file:", Str_xcmd = "xowa-cmd:";
public static final byte[] Bry_file = Bry_.new_a7(Str_file), Bry_xcmd = Bry_.new_a7(Str_xcmd);
public static final byte[] Bry_file_with_slashes = Bry_.new_a7("file:///");
public static final byte[] Bry_file = BryUtl.NewA7(Str_file), Bry_xcmd = BryUtl.NewA7(Str_xcmd);
public static final byte[] Bry_file_with_slashes = BryUtl.NewA7("file:///");
public static final int Len_xcmd = Bry_xcmd.length;
public static final byte[] Bry_relative = Bry_.new_a7("//");
public static final byte[] Bry_relative = BryUtl.NewA7("//");
public static Gfo_protocol_itm Get_or(byte tid, Gfo_protocol_itm or) {
Gfo_protocol_itm[] ary = Ary();
return tid >= ary.length ? or : ary[tid];
@@ -117,7 +122,7 @@ public class Gfo_protocol_itm {
int len = Regy.Len();
protocol_itm_ary = new Gfo_protocol_itm[len];
for (int i = 0; i < len; i++)
protocol_itm_ary[i] = (Gfo_protocol_itm)Regy.Get_at(i);
protocol_itm_ary[i] = (Gfo_protocol_itm)Regy.GetAt(i);
}
return protocol_itm_ary;
} private static Gfo_protocol_itm[] protocol_itm_ary;
@@ -126,7 +131,7 @@ public class Gfo_protocol_itm {
int len = Regy.Len();
protocol_str_ary = new String[len];
for (int i = 0; i < len; i++)
protocol_str_ary[i] = ((Gfo_protocol_itm)Regy.Get_at(i)).Text_str();
protocol_str_ary[i] = ((Gfo_protocol_itm)Regy.GetAt(i)).Text_str();
}
return protocol_str_ary;
} private static String[] protocol_str_ary;

View File

@@ -13,8 +13,9 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net; import gplx.*; import gplx.core.*;
package gplx.core.net;
import gplx.core.net.qargs.*;
import gplx.types.basics.utls.BryUtl;
public class Gfo_url {
private final int segs__len;
public Gfo_url(byte[] raw, byte protocol_tid, byte[] protocol_bry, byte[][] segs, Gfo_qarg_itm[] qargs, byte[] anch) {
@@ -34,5 +35,5 @@ public class Gfo_url {
public byte[] Segs__get_at_1st() {return segs__len > 0 ? segs[0] : null;}
public byte[] Segs__get_at_nth() {return segs__len > 1 ? segs[segs__len - 1] : null;}
public static final Gfo_url Empty = new Gfo_url(Bry_.Empty, Gfo_protocol_itm.Tid_unknown, Bry_.Empty, Bry_.Ary_empty, null, null);
public static final Gfo_url Empty = new Gfo_url(BryUtl.Empty, Gfo_protocol_itm.Tid_unknown, BryUtl.Empty, BryUtl.AryEmpty, null, null);
}

View File

@@ -14,23 +14,23 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net;
import gplx.Bry_;
import gplx.Bry_bfr;
import gplx.Bry_bfr_;
import gplx.Bry_find_;
import gplx.List_adp;
import gplx.List_adp_;
import gplx.types.basics.utls.BryLni;
import gplx.types.basics.utls.BryUtl;
import gplx.types.custom.brys.wtrs.BryWtr;
import gplx.types.custom.brys.BryFind;
import gplx.types.basics.lists.List_adp;
import gplx.types.basics.lists.List_adp_;
import gplx.core.btries.Btrie_rv;
import gplx.core.btries.Btrie_slim_mgr;
import gplx.core.net.qargs.Gfo_qarg_itm;
import gplx.langs.htmls.encoders.Gfo_url_encoder_;
import gplx.objects.primitives.BoolUtl;
import gplx.objects.strings.AsciiByte;
import gplx.types.basics.utls.BoolUtl;
import gplx.types.basics.constants.AsciiByte;
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 Btrie_rv trv = new Btrie_rv();
private final List_adp segs_list = List_adp_.New(), qargs_list = List_adp_.New();
private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(500);
private final BryWtr tmp_bfr = BryWtr.NewAndReset(500);
public Gfo_url_parser() {
Init_protocols(Gfo_protocol_itm.Ary());
Init_protocol_itm(Gfo_protocol_itm.Bry_relative, Gfo_protocol_itm.Tid_relative_1);
@@ -53,8 +53,8 @@ public class Gfo_url_parser {
rel = true;
}
if (!rel) { // search for ":"; NOTE: only search if not rel; i.e.: "//"
int colon_pos = Bry_find_.Find_fwd(src, AsciiByte.Colon, pos, src_end); // no colon found; EX: "//a.org/b"; "a.org/b"
if (colon_pos != Bry_find_.Not_found) // colon found; EX: "http://" or "https://"
int colon_pos = BryFind.FindFwd(src, AsciiByte.Colon, pos, src_end); // no colon found; EX: "//a.org/b"; "a.org/b"
if (colon_pos != BryFind.NotFound) // colon found; EX: "http://" or "https://"
pos = colon_pos + AsciiByte.Len1;
if (pos < src_end && src[pos] == AsciiByte.Slash) { // skip slash after colon
pos += 1;
@@ -62,17 +62,17 @@ public class Gfo_url_parser {
pos += 1;
}
}
int slash_pos = Bry_find_.Find_fwd(src, AsciiByte.Slash, pos, src_end);
if (slash_pos == Bry_find_.Not_found) // no terminating slash; EX: http://a.org
int slash_pos = BryFind.FindFwd(src, AsciiByte.Slash, pos, src_end);
if (slash_pos == BryFind.NotFound) // no terminating slash; EX: http://a.org
slash_pos = src_end;
slash_pos = Bry_.Trim_end_pos(src, slash_pos);
slash_pos = BryUtl.TrimEndPos(src, slash_pos);
site_data.Atrs_set(rel, pos, slash_pos);
}
public Gfo_url Parse(byte[] src) {return Parse(src, 0, src.length);}
public Gfo_url Parse(byte[] src, int src_bgn, int src_end) {
// protocol
byte protocol_tid = protocols.Match_byte_or(trv, src, src_bgn, src_end, Gfo_protocol_itm.Tid_unknown);
int pos = Bry_find_.Find_fwd_while(src, trv.Pos(), src_end, AsciiByte.Slash); // set pos after last slash; EX: "https://A" -> position before "A"
int pos = BryFind.FindFwdWhile(src, trv.Pos(), src_end, AsciiByte.Slash); // set pos after last slash; EX: "https://A" -> position before "A"
byte[] protocol_bry = protocol_tid == Gfo_protocol_itm.Tid_unknown
? null
: Make_bry(false, src, src_bgn, pos);
@@ -186,7 +186,7 @@ public class Gfo_url_parser {
return (Gfo_qarg_itm[])qargs_list.ToAryAndClear(Gfo_qarg_itm.class);
}
private byte[] Make_bry(boolean encoded, byte[] src, int bgn, int end) {
return encoded ? Gfo_url_encoder_.Xourl.Decode(tmp_bfr, BoolUtl.N, src, bgn, end).To_bry_and_clear() : Bry_.Mid(src, bgn, end);
return encoded ? Gfo_url_encoder_.Xourl.Decode(tmp_bfr, BoolUtl.N, src, bgn, end).ToBryAndClear() : BryLni.Mid(src, bgn, end);
}
public static final byte[] Bry_double_slash = new byte[] {AsciiByte.Slash, AsciiByte.Slash};

View File

@@ -13,42 +13,58 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net; import gplx.*; import gplx.core.*;
import gplx.core.net.qargs.*;
package gplx.core.net;
import gplx.core.net.qargs.Gfo_qarg_itm;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.BryUtl;
import gplx.types.custom.brys.wtrs.BryWtr;
import gplx.types.basics.utls.StringUtl;
import gplx.types.basics.strings.bfrs.GfoStringBldr;
class Gfo_url_parser_fxt {
private final Gfo_url_parser parser = new Gfo_url_parser();
private Gfo_url actl;
public Gfo_url_parser_fxt Test__protocol_tid(byte v) {Tfds.Eq_byte(v, actl.Protocol_tid(), "protocol_tid"); return this;}
public Gfo_url_parser_fxt Test__protocol_bry(String v) {Tfds.Eq_str(v, actl.Protocol_bry(), "protocol_bry"); return this;}
public Gfo_url_parser_fxt Test__site(String v) {Tfds.Eq_str(v, actl.Segs__get_at_1st(), "site"); return this;}
public Gfo_url_parser_fxt Test__page(String v) {Tfds.Eq_str(v, actl.Segs__get_at_nth(), "page"); return this;}
public Gfo_url_parser_fxt Test__anch(String v) {Tfds.Eq_str(v, actl.Anch(), "anch"); return this;}
public Gfo_url_parser_fxt Test__protocol_tid(byte v) {GfoTstr.EqByte(v, actl.Protocol_tid(), "protocol_tid"); return this;}
public Gfo_url_parser_fxt Test__protocol_bry(String v) {GfoTstr.Eq(v, actl.Protocol_bry(), "protocol_bry"); return this;}
public Gfo_url_parser_fxt Test__site(String v) {GfoTstr.Eq(v, actl.Segs__get_at_1st(), "site"); return this;}
public Gfo_url_parser_fxt Test__page(String v) {GfoTstr.Eq(v, actl.Segs__get_at_nth(), "page"); return this;}
public Gfo_url_parser_fxt Test__anch(String v) {GfoTstr.Eq(v, actl.Anch(), "anch"); return this;}
public Gfo_url_parser_fxt Test__segs(String... ary) {
Tfds.Eq_str_lines(String_.Concat_lines_nl(ary), String_.Concat_lines_nl(String_.Ary(actl.Segs())), "segs");
Tfds.Eq_int(ary.length, actl.Segs().length, "segs_len");
GfoTstr.EqLines(StringUtl.ConcatLinesNl(ary), StringUtl.ConcatLinesNl(StringUtl.Ary(actl.Segs())), "segs");
GfoTstr.Eq(ary.length, actl.Segs().length, "segs_len");
return this;
}
public Gfo_url_parser_fxt Test__qargs(String... ary) {Tfds.Eq_str_lines(String_.To_str__as_kv_ary(ary), Qargs__To_str(actl.Qargs()), "qargs"); return this;}
public Gfo_url_parser_fxt Test__qargs(String... ary) {GfoTstr.EqLines(StringUtl_ToStrByKvAry(ary), Qargs__To_str(actl.Qargs()), "qargs"); return this;}
public Gfo_url_parser_fxt Exec__parse(String v) {
this.actl = parser.Parse(Bry_.new_u8(v), 0, String_.Len(v));
this.actl = parser.Parse(BryUtl.NewU8(v), 0, StringUtl.Len(v));
return this;
}
public void Test_Parse_site_fast(String raw, String expd) {
byte[] raw_bry = Bry_.new_u8(raw);
byte[] raw_bry = BryUtl.NewU8(raw);
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);
String actl = StringUtl.NewU8(raw_bry, site_data.Site_bgn(), site_data.Site_end());
GfoTstr.EqObj(expd, actl);
} private final Gfo_url_site_data site_data = new Gfo_url_site_data();
private static String Qargs__To_str(Gfo_qarg_itm[] ary) {
int len = ary.length;
Bry_bfr bfr = Bry_bfr_.New();
BryWtr bfr = BryWtr.New();
for (int i = 0; i < len; ++i) {
Gfo_qarg_itm itm = ary[i];
bfr.Add(itm.Key_bry()).Add_byte_eq();
bfr.Add(itm.Key_bry()).AddByteEq();
if (itm.Val_bry() != null)
bfr.Add(itm.Val_bry());
bfr.Add_byte_nl();
bfr.AddByteNl();
}
return bfr.To_str_and_clear();
return bfr.ToStrAndClear();
}
private static String StringUtl_ToStrByKvAry(String... ary) {
GfoStringBldr sb = new GfoStringBldr();
int len = ary.length;
for (int i = 0; i < len; i += 2) {
sb.Add(ary[i]).AddChar('=');
String val = i + 1 < len ? ary[i + 1] : null;
if (val != null) sb.Add(val);
sb.AddCharNl();
}
return sb.ToStrAndClear();
}
}

View File

@@ -32,10 +32,10 @@ public class Gfo_url_parser_tst {
@Test public void Site__parts__1() {
tstr.Exec__parse("https://wikipedia").Test__protocol_tid(Gfo_protocol_itm.Tid_https).Test__segs("wikipedia");
}
@Test public void Site__slash__none() {
@Test public void Site__slash__none() {
tstr.Exec__parse("https:site").Test__protocol_tid(Gfo_protocol_itm.Tid_https).Test__site("site");
}
@Test public void Site__slash__eos() {
@Test public void Site__slash__eos() {
tstr.Exec__parse("https://en.wikipedia.org/").Test__protocol_tid(Gfo_protocol_itm.Tid_https).Test__site("en.wikipedia.org");
}
@Test public void Paths__1() {

View File

@@ -1,19 +1,21 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net; import gplx.*; import gplx.core.*;
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net;
import gplx.types.basics.utls.BryUtl;
import gplx.types.errs.ErrUtl;
public class Http_client_rdr_ {
public static Http_client_rdr new_stream() {return new Http_client_rdr__stream();}
public static Http_client_rdr new_mem() {return new Http_client_rdr__mem();}
@@ -28,7 +30,7 @@ class Http_client_rdr__mem implements Http_client_rdr {
public String Read_line() {
return idx == ary_len ? null : ary[idx++];
}
public byte[] Read_line_as_bry() {return Bry_.new_u8(Read_line());}
public int Read_char_ary(char[] ary, int bgn, int len) {throw Err_.new_unimplemented();}
public byte[] Read_line_as_bry() {return BryUtl.NewU8(Read_line());}
public int Read_char_ary(char[] ary, int bgn, int len) {throw ErrUtl.NewUnimplemented();}
public void Rls() {}
}

View File

@@ -1,19 +1,21 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net; import gplx.*; import gplx.core.*;
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net;
import gplx.types.basics.utls.BryUtl;
import gplx.types.errs.ErrUtl;
import java.io.*;
class Http_client_rdr__stream implements Http_client_rdr {
private BufferedReader br;
@@ -22,15 +24,15 @@ class Http_client_rdr__stream implements Http_client_rdr {
}
public String Read_line() {
try {return br.readLine();}
catch (IOException e) {throw Err_.new_exc(e, "net", "Read_line failed");}
catch (IOException e) {throw ErrUtl.NewArgs(e, "Read_line failed");}
}
public int Read_char_ary(char[] ary, int bgn, int len) {
try {return br.read(ary, bgn, len);}
catch (IOException e) {throw Err_.new_exc(e, "net", "Read_line failed");}
catch (IOException e) {throw ErrUtl.NewArgs(e, "Read_line failed");}
}
public byte[] Read_line_as_bry() {return Bry_.new_u8(Read_line());}
public byte[] Read_line_as_bry() {return BryUtl.NewU8(Read_line());}
public void Rls() {
try {br.close();}
catch (IOException e) {throw Err_.new_exc(e, "net", "Rls failed");}
catch (IOException e) {throw ErrUtl.NewArgs(e, "Rls failed");}
}
}

View File

@@ -13,8 +13,9 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net; import gplx.*; import gplx.core.*;
import gplx.core.ios.*; import gplx.core.ios.streams.*;
package gplx.core.net;
import gplx.core.ios.streams.*;
import gplx.types.errs.ErrUtl;
import java.io.*;
class Http_client_wtr__stream implements Http_client_wtr {
private final byte[] tmp_stream_bry = new byte[1024];
@@ -24,15 +25,15 @@ class Http_client_wtr__stream implements Http_client_wtr {
}
public void Write_bry(byte[] bry) {
try {stream.write(bry);}
catch (IOException e) {throw Err_.new_exc(e, "net", "Write_bry failed");}
catch (IOException e) {throw ErrUtl.NewArgs(e, "Write_bry failed");}
}
public void Write_str(String s) {
try {stream.writeBytes(s);}
catch (Exception e) {throw Err_.new_exc(e, "net", "Write_str failed");}
catch (Exception e) {throw ErrUtl.NewArgs(e, "Write_str failed");}
}
public void Write_mid(byte[] bry, int bgn, int end) {
try {stream.write(bry, bgn, end - bgn);}
catch (IOException e) {throw Err_.new_exc(e, "net", "Write_mid failed");}
catch (IOException e) {throw ErrUtl.NewArgs(e, "Write_mid failed");}
}
public void Write_stream(Io_stream_rdr stream_rdr) {
synchronized (tmp_stream_bry) {
@@ -46,6 +47,6 @@ class Http_client_wtr__stream implements Http_client_wtr {
}
public void Rls() {
try {stream.close();}
catch (IOException e) {throw Err_.new_exc(e, "net", "Rls failed");}
catch (IOException e) {throw ErrUtl.NewArgs(e, "Rls failed");}
}
}

View File

@@ -13,11 +13,13 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net; import gplx.*;
package gplx.core.net;
import gplx.types.basics.lists.Ordered_hash;
import gplx.types.basics.lists.Ordered_hash_;
public class Http_post_data_hash {
private final Ordered_hash hash = Ordered_hash_.New_bry();
public int Len() {return hash.Len();}
public Http_post_data_itm Get_at(int i) {return (Http_post_data_itm)hash.Get_at(i);}
public Http_post_data_itm Get_at(int i) {return (Http_post_data_itm)hash.GetAt(i);}
public Http_post_data_itm Get_by(byte[] k) {return (Http_post_data_itm)hash.GetByOrNull(k);}
public void Add(byte[] key, byte[] val) {
hash.Add(key, new Http_post_data_itm(key, val));

View File

@@ -13,8 +13,10 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net; import gplx.*;
import gplx.objects.strings.AsciiByte;
package gplx.core.net;
import gplx.types.custom.brys.wtrs.BryWtr;
import gplx.types.basics.constants.AsciiByte;
import gplx.types.basics.utls.StringUtl;
public class Http_request_itm {
public Http_request_itm(int type, byte[] url, byte[] protocol, byte[] host, byte[] user_agent
, byte[] accept, byte[] accept_language, byte[] accept_encoding, boolean dnt, byte[] x_requested_with, byte[] cookie, byte[] referer
@@ -48,34 +50,34 @@ public class Http_request_itm {
public byte[] Cache_control() {return cache_control;} private final byte[] cache_control;
public byte[] Origin() {return origin;} private final byte[] origin;
public Http_post_data_hash Post_data_hash() {return post_data_hash;} private final Http_post_data_hash post_data_hash;
public String To_str(Bry_bfr bfr, boolean line) {
bfr .Add_kv_dlm(line, "type" , type == Type_get ? "GET" : "POST")
.Add_kv_dlm(line, "url" , url)
.Add_kv_dlm(line, "protocol" , protocol)
.Add_kv_dlm(line, "host" , host)
.Add_kv_dlm(line, "user_agent" , user_agent)
.Add_kv_dlm(line, "accept" , accept)
.Add_kv_dlm(line, "accept_encoding" , accept_encoding)
.Add_kv_dlm(line, "dnt" , dnt)
.Add_kv_dlm(line, "x_requested_with" , x_requested_with)
.Add_kv_dlm(line, "cookie" , cookie)
.Add_kv_dlm(line, "referer" , referer)
.Add_kv_dlm(line, "content_length" , content_length)
.Add_kv_dlm(line, "content_type" , content_type)
.Add_kv_dlm(line, "content_type_boundary" , content_type_boundary)
.Add_kv_dlm(line, "connection" , connection)
.Add_kv_dlm(line, "pragma" , pragma)
.Add_kv_dlm(line, "cache_control" , cache_control)
public String To_str(BryWtr bfr, boolean line) {
bfr .AddKvDlm(line, "type" , type == Type_get ? "GET" : "POST")
.AddKvDlm(line, "url" , url)
.AddKvDlm(line, "protocol" , protocol)
.AddKvDlm(line, "host" , host)
.AddKvDlm(line, "user_agent" , user_agent)
.AddKvDlm(line, "accept" , accept)
.AddKvDlm(line, "accept_encoding" , accept_encoding)
.AddKvDlm(line, "dnt" , dnt)
.AddKvDlm(line, "x_requested_with" , x_requested_with)
.AddKvDlm(line, "cookie" , cookie)
.AddKvDlm(line, "referer" , referer)
.AddKvDlm(line, "content_length" , content_length)
.AddKvDlm(line, "content_type" , content_type)
.AddKvDlm(line, "content_type_boundary" , content_type_boundary)
.AddKvDlm(line, "connection" , connection)
.AddKvDlm(line, "pragma" , pragma)
.AddKvDlm(line, "cache_control" , cache_control)
;
if (post_data_hash != null) {
int len = post_data_hash.Len();
for (int i = 0; i < len; ++i) {
Http_post_data_itm itm = post_data_hash.Get_at(i);
bfr.Add_byte_repeat(AsciiByte.Space, 2);
bfr.Add_kv_dlm(line, String_.new_u8(itm.Key()), itm.Val());
bfr.AddByteRepeat(AsciiByte.Space, 2);
bfr.AddKvDlm(line, StringUtl.NewU8(itm.Key()), itm.Val());
}
}
return bfr.To_str_and_clear();
return bfr.ToStrAndClear();
}
public static final int Type_get = 1, Type_post = 2;
}

View File

@@ -14,17 +14,17 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net;
import gplx.Bry_;
import gplx.Bry_bfr;
import gplx.Bry_bfr_;
import gplx.Bry_find_;
import gplx.Err_;
import gplx.String_;
import gplx.core.btries.Btrie_rv;
import gplx.core.btries.Btrie_slim_mgr;
import gplx.core.primitives.Int_obj_val;
import gplx.objects.primitives.BoolUtl;
import gplx.objects.strings.AsciiByte;
import gplx.types.basics.utls.BryLni;
import gplx.types.basics.utls.BryUtl;
import gplx.types.custom.brys.wtrs.BryWtr;
import gplx.types.custom.brys.BryFind;
import gplx.types.basics.constants.AsciiByte;
import gplx.types.basics.utls.BoolUtl;
import gplx.types.basics.utls.StringUtl;
import gplx.types.basics.wrappers.IntVal;
import gplx.types.errs.ErrUtl;
public class Http_request_parser {
private boolean dnt;
private int type, content_length;
@@ -32,7 +32,7 @@ public class Http_request_parser {
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_w_size(255); private final Btrie_rv trv = new Btrie_rv();
private final BryWtr tmp_bfr = BryWtr.NewWithSize(255); private final Btrie_rv trv = new Btrie_rv();
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() {
@@ -52,99 +52,99 @@ public class Http_request_parser {
while (true) {
String line_str = rdr.Read_line(); if (line_str == null) break; // needed for TEST
if (log) server_wtr.Write_str_w_nl(line_str);
byte[] line = Bry_.new_u8(line_str);
byte[] line = BryUtl.NewU8(line_str);
int line_len = line.length;
if (line_len == 0) {
switch (type) {
case Http_request_itm.Type_get: break;
case Http_request_itm.Type_post:
if (reading_post_data || post_nl_seen) throw Err_.new_wo_type("http.request.parser;invalid new line during post", "request", To_str());
if (reading_post_data || post_nl_seen) throw ErrUtl.NewArgs("http.request.parser;invalid new line during post", "request", To_str());
post_nl_seen = true; // only allow one \n per POST
continue; // ignore line and get next
default: throw Err_.new_unimplemented();
default: throw ErrUtl.NewUnimplemented();
}
break; // only GET will reach this line; GET requests always end with blank line; stop;
}
if (content_type_boundary != null && Bry_.Has_at_bgn(line, content_type_boundary)) {
if (content_type_boundary != null && BryUtl.HasAtBgn(line, content_type_boundary)) {
while (true) {
if (Bry_.Has_at_end(line, Tkn_content_type_boundary_end)) break; // last form_data pair will end with "--"; stop
if (BryUtl.HasAtEnd(line, Tkn_content_type_boundary_end)) break; // last form_data pair will end with "--"; stop
line = Parse_content_type_boundary(rdr);
}
break; // assume form_data sends POST request
}
Object o = trie.Match_at(trv, line, 0, line_len);
Object o = trie.MatchAt(trv, line, 0, line_len);
if (o == null) {
server_wtr.Write_str_w_nl(String_.Format("http.request.parser; unknown line; line={0} request={1}", line_str, To_str()));
server_wtr.Write_str_w_nl(StringUtl.Format("http.request.parser; unknown line; line={0} request={1}", line_str, To_str()));
continue;
}
int val_bgn = Bry_find_.Find_fwd_while_ws(line, trv.Pos(), line_len); // skip ws after key; EX: "Host: "
int tid = ((Int_obj_val)o).Val();
int val_bgn = BryFind.FindFwdWhileWs(line, trv.Pos(), line_len); // skip ws after key; EX: "Host: "
int tid = ((IntVal)o).Val();
switch (tid) {
case Tid_get:
case Tid_post: Parse_type(tid, val_bgn, line, line_len); break;
case Tid_host: this.host = Bry_.Mid(line, val_bgn, line_len); break;
case Tid_user_agent: this.user_agent = Bry_.Mid(line, val_bgn, line_len); break;
case Tid_accept: this.accept = Bry_.Mid(line, val_bgn, line_len); break;
case Tid_accept_language: this.accept_language = Bry_.Mid(line, val_bgn, line_len); break;
case Tid_accept_encoding: this.accept_encoding = Bry_.Mid(line, val_bgn, line_len); break;
case Tid_host: this.host = BryLni.Mid(line, val_bgn, line_len); break;
case Tid_user_agent: this.user_agent = BryLni.Mid(line, val_bgn, line_len); break;
case Tid_accept: this.accept = BryLni.Mid(line, val_bgn, line_len); break;
case Tid_accept_language: this.accept_language = BryLni.Mid(line, val_bgn, line_len); break;
case Tid_accept_encoding: this.accept_encoding = BryLni.Mid(line, val_bgn, line_len); break;
case Tid_dnt: this.dnt = line[val_bgn] == AsciiByte.Num1; break;
case Tid_x_requested_with: this.x_requested_with = Bry_.Mid(line, val_bgn, line_len); break;
case Tid_cookie: this.cookie = Bry_.Mid(line, val_bgn, line_len); break;
case Tid_referer: this.referer = Bry_.Mid(line, val_bgn, line_len); break;
case Tid_content_length: this.content_length = Bry_.To_int_or(line, val_bgn, line_len, -1); break;
case Tid_x_requested_with: this.x_requested_with = BryLni.Mid(line, val_bgn, line_len); break;
case Tid_cookie: this.cookie = BryLni.Mid(line, val_bgn, line_len); break;
case Tid_referer: this.referer = BryLni.Mid(line, val_bgn, line_len); break;
case Tid_content_length: this.content_length = BryUtl.ToIntOr(line, val_bgn, line_len, -1); break;
case Tid_content_type: Parse_content_type(val_bgn, line, line_len); break;
case Tid_connection: this.connection = Bry_.Mid(line, val_bgn, line_len); break;
case Tid_pragma: this.pragma = Bry_.Mid(line, val_bgn, line_len); break;
case Tid_cache_control: this.cache_control = Bry_.Mid(line, val_bgn, line_len); break;
case Tid_origin: this.origin = Bry_.Mid(line, val_bgn, line_len); break;
case Tid_connection: this.connection = BryLni.Mid(line, val_bgn, line_len); break;
case Tid_pragma: this.pragma = BryLni.Mid(line, val_bgn, line_len); break;
case Tid_cache_control: this.cache_control = BryLni.Mid(line, val_bgn, line_len); break;
case Tid_origin: this.origin = BryLni.Mid(line, val_bgn, line_len); break;
case Tid_upgrade_request: break;
case Tid_x_host: break;
case Tid_x_real_ip: break;
case Tid_accept_charset: break;
case Tid_sec_fetch_mode: break;
case Tid_sec_fetch_site: break;
default: throw Err_.new_unhandled(tid);
default: throw ErrUtl.NewUnhandled(tid);
}
}
return Make_request_itm();
}
}
private void Parse_type(int tid, int val_bgn, byte[] line, int line_len) { // EX: "POST /xowa-cmd:exec_as_json HTTP/1.1"
int url_end = Bry_find_.Find_bwd(line, AsciiByte.Space, line_len); if (url_end == Bry_find_.Not_found) throw Err_.new_wo_type("invalid protocol", "line", line, "request", To_str());
int url_end = BryFind.FindBwd(line, AsciiByte.Space, line_len); if (url_end == BryFind.NotFound) throw ErrUtl.NewArgs("invalid protocol", "line", line, "request", To_str());
switch (tid) {
case Tid_get : this.type = Http_request_itm.Type_get; break;
case Tid_post : this.type = Http_request_itm.Type_post; break;
default : throw Err_.new_unimplemented();
default : throw ErrUtl.NewUnimplemented();
}
this.url = Bry_.Mid(line, val_bgn, url_end);
this.protocol = Bry_.Mid(line, url_end + 1, line_len);
this.url = BryLni.Mid(line, val_bgn, url_end);
this.protocol = BryLni.Mid(line, url_end + 1, line_len);
}
private void Parse_content_type(int val_bgn, byte[] line, int line_len) { // EX: Content-Type: multipart/form-data; boundary=---------------------------72432484930026
// handle wolfram and other clients; DATE:2015-08-03
int boundary_bgn = Bry_find_.Find_fwd(line, Tkn_boundary, val_bgn, line_len); if (boundary_bgn == Bry_find_.Not_found) return; // PURPOSE: ignore content-type for GET calls like by Mathematica server; DATE:2015-08-04 // throw Err_.new_wo_type("invalid content_type", "line", line, "request", To_str());
int content_type_end = Bry_find_.Find_bwd(line, AsciiByte.Semic, boundary_bgn);
this.content_type = Bry_.Mid(line, val_bgn, content_type_end);
this.content_type_boundary = Bry_.Add(Tkn_content_type_boundary_end, Bry_.Mid(line, boundary_bgn += Tkn_boundary.length, line_len));
int boundary_bgn = BryFind.FindFwd(line, Tkn_boundary, val_bgn, line_len); if (boundary_bgn == BryFind.NotFound) return; // PURPOSE: ignore content-type for GET calls like by Mathematica server; DATE:2015-08-04 // throw ErrUtl.NewArgs("invalid content_type", "line", line, "request", To_str());
int content_type_end = BryFind.FindBwd(line, AsciiByte.Semic, boundary_bgn);
this.content_type = BryLni.Mid(line, val_bgn, content_type_end);
this.content_type_boundary = BryUtl.Add(Tkn_content_type_boundary_end, BryLni.Mid(line, boundary_bgn += Tkn_boundary.length, line_len));
}
private Http_request_itm Make_request_itm() {
return new Http_request_itm(type, url, protocol, host, user_agent, accept, accept_language, accept_encoding, dnt, x_requested_with, cookie, referer, content_length, content_type, content_type_boundary, connection, pragma, cache_control, origin, post_data_hash);
}
private byte[] Parse_content_type_boundary(Http_client_rdr rdr) {
if (post_data_hash == null) post_data_hash = new Http_post_data_hash();
byte[] line = Bry_.new_u8(rdr.Read_line()); // cur line is already known to be content_type_boundary; skip it
byte[] line = BryUtl.NewU8(rdr.Read_line()); // cur line is already known to be content_type_boundary; skip it
byte[] key = Parse_post_data_name(line);
String line_str = rdr.Read_line(); // blank-line
if (String_.Len_gt_0(line_str)) {throw Err_.new_wo_type("http.request.parser; blank_line should follow content_type_boundary", "request", To_str());}
if (StringUtl.IsNotNullOrEmpty(line_str)) {throw ErrUtl.NewArgs("http.request.parser; blank_line should follow content_type_boundary", "request", To_str());}
while (true) {
line = Bry_.new_u8(rdr.Read_line());
if (Bry_.Has_at_bgn(line, content_type_boundary)) break;
line = BryUtl.NewU8(rdr.Read_line());
if (BryUtl.HasAtBgn(line, content_type_boundary)) break;
// add \n between lines, but not after last line
if (tmp_bfr.Len_gt_0())
tmp_bfr.Add_byte_nl();
if (tmp_bfr.HasSome())
tmp_bfr.AddByteNl();
tmp_bfr.Add(line);
}
byte[] val = tmp_bfr.To_bry_and_clear();
byte[] val = tmp_bfr.ToBryAndClear();
post_data_hash.Add(key, val);
return line;
}
@@ -155,17 +155,17 @@ public class Http_request_parser {
pos = Assert_tkn(line, pos, line_len, Tkn_name);
int name_end = line_len;
if (line[pos] == AsciiByte.Quote) {
if (line[name_end - 1] != AsciiByte.Quote) throw Err_.new_wo_type("http.request.parser; invalid form at end", "line", line, "request", To_str());
if (line[name_end - 1] != AsciiByte.Quote) throw ErrUtl.NewArgs("http.request.parser; invalid form at end", "line", line, "request", To_str());
++pos;
--name_end;
}
return Bry_.Mid(line, pos, name_end);
return BryLni.Mid(line, pos, name_end);
}
private int Assert_tkn(byte[] src, int src_pos, int src_len, byte[] tkn) {
int tkn_len = tkn.length;
if (!Bry_.Match(src, src_pos, src_pos + tkn_len, tkn)) throw Err_.new_wo_type("http.request.parser; invalid form_data line", "tkn", tkn, "line", src, "request", To_str());
if (!BryLni.Eq(src, src_pos, src_pos + tkn_len, tkn)) throw ErrUtl.NewArgs("http.request.parser; invalid form_data line", "tkn", tkn, "line", src, "request", To_str());
int rv = src_pos += tkn_len;
return Bry_find_.Find_fwd_while_ws(src, rv, src_len);
return BryFind.FindFwdWhileWs(src, rv, src_len);
}
private String To_str() {return Make_request_itm().To_str(tmp_bfr, BoolUtl.N);}
private static final int Tid_get = 1, Tid_post = 2, Tid_host = 3, Tid_user_agent = 4, Tid_accept = 5, Tid_accept_language = 6, Tid_accept_encoding = 7, Tid_dnt = 8
@@ -196,8 +196,8 @@ public class Http_request_parser {
.Add_str_int("Sec-Fetch-Mode:" , Tid_sec_fetch_mode)
.Add_str_int("Sec-Fetch-Site:" , Tid_sec_fetch_site)
;
private static final byte[] Tkn_boundary = Bry_.new_a7("boundary="), Tkn_content_type_boundary_end = Bry_.new_a7("--")
, Tkn_content_disposition = Bry_.new_a7("Content-Disposition:"), Tkn_form_data = Bry_.new_a7("form-data;")
, Tkn_name = Bry_.new_a7("name=")
private static final byte[] Tkn_boundary = BryUtl.NewA7("boundary="), Tkn_content_type_boundary_end = BryUtl.NewA7("--")
, Tkn_content_disposition = BryUtl.NewA7("Content-Disposition:"), Tkn_form_data = BryUtl.NewA7("form-data;")
, Tkn_name = BryUtl.NewA7("name=")
;
}

View File

@@ -13,21 +13,24 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net; import gplx.*; import gplx.core.*;
package gplx.core.net;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.BryUtl;
import gplx.types.basics.utls.StringUtl;
import org.junit.*; import gplx.core.tests.*;
public class Http_request_parser_tst {
@Before public void init() {fxt.Clear();} private final Http_request_parser_fxt fxt = new Http_request_parser_fxt();
@Test public void Type_post() {
@Test public void Type_post() {
fxt.Test_type_post("POST /url HTTP/1.1", Http_request_itm.Type_post, "/url", "HTTP/1.1");
}
@Test public void Type_content_type() {
@Test public void Type_content_type() {
fxt.Test_content_type("Content-Type: multipart/form-data; boundary=---------------------------72432484930026", "multipart/form-data", "-----------------------------72432484930026");
}
@Test public void Type_content_type__x_www_form_url_encoded() { // PURPOSE: ignore content-type for GET calls like by Mathematica server; DATE:2015-08-04
@Test public void Type_content_type__x_www_form_url_encoded() { // PURPOSE: ignore content-type for GET calls like by Mathematica server; DATE:2015-08-04
fxt.Test_content_type("Content-Type: application/x-www-form-urlencoded", null, null);
}
@Test public void Type_form_data() {
fxt.Test_form_data(String_.Ary
@Test public void Type_form_data() {
fxt.Test_form_data(StringUtl.Ary
( "POST /url HTTP/1.1"
, "Content-Type: multipart/form-data; boundary=---------------------------12345678901234"
, ""
@@ -45,10 +48,10 @@ public class Http_request_parser_tst {
, fxt.Make_post_data_itm("key1", "val1")
);
}
@Test public void Type_accept_charset() {
@Test public void Type_accept_charset() {
fxt.Test_ignore("Accept-Charset: ISO-8859-1,utf-8;q=0.7");
}
@Test public void Nginx() {// PURPOSE: support http headers from nginx; ISSUE#:255
@Test public void Nginx() {// PURPOSE: support http headers from nginx; ISSUE#:255
fxt.Test_ignore("Upgrade-Insecure-Requests: test1; X-Host: test2; X-Real-IP: test3;");
}
}
@@ -63,19 +66,19 @@ class Http_request_parser_fxt {
parser.Clear();
server_wtr.Clear();
}
public Http_post_data_itm Make_post_data_itm(String key, String val) {return new Http_post_data_itm(Bry_.new_u8(key), Bry_.new_u8(val));}
public Http_post_data_itm Make_post_data_itm(String key, String val) {return new Http_post_data_itm(BryUtl.NewU8(key), BryUtl.NewU8(val));}
public void Test_type_post(String line, int expd_type, String expd_url, String expd_protocol) {
client_rdr.Stream_(String_.Ary(line));
client_rdr.Stream_(StringUtl.Ary(line));
Http_request_itm req = parser.Parse(client_rdr);
Tfds.Eq(expd_type , req.Type());
Tfds.Eq(expd_url , String_.new_u8(req.Url()));
Tfds.Eq(expd_protocol , String_.new_u8(req.Protocol()));
GfoTstr.EqObj(expd_type , req.Type());
GfoTstr.EqObj(expd_url , StringUtl.NewU8(req.Url()));
GfoTstr.EqObj(expd_protocol , StringUtl.NewU8(req.Protocol()));
}
public void Test_content_type(String line, String expd_content_type, String expd_content_boundary) {
client_rdr.Stream_(String_.Ary(line));
client_rdr.Stream_(StringUtl.Ary(line));
Http_request_itm req = parser.Parse(client_rdr);
Tfds.Eq(expd_content_type , String_.new_u8(req.Content_type()));
Tfds.Eq(expd_content_boundary , String_.new_u8(req.Content_type_boundary()));
GfoTstr.EqObj(expd_content_type , StringUtl.NewU8(req.Content_type()));
GfoTstr.EqObj(expd_content_boundary , StringUtl.NewU8(req.Content_type_boundary()));
}
public void Test_form_data(String[] ary, Http_post_data_itm... expd) {
client_rdr.Stream_(ary);
@@ -84,13 +87,13 @@ class Http_request_parser_fxt {
int len = hash.Len();
for (int i = 0; i < len; ++i) {
Http_post_data_itm itm = hash.Get_at(i);
Tfds.Eq_bry(itm.Key(), expd[i].Key());
Tfds.Eq_bry(itm.Val(), expd[i].Val());
GfoTstr.Eq(itm.Key(), expd[i].Key());
GfoTstr.Eq(itm.Val(), expd[i].Val());
}
}
public void Test_ignore(String line) {
client_rdr.Stream_(String_.Ary(line));
client_rdr.Stream_(StringUtl.Ary(line));
parser.Parse(client_rdr);
Gftest.Eq__str(null, server_wtr.Data());
Gftest.EqNull(server_wtr.Data());
}
}

View File

@@ -13,10 +13,11 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net; import gplx.*; import gplx.core.*;
public class Local_host_ {
public static String Ip_address() {
try {return java.net.InetAddress.getLocalHost().getHostAddress();}
catch (Exception e) {throw Err_.new_exc(e, "net", "ip_address failed");}
}
}
package gplx.core.net;
import gplx.types.errs.ErrUtl;
public class Local_host_ {
public static String Ip_address() {
try {return java.net.InetAddress.getLocalHost().getHostAddress();}
catch (Exception e) {throw ErrUtl.NewArgs(e, "ip_address failed");}
}
}

View File

@@ -1,19 +1,20 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net; import gplx.*; import gplx.core.*;
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net;
import gplx.types.errs.ErrUtl;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
@@ -26,17 +27,17 @@ public class Server_socket_adp__base implements Server_socket_adp {
server_socket.setReuseAddress(true);
server_socket.bind(new InetSocketAddress(port));
}
catch (IOException e) {throw Err_.new_exc(e, "net", "Get_input_stream failed");}
catch (IOException e) {throw ErrUtl.NewArgs(e, "Get_input_stream failed");}
return this;
}
public Socket_adp Accept() {
Socket client_socket = null;
try {client_socket = server_socket.accept();}
catch (IOException e) {throw Err_.new_exc(e, "net", "Get_input_stream failed");}
catch (IOException e) {throw ErrUtl.NewArgs(e, "Get_input_stream failed");}
return new Socket_adp__base(client_socket);
}
public void Rls() {
try {server_socket.close();}
catch (IOException e) {throw Err_.new_exc(e, "net", "Rls failed");}
catch (IOException e) {throw ErrUtl.NewArgs(e, "Rls failed");}
}
}

View File

@@ -1,19 +1,20 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net; import gplx.*; import gplx.core.*;
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net;
import gplx.types.errs.ErrUtl;
import java.io.IOException;
import java.net.*;
public class Socket_adp__base implements Socket_adp {
@@ -24,14 +25,14 @@ public class Socket_adp__base implements Socket_adp {
}
public Object Get_input_stream() {
try {return socket.getInputStream();}
catch (IOException e) {throw Err_.new_exc(e, "net", "Get_input_stream failed");}
catch (IOException e) {throw ErrUtl.NewArgs(e, "Get_input_stream failed");}
}
public Object Get_output_stream() {
try {return socket.getOutputStream();}
catch (IOException e) {throw Err_.new_exc(e, "net", "Get_output_stream failed");}
catch (IOException e) {throw ErrUtl.NewArgs(e, "Get_output_stream failed");}
}
public void Rls() {
try {socket.close();}
catch (IOException e) {throw Err_.new_exc(e, "net", "Rls failed");}
catch (IOException e) {throw ErrUtl.NewArgs(e, "Rls failed");}
}
}

View File

@@ -13,12 +13,13 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net.downloads; import gplx.*; import gplx.core.*; import gplx.core.net.*;
public interface Http_download_wkr {
String Fail_msg();
Io_url Tmp_url();
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();
}
package gplx.core.net.downloads;
import gplx.libs.files.Io_url;
public interface Http_download_wkr {
String Fail_msg();
Io_url Tmp_url();
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

@@ -1,20 +1,25 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net.downloads; import gplx.*; import gplx.core.*; import gplx.core.net.*;
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net.downloads;
import gplx.core.progs.*;
import gplx.libs.files.Io_mgr;
import gplx.types.errs.ErrUtl;
import gplx.types.basics.utls.LongUtl;
import gplx.types.basics.utls.StringUtl;
import gplx.libs.files.Io_url;
public abstract class Http_download_wkr__base implements Http_download_wkr {
private long expd_size;
private Io_url tmp_url, checkpoint_url;
@@ -36,14 +41,14 @@ public abstract class Http_download_wkr__base implements Http_download_wkr {
try {status = this.Exec_hook(prog_ui, src_str, tmp_url, downloaded);}
catch (Exception e) {
status = Gfo_prog_ui_.Status__fail;
fail_msg = Err_.Message_lang(e);
fail_msg = ErrUtl.Message(e);
}
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);
this.fail_msg = StringUtl.Format("bad size: bad={0} good={1}", actl_size, expd_size);
return Gfo_prog_ui_.Status__fail;
}
}
@@ -70,11 +75,11 @@ public abstract class Http_download_wkr__base implements Http_download_wkr {
}
private long Checkpoint__load() {
byte[] data = Io_mgr.Instance.LoadFilBryOrNull(checkpoint_url);
return data == null ? 0 : Long_.parse_or(String_.new_a7(data), 0);
return data == null ? 0 : LongUtl.ParseOr(StringUtl.NewA7(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));
Io_mgr.Instance.SaveFilStr(checkpoint_url, LongUtl.ToStr(new_val));
downloaded = new_val;
checkpoint_nxt += checkpoint_interval;
}

View File

@@ -1,22 +1,33 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net.downloads; import gplx.*; import gplx.core.*; import gplx.core.net.*;
import java.io.*;
import java.net.*;
import gplx.core.progs.*;
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net.downloads;
import gplx.libs.files.Io_mgr;
import gplx.core.progs.Gfo_prog_ui;
import gplx.core.progs.Gfo_prog_ui_;
import gplx.types.errs.ErrUtl;
import gplx.libs.files.Io_url;
import gplx.types.basics.utls.LongUtl;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class Http_download_wkr__jre extends Http_download_wkr__base {
public Http_download_wkr Make_new() {return new Http_download_wkr__jre();}
@Override public byte Exec_hook(Gfo_prog_ui prog_ui, String src_url, Io_url trg_url, long downloaded) {
@@ -30,7 +41,7 @@ public class Http_download_wkr__jre extends Http_download_wkr__base {
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_wo_type("write failed; permission error?", "trg", trg_url, "err", e.toString());}
catch (FileNotFoundException e) {throw ErrUtl.NewArgs("write failed; permission error?", "trg", trg_url, "err", e.toString());}
// open src stream
InputStream src_stream = null;
@@ -39,14 +50,14 @@ public class Http_download_wkr__jre extends Http_download_wkr__base {
catch (MalformedURLException e) {
try {if (trg_stream != null) trg_stream.close();}
catch (IOException e1) {}
throw Err_.new_wo_type("bad url", "src", src_url, "err" + e.toString());
throw ErrUtl.NewArgs("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.addRequestProperty("Range", "bytes=" + LongUtl.ToStr(prog_data_cur) + "-");
src_conn.setReadTimeout(10000); // explicitly set timeout; NOTE:needed on Mac OS X, else error never thrown; DATE:2016-09-03
src_conn.connect();
@@ -60,21 +71,21 @@ public class Http_download_wkr__jre extends Http_download_wkr__base {
Io_mgr.Instance.DeleteFil(this.Trg_url());
Io_mgr.Instance.DeleteFil(this.Checkpoint_url());
}
throw Err_.new_wo_type("server returned non-partial response code", "src", src_url, "code", src_conn.getResponseCode(), "msg", src_conn.getResponseMessage());
throw ErrUtl.NewArgs("server returned non-partial response code", "src", src_url, "code", src_conn.getResponseCode(), "msg", src_conn.getResponseMessage());
}
}
else {
if (response_code != HttpURLConnection.HTTP_OK) {
try {if (trg_stream != null) trg_stream.close();}
catch (IOException e1) {}
throw Err_.new_wo_type("server returned non-OK response code", "src", src_url, "code", src_conn.getResponseCode(), "msg", src_conn.getResponseMessage());
throw ErrUtl.NewArgs("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) {
try {if (trg_stream != null) trg_stream.close();}
catch (IOException e1) {}
throw Err_.new_wo_type(Err__server_connection_failed, "src", src_url, "err", e.toString());
throw ErrUtl.NewArgs(Err__server_connection_failed, "src", src_url, "err", e.toString());
}
// do downloading
@@ -91,7 +102,7 @@ public class Http_download_wkr__jre extends Http_download_wkr__base {
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_wo_type(Err__server_download_failed, "src", src_url, "trg_url", trg_url, "err", e.toString());
throw ErrUtl.NewArgs(Err__server_download_failed, "src", src_url, "trg_url", trg_url, "err", e.toString());
}
finally {
try {

View File

@@ -1,36 +1,37 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net.emails; import gplx.*; import gplx.core.*; import gplx.core.net.*;
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net.emails;
import gplx.langs.htmls.encoders.*;
import gplx.libs.logs.Gfo_log_;
import gplx.types.errs.ErrUtl;
import gplx.types.basics.utls.StringUtl;
import java.awt.Desktop;
import java.net.URI;
import java.net.URLDecoder;
import java.net.URLEncoder;
class Gfo_email_mgr__jre implements Gfo_email_mgr {
public void Send(String to, String subject, String body) {
try {
Gfo_url_encoder url_encoder = Gfo_url_encoder_.New__fsys_wnt().Make();
subject = url_encoder.Encode_str(subject);
body = url_encoder.Encode_str(body);
body = String_.Replace(body, "`", "%60");
body = StringUtl.Replace(body, "`", "%60");
String url_str = "mailto:gnosygnu+xowa_xolog@gmail.com?subject=" + subject + "&body=" + body;
URI uri = new URI(url_str);
Desktop.getDesktop().mail(uri);
} catch (Exception e) {
Gfo_log_.Instance.Warn("email failed", "subject", subject, "body", body, "err", Err_.Message_gplx_log(e));
Gfo_log_.Instance.Warn("email failed", "subject", subject, "body", body, "err", ErrUtl.ToStrLog(e));
}
}
}

View File

@@ -13,14 +13,16 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net.qargs; import gplx.*; import gplx.core.*; import gplx.core.net.*;
package gplx.core.net.qargs;
import gplx.types.basics.utls.BryUtl;
import gplx.types.basics.lists.Hash_adp_bry;
public class Gfo_qarg_enum_itm {
private final Hash_adp_bry hash = Hash_adp_bry.cs();
public Gfo_qarg_enum_itm(String key) {this.key = Bry_.new_u8(key);}
public Gfo_qarg_enum_itm(String key) {this.key = BryUtl.NewU8(key);}
public Gfo_qarg_enum_itm(byte[] key) {this.key = key;}
public byte[] Key() {return key;} private final byte[] key;
public Gfo_qarg_enum_itm Add(String key, int val) {
hash.Add_bry_int(Bry_.new_u8(key), val);
hash.Add_bry_int(BryUtl.NewU8(key), val);
return this;
}
public int Get_as_int_or(byte[] val, int or) {return hash.Get_as_int_or(val, or);}

View File

@@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net.qargs; import gplx.*; import gplx.core.*; import gplx.core.net.*;
package gplx.core.net.qargs;
import gplx.types.basics.lists.Hash_adp_bry;
public class Gfo_qarg_enum_mgr {
private final Hash_adp_bry hash = Hash_adp_bry.cs();
public Gfo_qarg_enum_mgr(Gfo_qarg_enum_itm... ary) {

View File

@@ -13,7 +13,12 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net.qargs; import gplx.*; import gplx.core.*; import gplx.core.net.*;
package gplx.core.net.qargs;
import gplx.types.basics.utls.BryUtl;
import gplx.types.errs.ErrUtl;
import gplx.types.basics.lists.Hash_adp_bry;
import gplx.types.basics.utls.IntUtl;
import gplx.types.basics.utls.StringUtl;
public class Gfo_qarg_mgr {
private final Hash_adp_bry hash = Hash_adp_bry.cs();
public Gfo_qarg_mgr Init(Gfo_qarg_itm[] args) {
@@ -25,34 +30,34 @@ public class Gfo_qarg_mgr {
}
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_fail(String key) {return Read_bry_or_fail(BryUtl.NewU8(key));}
public byte[] Read_bry_or_fail(byte[] key) {byte[] rv = Read_bry_or_null(key); if (rv == null) Fail_when_missing(StringUtl.NewU8(key)); return rv;}
public byte[] Read_bry_or_empty(byte[] key) {return Read_bry_or(key, BryUtl.Empty);}
public byte[] Read_bry_or_null(String key) {return Read_bry_or(BryUtl.NewU8(key), null);}
public byte[] Read_bry_or_null(byte[] key) {return Read_bry_or(key, null);}
public byte[] Read_bry_or(String key, byte[] or) {return Read_bry_or(Bry_.new_u8(key), or);}
public byte[] Read_bry_or(String key, byte[] or) {return Read_bry_or(BryUtl.NewU8(key), or);}
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_fail(String key) {String rv = Read_str_or_null(BryUtl.NewU8(key)); if (rv == null) Fail_when_missing(key); return rv;}
public String Read_str_or_null(String key) {return Read_str_or_null(BryUtl.NewU8(key));}
public String Read_str_or_null(byte[] key) {return Read_str_or(key, null);}
public String Read_str_or(String key, String or) {return Read_str_or(Bry_.new_u8(key), or);}
public String Read_str_or(String key, String or) {return Read_str_or(BryUtl.NewU8(key), or);}
public String Read_str_or(byte[] key, String or) {
Gfo_qarg_itm arg = (Gfo_qarg_itm)hash.Get_by_bry(key);
return arg == null ? or : String_.new_u8(arg.Val_bry());
return arg == null ? or : StringUtl.NewU8(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(String key, int or) {return Read_int_or(BryUtl.NewU8(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);
return val == null ? or : IntUtl.ParseOr(StringUtl.NewA7(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);}
private void Fail_when_missing(String key) {throw ErrUtl.NewArgs("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) {

View File

@@ -13,22 +13,31 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.net.qargs; import gplx.*;
package gplx.core.net.qargs;
import gplx.langs.htmls.encoders.*;
import gplx.objects.strings.AsciiByte;
import gplx.types.basics.utls.BryLni;
import gplx.types.basics.utls.BryUtl;
import gplx.types.custom.brys.wtrs.BryWtr;
import gplx.types.basics.lists.Hash_adp;
import gplx.types.basics.lists.Hash_adp_bry;
import gplx.types.basics.lists.List_adp;
import gplx.types.basics.lists.List_adp_;
import gplx.types.basics.utls.IntUtl;
import gplx.types.basics.constants.AsciiByte;
import gplx.types.basics.utls.StringUtl;
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.Len();}
public boolean Match(byte[] key, byte[] val) {
Gfo_qarg_itm arg = (Gfo_qarg_itm)hash.GetByOrNull(key);
return arg == null ? false : Bry_.Eq(val, arg.Val_bry());
return arg == null ? false : BryLni.Eq(val, arg.Val_bry());
}
public Gfo_qarg_itm Get_at(int i) {return (Gfo_qarg_itm)list.Get_at(i);}
public Gfo_qarg_itm Get_at(int i) {return (Gfo_qarg_itm)list.GetAt(i);}
public Gfo_qarg_itm Get_arg(byte[] key) {return (Gfo_qarg_itm)hash.GetByOrNull(key);}
public int Get_val_int_or(byte[] key, int or) {
byte[] val_bry = Get_val_bry_or(key, null); if (val_bry == null) return or;
return Bry_.To_int_or(val_bry, or);
return BryUtl.ToIntOr(val_bry, or);
}
public byte[] Get_val_bry_or(byte[] key, byte[] or) {
Gfo_qarg_itm arg = (Gfo_qarg_itm)hash.GetByOrNull(key);
@@ -36,13 +45,13 @@ public class Gfo_qarg_mgr_old {
}
public String Get_val_str_or(byte[] key, String or) {
Gfo_qarg_itm arg = (Gfo_qarg_itm)hash.GetByOrNull(key);
return arg == null ? or : String_.new_u8(arg.Val_bry());
return arg == null ? or : StringUtl.NewU8(arg.Val_bry());
}
public void Set_val_by_int(byte[] key, int val) {Set_val_by_bry(key, Bry_.new_a7(Int_.To_str(val)));}
public void Set_val_by_int(byte[] key, int val) {Set_val_by_bry(key, BryUtl.NewA7(IntUtl.ToStr(val)));}
public void Set_val_by_bry(byte[] key, byte[] val) {
Gfo_qarg_itm arg = (Gfo_qarg_itm)hash.GetByOrNull(key);
if (arg == null) {
arg = new Gfo_qarg_itm(key, Bry_.Empty);
arg = new Gfo_qarg_itm(key, BryUtl.Empty);
list.Add(arg);
hash.Add(key, arg);
}
@@ -60,43 +69,43 @@ public class Gfo_qarg_mgr_old {
return this;
}
public Gfo_qarg_itm[] To_ary() {return (Gfo_qarg_itm[])list.ToAry(Gfo_qarg_itm.class);}
public byte[] Concat(Bry_bfr bfr, byte[]... ary) {
public byte[] Concat(BryWtr bfr, byte[]... ary) {
int ary_len = ary.length;
for (int i = 0; i < ary_len; i++) {
byte[] key = ary[i];
Gfo_qarg_itm itm = Get_arg(key); if (itm == null) continue;
bfr.Add_byte(AsciiByte.Amp).Add(itm.Key_bry()).Add_byte(AsciiByte.Eq).Add(itm.Val_bry());
bfr.AddByte(AsciiByte.Amp).Add(itm.Key_bry()).AddByte(AsciiByte.Eq).Add(itm.Val_bry());
}
return bfr.To_bry_and_clear();
return bfr.ToBryAndClear();
}
public byte[] To_bry() {
int len = list.Len(); if (len == 0) return Bry_.Empty;
Bry_bfr bfr = Bry_bfr_.New();
int len = list.Len(); if (len == 0) return BryUtl.Empty;
BryWtr bfr = BryWtr.New();
To_bry(bfr, gplx.langs.htmls.encoders.Gfo_url_encoder_.Href, false);
return bfr.To_bry_and_clear();
return bfr.ToBryAndClear();
}
public void To_bry(Bry_bfr bfr, Gfo_url_encoder href_encoder, boolean encode) {
public void To_bry(BryWtr bfr, Gfo_url_encoder href_encoder, boolean encode) {
int len = list.Len(); if (len == 0) return;
for (int i = 0; i < len; ++i) {
Gfo_qarg_itm itm = (Gfo_qarg_itm)list.Get_at(i);
bfr.Add_byte(i == 0 ? AsciiByte.Question : AsciiByte.Amp);
Gfo_qarg_itm itm = (Gfo_qarg_itm)list.GetAt(i);
bfr.AddByte(i == 0 ? AsciiByte.Question : AsciiByte.Amp);
Write_or_encode(bfr, href_encoder, encode, itm.Key_bry());
bfr.Add_byte(AsciiByte.Eq);
bfr.AddByte(AsciiByte.Eq);
Write_or_encode(bfr, href_encoder, encode, itm.Val_bry());
}
}
public static void Concat_bfr(Bry_bfr bfr, Gfo_url_encoder href_encoder, Gfo_qarg_itm[] ary) {Concat_bfr(bfr, href_encoder, ary, true);}
private static void Concat_bfr(Bry_bfr bfr, Gfo_url_encoder href_encoder, Gfo_qarg_itm[] ary, boolean encode) {
public static void Concat_bfr(BryWtr bfr, Gfo_url_encoder href_encoder, Gfo_qarg_itm[] ary) {Concat_bfr(bfr, href_encoder, ary, true);}
private static void Concat_bfr(BryWtr bfr, Gfo_url_encoder href_encoder, Gfo_qarg_itm[] ary, boolean encode) {
int ary_len = ary.length;
for (int i = 0; i < ary_len; i++) {
Gfo_qarg_itm itm = ary[i];
bfr.Add_byte(i == 0 ? AsciiByte.Question : AsciiByte.Amp);
bfr.AddByte(i == 0 ? AsciiByte.Question : AsciiByte.Amp);
Write_or_encode(bfr, href_encoder, encode, itm.Key_bry());
bfr.Add_byte(AsciiByte.Eq);
bfr.AddByte(AsciiByte.Eq);
Write_or_encode(bfr, href_encoder, encode, itm.Val_bry());
}
}
private static void Write_or_encode(Bry_bfr bfr, Gfo_url_encoder href_encoder, boolean encode, byte[] bry) {
private static void Write_or_encode(BryWtr bfr, Gfo_url_encoder href_encoder, boolean encode, byte[] bry) {
if (bry == null) return; // NOTE: need null check b/c itm.Val_bry can be null
if (encode)
href_encoder.Encode(bfr, bry);

View File

@@ -1,19 +1,20 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.primitives; import gplx.*; import gplx.core.*;
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.primitives;
import gplx.types.basics.utls.BryUtl;
public class Bry_ary {
private byte[][] ary; private int len, max;
public Bry_ary(int max) {
@@ -45,7 +46,7 @@ public class Bry_ary {
public void Set_at_last(byte[] v) {ary[len - 1] = v;}
public void Set_at(int i, byte[] v) {ary[i] = v;}
public byte[][] To_ary(int rel) {
if (len == 0) return Bry_.Ary_empty;
if (len == 0) return BryUtl.AryEmpty;
int rv_len = len + rel;
byte[][] rv = new byte[rv_len][];
for (int i = 0; i < rv_len; ++i)

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