1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-04-05 21:00:31 -04:00
parent 80b9928b5c
commit 18dcd3f89e
615 changed files with 9826 additions and 8619 deletions

View File

@@ -24,7 +24,8 @@ public class Err_ { //_20110415
public static Err new_(String hdr) {return Err.hdr_(hdr);}
public static Err new_key_(String key, String hdr) {return Err.hdr_(hdr).Key_(key);}
public static Err err_key_(Exception exc, String key, String hdr) {return Err.exc_(exc, hdr).Key_(key);}
public static Err err_(Exception exc, String hdr) {return Err.exc_(exc, hdr);}
public static Err err_(Exception e) {return Err.exc_(e, Message_gplx_brief(e));}
public static Err err_(Exception e, String hdr) {return Err.exc_(e, hdr);}
public static Err err_(Exception e, String fmt, Object... args) {return Err.exc_(e, String_.Format(fmt, args));}
public static Err cast_(Exception ignore, Class<?> t, Object o) {
String o_str = "";

View File

@@ -50,11 +50,16 @@ public class Array_ {
rv[i + newLen] = cur[i];
return rv;
}
public static Object Resize(Object src, int trgLen) {
Object trg = Create(ComponentType(src), trgLen);
int srcLen = Array.getLength(src);
int copyLen = srcLen > trgLen ? trgLen : srcLen; // trgLen can either expand or shrink
CopyTo(src, 0, trg, 0, copyLen);
public static Object Resize_add_one(Object src, int src_len, Object new_obj) {
Object rv = Resize(src, src_len + 1);
Set(rv, src_len, new_obj);
return rv;
}
public static Object Resize(Object src, int trg_len) {
Object trg = Create(ComponentType(src), trg_len);
int src_len = Array.getLength(src);
int copy_len = src_len > trg_len ? trg_len : src_len; // trg_len can either expand or shrink
CopyTo(src, 0, trg, 0, copy_len);
return trg;
}
public static String XtoStr(Object ary) {

View File

@@ -18,26 +18,50 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx;
import gplx.core.primitives.*;
public class Bry_bfr {
private Bry_bfr_mkr_mgr mkr_mgr; private int reset;
public byte[] Bfr() {return bfr;} private byte[] bfr;
@gplx.Internal protected int Bfr_max() {return bfr_max;} private int bfr_max;
public int Len() {return bfr_len;} private int bfr_len;
public boolean Len_eq_0() {return bfr_len == 0;}
public boolean Len_gt_0() {return bfr_len > 0;}
public void Bfr_init(byte[] bfr, int bfr_len) {
this.bfr = bfr;
this.bfr_len = bfr_len;
this.bfr_max = bfr.length; // NOTE: must sync bfr_max, else will fail later during add; bfr will think bfr has .length of bfr_max, when it actually has .length of bfr_len; DATE:2014-03-09
synchronized (this) {
this.bfr = bfr;
this.bfr_len = bfr_len;
this.bfr_max = bfr.length; // NOTE: must sync bfr_max, else will fail later during add; bfr will think bfr has .length of bfr_max, when it actually has .length of bfr_len; DATE:2014-03-09
}
}
@gplx.Internal protected int Mkr_itm() {return mkr_itm;} private int mkr_itm = -1;
@gplx.Internal protected Bry_bfr_mkr_mgr Mkr_mgr() {return mkr_mgr;} Bry_bfr_mkr_mgr mkr_mgr;
@gplx.Internal protected Bry_bfr Mkr_(Bry_bfr_mkr_mgr mkr_mgr, int itm) {this.mkr_mgr = mkr_mgr; this.mkr_itm = itm; return this;}
public Bry_bfr Mkr_rls() {mkr_mgr.Rls(this); return this;}
private void Mkr_clear() {
if (mkr_mgr != null) mkr_mgr.Rls(this);
mkr_mgr = null;
mkr_itm = -1;
public Bry_bfr Mkr_rls() {
if (mkr_mgr != null) {
synchronized (mkr_mgr) {
mkr_mgr.Rls(mkr_idx);
}
synchronized (this) {
this.mkr_mgr = null;
this.mkr_idx = -1;
}
}
return this;
}
private Bry_bfr Reset_(int v) {reset = v; return this;} private int reset;
public void Clear_and_rls() {
this.Clear();
this.Mkr_rls();
}
public String To_str_and_rls() {return String_.new_utf8_(To_bry_and_rls());}
public byte[] To_bry_and_rls() {
byte[] rv = null;
synchronized (bfr) {
rv = Xto_bry();
this.Clear();
if (reset > 0) Reset_if_gt(reset);
synchronized (mkr_mgr) {
mkr_mgr.Rls(mkr_idx);
}
mkr_mgr = null;
mkr_idx = -1;
}
return rv;
}
private Bry_bfr Reset_(int v) {reset = v; return this;}
public Bry_bfr Reset_if_gt(int limit) {
if (bfr_max > limit) {
this.bfr_max = limit;
@@ -46,7 +70,12 @@ public class Bry_bfr {
bfr_len = 0;
return this;
}
public Bry_bfr Clear() {bfr_len = 0; return this;}
public Bry_bfr Clear() {
synchronized (this) {
this.bfr_len = 0;
}
return this;
}
public Bry_bfr ClearAndReset() {bfr_len = 0; if (reset > 0) Reset_if_gt(reset); return this;}
public byte Get_at_last_or_nil_if_empty() {return bfr_len == 0 ? Byte_ascii.Nil : bfr[bfr_len - 1];}
public Bry_bfr Add_safe(byte[] val) {return val == null ? this : Add(val);}
@@ -491,7 +520,7 @@ public class Bry_bfr {
}
public void Rls() {
bfr = null;
Mkr_clear();
this.Mkr_rls();
}
@Override public int hashCode() {return Bry_obj_ref.CalcHashCode(bfr, 0, bfr_len);}
@Override public boolean equals(Object obj) {return obj == null ? false : Bry_.Match(bfr, 0, bfr_len, ((Bry_obj_ref)obj).Val());} // NOTE: strange, but null check needed; throws null error; PAGE:c:File:Eug<75>ne_Delacroix_-_La_libert<72>_guidant_le_peuple.jpg
@@ -499,6 +528,15 @@ public class Bry_bfr {
bfr_max = v;
bfr = Bry_.Resize(bfr, 0, v);
}
@gplx.Internal protected int Mkr_idx() {return mkr_idx;} private int mkr_idx = -1;
@gplx.Internal protected boolean Mkr_idx_is_null() {return mkr_idx == -1;}
@gplx.Internal protected int Bfr_max() {return bfr_max;} private int bfr_max;
@gplx.Internal protected Bry_bfr Mkr_init(Bry_bfr_mkr_mgr mkr_mgr, int itm) {
synchronized (this) {
this.mkr_mgr = mkr_mgr; this.mkr_idx = itm;
}
return this;
}
public static Bry_bfr new_() {return new Bry_bfr(16);}
public static Bry_bfr new_(int v) {return new Bry_bfr(v);}
public static Bry_bfr reset_(int v) {return new Bry_bfr(16).Reset_(v);} // PERF: set initial size to 16, not reset val; allows for faster "startup"; DATE:2014-06-14

View File

@@ -24,7 +24,8 @@ public class Bry_bfr_mkr {
public Bry_bfr Get_k004() {return mkr_k004.Get();}
public Bry_bfr Get_m001() {return mkr_m001.Get();}
public void Rls(Bry_bfr v) {
v.Mkr_mgr().Rls(v);
v.Mkr_rls();
// v.Mkr_mgr().Rls(v);
}
public void Reset_if_gt(int v) {
for (byte i = Tid_b128; i <= Tid_m001; i++)
@@ -71,7 +72,7 @@ class Bry_bfr_mkr_mgr {
for (int i = 0; i < ary_max; i++) {
Bry_bfr itm = ary[i];
if (itm != null) {
if (itm.Mkr_mgr() != null) throw Err_.new_("failed to clear bfr: " + Int_.Xto_str(i));
if (!itm.Mkr_idx_is_null()) throw Err_.new_("failed to clear bfr: " + Int_.Xto_str(i));
itm.Clear();
}
ary[i] = null;
@@ -117,7 +118,7 @@ class Bry_bfr_mkr_mgr {
ary[rv_idx] = rv;
}
}
rv.Mkr_(this, rv_idx);
rv.Mkr_init(this, rv_idx);
return rv.Clear(); // NOTE: ALWAYS call Clear when doing Get. caller may forget to call Clear, and reused bfr may have leftover bytes. unit tests will not catch, and difficult to spot in app
}
}
@@ -131,16 +132,26 @@ class Bry_bfr_mkr_mgr {
Array_.CopyTo(free, 0, new_free, 0, free_len);
free = new_free;
}
public void Rls(Bry_bfr v) {
// public void Rls(Bry_bfr v) {
// synchronized (thread_lock) {
// int idx = v.Mkr_itm();
// if (idx == -1) throw Err_mgr._.fmt_("gplx.Bry_bfr", "rls_failed", "rls called on bfr that was not created by factory");
// int new_ary_len = nxt_idx - 1;
// if (idx == new_ary_len)
// nxt_idx = new_ary_len;
// else
// free[free_len++] = idx;
// v.Mkr_(null, -1);
// }
// }
public void Rls(int idx) {
synchronized (thread_lock) {
int idx = v.Mkr_itm();
if (idx == -1) throw Err_mgr._.fmt_("gplx.Bry_bfr", "rls_failed", "rls called on bfr that was not created by factory");
int new_ary_len = nxt_idx - 1;
if (idx == new_ary_len)
nxt_idx = new_ary_len;
else
free[free_len++] = idx;
v.Mkr_(null, -1);
}
}
public static final Bry_bfr[] Ary_empty = new Bry_bfr[0];

View File

@@ -56,7 +56,7 @@ class Bry_bfr_mkr_fxt {
}
public Bry_bfr_mkr_fxt Rls(int i) {
Bry_bfr bfr = mkr.Ary()[i];
mkr.Rls(bfr);
bfr.Mkr_rls();
return this;
}
public Bry_bfr_mkr_fxt Tst_idxs(int... expd) {
@@ -65,7 +65,7 @@ class Bry_bfr_mkr_fxt {
for (int i = 0; i < actl_len; i++) {
Bry_bfr bfr = mkr.Ary()[i];
int actl_val = Bry_bfr_mkr_tst.Int_null;
if (bfr != null) actl_val = bfr.Mkr_itm();
if (bfr != null) actl_val = bfr.Mkr_idx();
actl[i] = actl_val;
}
Tfds.Eq_ary(expd, actl);

View File

@@ -134,9 +134,9 @@ public class Int_ implements GfoInvkAble {
if (val < 0) throw Err_.new_("key must be >= 0").Add("key", key).Add("val", val);
return this;
}
public static String Xto_str_pad_bgn_space(int v, int reqdPlaces) {return Xto_str_pad_bgn(v, reqdPlaces, Byte_ascii.Space, true);} // EX: 1, 3 returns " 1"
public static String Xto_str_pad_bgn(int v, int reqdPlaces) {return Xto_str_pad_bgn(v, reqdPlaces, Byte_ascii.Num_0, true);} // EX: 1, 3 returns "001"
static String Xto_str_pad_bgn(int val, int places, byte pad_chr, boolean bgn) {
public static String Xto_str_pad_bgn_space(int v, int reqdPlaces) {return Xto_str_pad_bgn_zero(v, reqdPlaces, Byte_ascii.Space, true);} // EX: 1, 3 returns " 1"
public static String Xto_str_pad_bgn_zero(int v, int reqdPlaces) {return Xto_str_pad_bgn_zero(v, reqdPlaces, Byte_ascii.Num_0, true);} // EX: 1, 3 returns "001"
static String Xto_str_pad_bgn_zero(int val, int places, byte pad_chr, boolean bgn) {
int len = DigitCount(val);
int pad_len = places - len; if (pad_len < 0) return Int_.Xto_str(val);
Bry_bfr bfr = Bry_bfr.new_();
@@ -165,7 +165,7 @@ public class Int_ implements GfoInvkAble {
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_XtoStr_PadBgn)) {
int v = m.ReadInt(GfsCore_.Arg_primitive), pad = m.ReadInt("pad");
return ctx.Deny() ? (Object)this : Xto_str_pad_bgn(v, pad);
return ctx.Deny() ? (Object)this : Xto_str_pad_bgn_zero(v, pad);
}
else if (ctx.Match(k, "Add")) {
int v = m.ReadInt(GfsCore_.Arg_primitive), operand = m.ReadInt("operand");
@@ -204,10 +204,11 @@ public class Int_ implements GfoInvkAble {
if (rvLen < 8) rv = String_.Repeat("0", 8 - rvLen) + rv;
return String_.Upper(rv);
}
public static String Xto_str(int[] ary) {
public static String Xto_str(int[] ary) {return Xto_str(ary, " ");}
public static String Xto_str(int[] ary, String dlm) {
String_bldr sb = String_bldr_.new_();
for (int i = 0; i < ary.length; i++)
sb.Add_spr_unless_first(Int_.Xto_str(ary[i]), " ", i);
sb.Add_spr_unless_first(Int_.Xto_str(ary[i]), dlm, i);
return sb.XtoStr();
}
public static int[] Ary_parse(String raw_str, int reqd_len, int[] or) {

View File

@@ -26,7 +26,7 @@ public class Int__tst {
tst_XtoStr_PadLeft_Zeroes(-12 , 3, "-12"); // negative
tst_XtoStr_PadLeft_Zeroes(-123 , 3, "-123"); // negative
tst_XtoStr_PadLeft_Zeroes(-1234 , 3, "-1234"); // negative
} void tst_XtoStr_PadLeft_Zeroes(int val, int zeros, String expd) {Tfds.Eq(expd, Int_.Xto_str_pad_bgn(val, zeros));}
} void tst_XtoStr_PadLeft_Zeroes(int val, int zeros, String expd) {Tfds.Eq(expd, Int_.Xto_str_pad_bgn_zero(val, zeros));}
@Test public void parseOr_() {
tst_ParseOr("", -1); // empty
tst_ParseOr("123", 123); // single

View File

@@ -25,6 +25,7 @@ import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
public class DateAdp_ implements GfoInvkAble {
public static final String Cls_ref_name = "Date";
public static final Class<?> Cls_ref_type = DateAdp.class;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_Now)) return Now();

View File

@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public class UuidAdp {
public class Guid_adp {
public String XtoStr() {return guid.toString();}
public UuidAdp(java.util.UUID guid) {this.guid = guid;} java.util.UUID guid;
public Guid_adp(java.util.UUID guid) {this.guid = guid;} java.util.UUID guid;
}

View File

@@ -16,8 +16,9 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public class UuidAdp_ {
public static final UuidAdp Null = parse_("00000000-0000-0000-0000-000000000000");
public static UuidAdp random_() {return new UuidAdp(java.util.UUID.randomUUID());}
public static UuidAdp parse_(String s) {return new UuidAdp(java.util.UUID.fromString(s));}
public class Guid_adp_ {
public static final String Cls_ref_name = "Guid";
public static final Guid_adp Empty = parse_("00000000-0000-0000-0000-000000000000");
public static Guid_adp random_() {return new Guid_adp(java.util.UUID.randomUUID());}
public static Guid_adp parse_(String s) {return new Guid_adp(java.util.UUID.fromString(s));}
}

View File

@@ -17,12 +17,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
import org.junit.*;
public class UuidAdp__tst {
public class Guid_adp__tst {
@Test public void parse_() {
tst_parse_("467ffb41-cdfe-402f-b22b-be855425784b");
}
void tst_parse_(String s) {
UuidAdp uuid = UuidAdp_.parse_(s);
Guid_adp uuid = Guid_adp_.parse_(s);
Tfds.Eq(uuid.XtoStr(), s);
}
}

View File

@@ -116,7 +116,7 @@ public class TimeSpanAdp_ {
zeros = first && !fmt_padZeros ? 1 : padZerosAry[i]; // if first, don't zero pad (avoid "01")
dlm = first ? "" : Sprs[i]; // if first, don't use dlm (avoid ":01")
sb.Add(dlm);
sb.Add(Int_.Xto_str_pad_bgn(val, zeros));
sb.Add(Int_.Xto_str_pad_bgn_zero(val, zeros));
first = false;
}
return sb.XtoStr();

View File

@@ -18,6 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx;
public class Yn {
public static final String Y = "y", N = "n";
public static boolean parse_by_char_or(String v, boolean or) {
if (String_.Eq(v, Y)) return true;
else if (String_.Eq(v, N)) return false;
else return or;
}
public static boolean parse_or_n_(String v) {return parse_or_(v, false);}
public static int parse_as_int(String v) {
if (v == null) return Bool_.__int;

View File

@@ -65,7 +65,7 @@ public class OrderedHash_base extends HashAdp_base implements OrderedHash, GfoIn
int count = ordered.Count();
int pad = String_.Len(Int_.Xto_str(count));
for (int i = 0; i < count; i++) {
sb .Add(Int_.Xto_str_pad_bgn(i, pad))
sb .Add(Int_.Xto_str_pad_bgn_zero(i, pad))
.Add(":").Add(ordered.FetchAt(i).toString())
.Add(Op_sys.Cur().Nl_str());
}

View File

@@ -50,6 +50,10 @@ public class Io_mgr { // exists primarily to gather all cmds under gplx namespac
}
return false;
}
public void Create_fil_ary(Io_fil[] fil_ary) {
for (Io_fil fil : fil_ary)
SaveFilStr(fil.Url(), fil.Data());
}
public Io_url[] QueryDir_fils(Io_url dir) {return QueryDir_args(dir).ExecAsUrlAry();}
public IoEngine_xrg_queryDir QueryDir_args(Io_url dir) {return IoEngine_xrg_queryDir.new_(dir);}
public void DeleteDirSubs(Io_url url) {IoEngine_xrg_deleteDir.new_(url).Exec();}
@@ -133,5 +137,6 @@ public class Io_mgr { // exists primarily to gather all cmds under gplx namespac
public IoEngine_xrg_downloadFil DownloadFil_args(String src, Io_url trg) {return IoEngine_xrg_downloadFil.new_(src, trg);}
public static final Io_mgr _ = new Io_mgr(); public Io_mgr() {}
public static final int Len_kb = 1024, Len_mb = 1048576, Len_gb = 1073741824, Len_gb_2 = 2147483647;
public static final long Len_mb_long = Len_mb;
public static final long Len_null = -1;
}

View File

@@ -542,7 +542,7 @@ class Io_stream_rdr_http implements Io_stream_rdr {
public Io_stream_rdr_http(IoEngine_xrg_downloadFil xrg) {
this.xrg = xrg;
} private IoEngine_xrg_downloadFil xrg;
public byte Tid() {return Io_stream_.Tid_file;}
public byte Tid() {return Io_stream_.Tid_raw;}
public Io_url Url() {return url;} public Io_stream_rdr Url_(Io_url v) {url = v; return this;} private Io_url url;
public long Len() {return len;} public Io_stream_rdr Len_(long v) {len = v; return this;} private long len = IoItmFil.Size_invalid; // NOTE: must default size to -1; DATE:2014-06-21
private String src_str; private HttpURLConnection src_conn; private java.io.BufferedInputStream src_stream;

View File

@@ -22,7 +22,7 @@ public class IoEngine_xrg_recycleFil extends IoEngine_xrg_fil_affects1_base {
public int Mode() {return mode;} public IoEngine_xrg_recycleFil Mode_(int v) {mode = v; return this;} int mode;
public String AppName() {return appName;} public IoEngine_xrg_recycleFil AppName_(String val) {appName = val; return this;} private String appName = "unknown_app";
public UuidAdp Uuid() {return uuid;} public IoEngine_xrg_recycleFil Uuid_(UuidAdp val) {uuid = val; return this;} UuidAdp uuid;
public Guid_adp Uuid() {return uuid;} public IoEngine_xrg_recycleFil Uuid_(Guid_adp val) {uuid = val; return this;} Guid_adp uuid;
public boolean Uuid_include() {return uuid_include;} public IoEngine_xrg_recycleFil Uuid_include_() {uuid_include = true; return this;} private boolean uuid_include;
public DateAdp Time() {return time;} public IoEngine_xrg_recycleFil Time_(DateAdp val) {time = val; return this;} DateAdp time;
public ListAdp RootDirNames() {return rootDirNames;} public IoEngine_xrg_recycleFil RootDirNames_(ListAdp val) {rootDirNames = val; return this;} ListAdp rootDirNames;
@@ -49,7 +49,7 @@ public class IoEngine_xrg_recycleFil extends IoEngine_xrg_fil_affects1_base {
public IoEngine_xrg_recycleFil(int v) {
mode = v;
time = DateAdp_.Now();
uuid = UuidAdp_.random_();
uuid = Guid_adp_.random_();
rootDirNames = ListAdp_.new_(); rootDirNames.Add("z_trash");
}
public static IoEngine_xrg_recycleFil sysm_(Io_url url) {return new IoEngine_xrg_recycleFil(SysmConst);}

View File

@@ -0,0 +1,38 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
public class Io_fil implements gplx.CompareAble {
public Io_fil(Io_url url, String data) {this.url = url; this.data = data;}
public Io_url Url() {return url;} public Io_fil Url_(Io_url v) {url = v; return this;} Io_url url;
public String Data() {return data;} public Io_fil Data_(String v) {data = v; return this;} private String data;
public int compareTo(Object obj) {
return gplx.CompareAble_.Compare(url.Raw(), ((Io_fil)obj).Url().Raw());
}
public static Io_fil[] new_ary_(Io_url[] url_ary) {
int url_ary_len = url_ary.length;
Io_fil[] rv = new Io_fil[url_ary_len];
for (int i = 0; i < url_ary_len; i++) {
Io_url url = url_ary[i];
String data = Io_mgr._.LoadFilStr(url);
Io_fil fil = new Io_fil(url, data);
rv[i] = fil;
}
return rv;
}
public static final Io_fil[] Ary_empty = new Io_fil[0];
}

View File

@@ -0,0 +1,24 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
public class Io_fil_mkr {
private final ListAdp list = ListAdp_.new_();
public Io_fil_mkr Add(String url, String data) {return Add(Io_url_.mem_fil_(url), data);}
public Io_fil_mkr Add(Io_url url, String data) {list.Add(new Io_fil(url, data)); return this;}
public Io_fil[] To_ary() {return (Io_fil[])list.Xto_ary(Io_fil.class);}
}

View File

@@ -91,6 +91,9 @@ public class Io_size_ {
long rv = parse_or_(v, Long_.MinValue); if (rv == Long_.MinValue) throw Err_.new_fmt_("invalid val: {0}", v);
return rv;
}
public static String To_str_mb(long v) {return Long_.Xto_str(v / Io_mgr.Len_mb_long);}
public static long To_long_by_msg_mb(GfoMsg m) {return m.ReadLong("v") * Io_mgr.Len_mb_long;}
public static long To_long_by_int_mb(int v) {return (long)v * Io_mgr.Len_mb_long;}
}
class Io_size_fmtr_arg implements Bry_fmtr_arg {
public long Val() {return val;} public Io_size_fmtr_arg Val_(long v) {val = v; return this;} long val;

View File

@@ -17,6 +17,39 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
public class Io_stream_ { // SERIALIZED
public static final byte Tid_null = 0, Tid_file = 1, Tid_zip = 2, Tid_gzip = 3, Tid_bzip2 = 4;
public static final byte Tid_null = 0, Tid_raw = 1, Tid_zip = 2, Tid_gzip = 3, Tid_bzip2 = 4;
public static final String Ext_zip = ".zip", Ext_gz = ".gz", Ext_bz2 = ".bz2";
public static String Obsolete_to_str(byte v) {
switch (v) {
case Io_stream_.Tid_raw : return ".xdat";
case Io_stream_.Tid_zip : return ".zip";
case Io_stream_.Tid_gzip : return ".gz";
case Io_stream_.Tid_bzip2 : return ".bz2";
default : throw Err_.unhandled(v);
}
}
public static byte Obsolete_to_tid(String v) {
if (String_.Eq(v, ".xdat")) return Io_stream_.Tid_raw;
else if (String_.Eq(v, ".zip")) return Io_stream_.Tid_zip;
else if (String_.Eq(v, ".gz")) return Io_stream_.Tid_gzip;
else if (String_.Eq(v, ".bz2")) return Io_stream_.Tid_bzip2;
else throw Err_.unhandled(v);
}
public static String To_str(byte v) {
switch (v) {
case Io_stream_.Tid_raw : return "raw";
case Io_stream_.Tid_zip : return "zip";
case Io_stream_.Tid_gzip : return "gzip";
case Io_stream_.Tid_bzip2 : return "bzip2";
default : throw Err_.unhandled(v);
}
}
public static byte To_tid(String v) {
if (String_.Eq(v, "raw")) return Io_stream_.Tid_raw;
else if (String_.Eq(v, "zip")) return Io_stream_.Tid_zip;
else if (String_.Eq(v, "gzip")) return Io_stream_.Tid_gzip;
else if (String_.Eq(v, "bzip2")) return Io_stream_.Tid_bzip2;
else throw Err_.unhandled(v);
}
}

View File

@@ -31,7 +31,7 @@ public class Io_stream_rdr_ {
}
public static Io_stream_rdr new_by_tid_(byte tid) {
switch (tid) {
case Io_stream_.Tid_file: return new Io_stream_rdr_file();
case Io_stream_.Tid_raw: return new Io_stream_rdr_file();
case Io_stream_.Tid_zip: return new Io_stream_rdr_zip();
case Io_stream_.Tid_gzip: return new Io_stream_rdr_gzip();
case Io_stream_.Tid_bzip2: return new Io_stream_rdr_bzip2();
@@ -124,7 +124,7 @@ class Io_stream_rdr_adp implements Io_stream_rdr {
private java.io.InputStream strm;
public Io_stream_rdr_adp(java.io.InputStream strm) {this.strm = strm;}
public Object Under() {return strm;}
public byte Tid() {return Io_stream_.Tid_file;}
public byte Tid() {return Io_stream_.Tid_raw;}
public Io_url Url() {return url;} public Io_stream_rdr Url_(Io_url v) {this.url = v; return this;} private Io_url url;
public long Len() {return len;} public Io_stream_rdr Len_(long v) {len = v; return this;} private long len = Io_mgr.Len_null;
public void Open_mem(byte[] v) {}
@@ -172,7 +172,7 @@ abstract class Io_stream_rdr_base implements Io_stream_rdr {
public abstract java.io.InputStream Wrap_stream(java.io.InputStream stream);
}
class Io_stream_rdr_file extends Io_stream_rdr_base {
@Override public byte Tid() {return Io_stream_.Tid_file;}
@Override public byte Tid() {return Io_stream_.Tid_raw;}
public Io_stream_rdr Open() {
try {
if (!Io_mgr._.Exists(url))

View File

@@ -35,7 +35,7 @@ public class Io_stream_wtr_ {
}
public static Io_stream_wtr new_by_tid_(byte v) {
switch (v) {
case gplx.ios.Io_stream_.Tid_file : return new Io_stream_wtr_file();
case gplx.ios.Io_stream_.Tid_raw : return new Io_stream_wtr_file();
case gplx.ios.Io_stream_.Tid_zip : return new Io_stream_wtr_zip();
case gplx.ios.Io_stream_.Tid_gzip : return new Io_stream_wtr_gzip();
case gplx.ios.Io_stream_.Tid_bzip2 : return new Io_stream_wtr_bzip2();
@@ -172,7 +172,7 @@ class Io_stream_wtr_zip implements Io_stream_wtr {
}
class Io_stream_wtr_file implements Io_stream_wtr {
IoStream bry_stream;
@Override public byte Tid() {return Io_stream_.Tid_file;}
@Override public byte Tid() {return Io_stream_.Tid_raw;}
public Io_url Url() {return url;} public Io_stream_wtr Url_(Io_url v) {url = v; return this;} Io_url url;
public void Trg_bfr_(Bry_bfr v) {trg_bfr = v;} private Bry_bfr trg_bfr; java.io.ByteArrayOutputStream mem_stream;
public Io_stream_wtr Open() {

View File

@@ -45,8 +45,14 @@ public class Op_sys {
public static final Op_sys Drd = new_unx_flavor_(Tid_drd, "windows", Bitness_32);
public static final Op_sys Wnt = new_wnt_(Sub_tid_unknown, Bitness_32);
public static Op_sys Cur() {return cur_op_sys;} static Op_sys cur_op_sys = new_auto_identify_();
static Op_sys new_wnt_(byte bitness, byte sub_tid) {return new Op_sys(Tid_wnt , sub_tid , "windows", bitness, "\r\n", Byte_ascii.Backslash , Bool_.N, new byte[] {Byte_ascii.Slash, Byte_ascii.Backslash, Byte_ascii.Lt, Byte_ascii.Gt, Byte_ascii.Colon, Byte_ascii.Pipe, Byte_ascii.Question, Byte_ascii.Asterisk, Byte_ascii.Quote});}
static Op_sys new_unx_flavor_(byte tid, String os_name, byte bitness) {return new Op_sys(tid , Sub_tid_unknown , os_name , bitness, "\n" , Byte_ascii.Slash , Bool_.Y, new byte[] {Byte_ascii.Slash});}
public static String Fsys_path_to_lnx(String v) {
return cur_op_sys.Tid_is_wnt() ? String_.Replace(v, Wnt.fsys_dir_spr_str, Lnx.fsys_dir_spr_str) : v;
}
public static String Fsys_path_to_wnt(String v) {
return cur_op_sys.Tid_is_wnt() ? String_.Replace(v, Lnx.fsys_dir_spr_str, Wnt.fsys_dir_spr_str) : v;
}
private static Op_sys new_wnt_(byte bitness, byte sub_tid) {return new Op_sys(Tid_wnt , sub_tid , "windows", bitness, "\r\n", Byte_ascii.Backslash , Bool_.N, new byte[] {Byte_ascii.Slash, Byte_ascii.Backslash, Byte_ascii.Lt, Byte_ascii.Gt, Byte_ascii.Colon, Byte_ascii.Pipe, Byte_ascii.Question, Byte_ascii.Asterisk, Byte_ascii.Quote});}
private static Op_sys new_unx_flavor_(byte tid, String os_name, byte bitness) {return new Op_sys(tid , Sub_tid_unknown , os_name , bitness, "\n" , Byte_ascii.Slash , Bool_.Y, new byte[] {Byte_ascii.Slash});}
static final String GRP_KEY = "gplx.op_sys";
// public static Op_sys Cur_() {cur_op_sys = new_auto_identify_(); return cur_op_sys;}
static Op_sys new_auto_identify_() {

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public class Gfo_usr_dlg_ {
public static Gfo_usr_dlg _ = Gfo_usr_dlg_null._;
public static Gfo_usr_dlg I = Gfo_usr_dlg_null._;
public static final Gfo_usr_dlg Null = Gfo_usr_dlg_null._;
}
class Gfo_usr_dlg_null implements Gfo_usr_dlg {

View File

@@ -207,14 +207,14 @@ class TfdsMsgBldr {
for (int i = 0; i < list.Count(); i++) {
TfdsEqAryItm itm = (TfdsEqAryItm)list.FetchAt(i);
sb.Add_fmt_line("{0}: {1} {2} {3}"
, Int_.Xto_str_pad_bgn(itm.Idx(), 4)
, Int_.Xto_str_pad_bgn_zero(itm.Idx(), 4)
, String_.PadBgn(itm.Lhs(), lhsLenMax, " ")
, itm.Eq() ? "==" : "!="
, String_.PadBgn(itm.Rhs(), rhsLenMax, " ")
);
}
// String compSym = isEq ? " " : "!=";
// String result = String_.Format("{0}: {1}{2} {3} {4}", Int_.Xto_str_pad_bgn(i, 4), lhsString, String_.CrLf + "\t\t", compSym, rhsString);
// String result = String_.Format("{0}: {1}{2} {3} {4}", Int_.Xto_str_pad_bgn_zero(i, 4), lhsString, String_.CrLf + "\t\t", compSym, rhsString);
// foreach (Object obj in list) {
// String itmComparison = (String)obj;
// sb.Add_fmt_line("{0}{1}", "\t\t", itmComparison);

View File

@@ -45,7 +45,7 @@ public class IoEngine_fil_basic_memory_tst extends IoEngine_fil_basic_base {
list.DelAt(0); // remove drive
IoEngine_xrg_recycleFil recycleXrg = bin.Send_xrg(fil)
.RootDirNames_(list)
.AppName_("gplx.test").Time_(DateAdp_.parse_gplx("20100102_115559123")).Uuid_(UuidAdp_.parse_("467ffb41-cdfe-402f-b22b-be855425784b"));
.AppName_("gplx.test").Time_(DateAdp_.parse_gplx("20100102_115559123")).Uuid_(Guid_adp_.parse_("467ffb41-cdfe-402f-b22b-be855425784b"));
recycleXrg.Exec();
fx.tst_ExistsPaths(false, fil);
fx.tst_ExistsPaths(true, recycleXrg.RecycleUrl());

View File

@@ -37,7 +37,7 @@ public class IoEngine_fil_basic_system_tst extends IoEngine_fil_basic_base {
ListAdp list = root.XtoNames(); list.DelAt(0); // remove drive
IoEngine_xrg_recycleFil recycleXrg = bin.Send_xrg(fil)
.RootDirNames_(list)
.AppName_("gplx.test").Time_(DateAdp_.parse_gplx("20100102_115559123")).Uuid_(UuidAdp_.parse_("467ffb41-cdfe-402f-b22b-be855425784b"));
.AppName_("gplx.test").Time_(DateAdp_.parse_gplx("20100102_115559123")).Uuid_(Guid_adp_.parse_("467ffb41-cdfe-402f-b22b-be855425784b"));
recycleXrg.Exec();
fx.tst_ExistsPaths(false, fil);
fx.tst_ExistsPaths(true, recycleXrg.RecycleUrl());

View File

@@ -25,7 +25,7 @@ public class IoEngine_xrg_recycleFil_tst {
tst_GenRecycleUrl(recycle_(), Io_url_.mem_fil_("mem/z_trash/20100102/gplx.images;115559123;;fil.txt"));
tst_GenRecycleUrl(recycle_().Uuid_include_(), Io_url_.mem_fil_("mem/z_trash/20100102/gplx.images;115559123;467ffb41-cdfe-402f-b22b-be855425784b;fil.txt"));
}
IoEngine_xrg_recycleFil recycle_() {return IoEngine_xrg_recycleFil.gplx_(Io_url_.mem_fil_("mem/dir/fil.txt")).AppName_("gplx.images").Uuid_(UuidAdp_.parse_("467ffb41-cdfe-402f-b22b-be855425784b")).Time_(DateAdp_.parse_gplx("20100102_115559123"));}
IoEngine_xrg_recycleFil recycle_() {return IoEngine_xrg_recycleFil.gplx_(Io_url_.mem_fil_("mem/dir/fil.txt")).AppName_("gplx.images").Uuid_(Guid_adp_.parse_("467ffb41-cdfe-402f-b22b-be855425784b")).Time_(DateAdp_.parse_gplx("20100102_115559123"));}
void tst_GenRecycleUrl(IoEngine_xrg_recycleFil xrg, Io_url expd) {
Tfds.Eq(expd, xrg.RecycleUrl());
}