v3.3.4 v2.7.3.1
gnosygnu 9 years ago
parent 794b5a232f
commit 8e041d6e06

@ -10,7 +10,6 @@
<classpathentry kind="src" path="src_160_hash"/>
<classpathentry kind="src" path="src_200_io"/>
<classpathentry kind="src" path="src_210_env"/>
<classpathentry kind="src" path="src_220_console"/>
<classpathentry kind="src" path="src_300_classXtn"/>
<classpathentry kind="src" path="src_310_gfoNde"/>
<classpathentry kind="src" path="src_311_gfoObj"/>

@ -0,0 +1,77 @@
/*
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;
public class Err extends RuntimeException {
private final boolean is_gplx;
private final String trace;
private Err_msg[] msgs_ary = new Err_msg[8]; private int msgs_len = 8, msgs_idx = 0;
public Err(boolean is_gplx, String trace, String type, String msg, Object... args) {
this.is_gplx = is_gplx;
this.trace = is_gplx ? Err_.Trace_lang(this) : trace; // NOTE: Err_ factory methods pass in null stack trace for gplx excs; call Stack_trace here, note that trace will not show constructor
Msgs_add(type, msg, args);
}
public int Trace_ignore() {return trace_ignore;} public Err Trace_ignore_add_1_() {++trace_ignore; return this;} private int trace_ignore = 0;
public Err Args_add(Object... args) {msgs_ary[msgs_idx - 1].Args_add(args); return this;} // i - 1 to get current
@gplx.Internal protected boolean Type_match(String type) {
for (int i = 0; i < msgs_len; ++i) {
if (String_.Eq(type, msgs_ary[i].Type())) return true;
}
return false;
}
@gplx.Internal protected void Msgs_add(String type, String msg, Object[] args) {
if (msgs_idx == msgs_len) {
int new_len = msgs_len * 2;
Err_msg[] new_ary = new Err_msg[new_len];
Array_.CopyTo(msgs_ary, new_ary, 0);
this.msgs_ary = new_ary;
this.msgs_len = new_len;
}
msgs_ary[msgs_idx] = new Err_msg(type, msg, args);
++msgs_idx;
}
public String To_str__full() {return To_str(Bool_.N);}
public String To_str__log() {return To_str(Bool_.Y);}
private String To_str(boolean called_by_log) {
String nl_str = called_by_log ? "\t" : "\n";
String rv = ""; //nl_str + "----------------------------------------------------------------------" + nl_str;
for (int i = 0; i < msgs_idx; ++i) {
rv += "[err " + Int_.Xto_str(i) + "] " + msgs_ary[i].To_str() + nl_str;
}
rv += "[trace]:" + Trace_to_str(is_gplx, called_by_log, trace_ignore, trace == null ? Err_.Trace_lang(this) : trace);
return rv;
}
@Override public String getMessage() {return To_str__full();}
public static String Trace_to_str(boolean is_gplx, boolean called_by_log, int ignore_lines, String trace) {
String[] lines = String_.Split_lang(trace, '\n'); int lines_len = lines.length;
int line_bgn = 0;
if (is_gplx) { // remove Err_.new_wo_type lines from trace for gplx exceptions
for (int i = 0; i < lines_len; ++i) {
String line = lines[i];
if (String_.Has_at_bgn(line, "gplx.Err_.new")) continue; // ignore trace frames with "gplx.Err_.new"; EX: throw Err_.new_unimplemented
line_bgn = i + ignore_lines;
break;
}
}
// concat lines
String rv = "";
String line_bgn_dlm = called_by_log ? "\t " : "\n "; // "\n " indents
for (int i = line_bgn; i < lines_len; ++i)
rv += line_bgn_dlm + lines[i];
return rv;
}
}

@ -0,0 +1,71 @@
/*
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;
public class Err_ {
private static String Type__gplx = "gplx"; @gplx.Internal protected static String Trace_null = null;
public static void Noop(Exception e) {}
public static Err as_(Object obj) {return obj instanceof Err ? (Err)obj : null;}
public static Err new_(String type, String msg, Object... args) {return new Err(Bool_.Y, Trace_null, type, msg, args);}
public static Err new_wo_type(String msg, Object... args) {return new Err(Bool_.Y, Trace_null, Type__gplx, msg, args);}
public static Err new_exc(Exception e, String type, String msg, Object... args) {
Err rv = cast_or_make(e);
rv.Msgs_add(type, msg, args);
return rv;
}
public static Err new_unhandled(Object val) {return new Err(Bool_.Y, Trace_null, Type__gplx, "val is not in switch/if", "val", val);}
public static Err new_unimplemented() {return new Err(Bool_.Y, Trace_null, Type__gplx, "method not implemented");}
public static Err new_unimplemented_w_msg(String msg, Object... args) {return new Err(Bool_.Y, Trace_null, Type__gplx, msg, args);}
public static Err new_deprecated(String s) {return new Err(Bool_.Y, Trace_null, Type__gplx, "deprecated", "method", s);}
public static Err new_parse_type(Class<?> c, String raw) {return new_parse(ClassAdp_.FullNameOf_type(c), raw);}
public static Err new_parse_exc(Exception e, Class<?> c, String raw) {return new_parse(ClassAdp_.FullNameOf_type(c), raw).Args_add("e", Err_.Message_lang(e));}
public static Err new_parse(String type, String raw) {return new Err(Bool_.Y, Trace_null, Type__gplx, "parse failed", "type", type, "raw", raw);}
public static Err new_null() {return new Err(Bool_.Y, Trace_null, Type__gplx, "null obj");}
public static Err new_missing_idx(int idx, int len) {return new Err(Bool_.Y, Trace_null, Type__gplx, "index is out of bounds", "idx", idx, "len", len);}
public static Err new_missing_key(String key) {return new Err(Bool_.Y, Trace_null, Type__gplx, "key not found", "key", key);}
public static Err new_invalid_op(String msg) {return new Err(Bool_.Y, Trace_null, Type__gplx, msg);}
public static Err new_invalid_arg(String msg, Object... args) {return new Err(Bool_.Y, Trace_null, Type__gplx, msg, args);}
public static Err new_op_canceled() {return new Err(Bool_.Y, Trace_null, Type__op_canceled, "canceled by usr");}
public static Err new_type_mismatch_w_exc(Exception ignore, Class<?> t, Object o) {return new_type_mismatch(t, o);}
public static Err new_type_mismatch(Class<?> t, Object o) {return new Err(Bool_.Y, Trace_null, Type__gplx, "type mismatch", "expdType", ClassAdp_.FullNameOf_type(t), "actlType", ClassAdp_.NameOf_obj(o), "actlObj", Object_.Xto_str_strict_or_null_mark(o));}
public static Err new_cast(Exception ignore, Class<?> t, Object o) {
String o_str = "";
try {o_str = Object_.Xto_str_strict_or_null_mark(o);}
catch (Exception e) {o_str = "<ERROR>"; Err_.Noop(e);}
return new Err(Bool_.Y, Trace_null, Type__gplx, "cast failed", "type", ClassAdp_.NameOf_type(t), "obj", o_str);
}
public static String Message_lang(Exception e) {return e.getMessage();}
public static String Trace_lang(Exception e) {
String rv = "";
StackTraceElement[] ary = e.getStackTrace();
int len = ary.length;
for (int i = 0; i < len; i++) {
if (i != 0) rv += "\n";
rv += ary[i].toString();
}
return rv;
}
public static boolean Type_match(Exception e, String type) {
Err exc = Err_.as_(e);
return exc == null ? false : exc.Type_match(type);
}
public static String Message_gplx_full(Exception e) {return cast_or_make(e).To_str__full();}
public static String Message_gplx_log(Exception e) {return cast_or_make(e).To_str__log();}
private static Err cast_or_make(Exception e) {return ClassAdp_.Eq_typeSafe(e, Err.class) ? (Err)e : new Err(Bool_.N, Err_.Trace_lang(e), ClassAdp_.NameOf_obj(e), Err_.Message_lang(e));}
public static final String Type__op_canceled = "gplx.op_canceled";
}

@ -16,9 +16,9 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
class Exc_msg {
public class Err_msg {
private final String msg; private Object[] args;
public Exc_msg(String type, String msg, Object[] args) {
public Err_msg(String type, String msg, Object[] args) {
this.type = type;
this.msg = msg;
this.args = args;
@ -27,8 +27,10 @@ class Exc_msg {
public void Args_add(Object[] add) {
this.args = (Object[])Array_.Resize_add(args, add);
}
public String To_str() {
String rv = String_.Len_eq_0(type) ? "" : "[" + type + "] ";
public String To_str() {return To_str_w_type(type, msg, args);}
public static String To_str(String msg, Object... args) {return To_str_w_type(null, msg, args);}
public static String To_str_w_type(String type, String msg, Object... args) {
String rv = String_.Len_eq_0(type) ? "" : "<" + type + "> ";
rv += msg;
int len = args.length;
if (len > 0) {

@ -0,0 +1,47 @@
/*
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;
import org.junit.*;
public class Err_tst {
private final Err_fxt fxt = new Err_fxt();
@Test public void Trace_to_str__gplx() {
fxt.Test_Trace_to_str(Bool_.Y, Bool_.N, 0, String_.Concat_lines_nl_skip_last
( "gplx.Err_.new_wo_type(Err_.java:1)" // ignore this line
, "gplx.String_.Len(String_.java:2)"
), String_.Concat_lines_nl_skip_last
( ""
, " gplx.String_.Len(String_.java:2)"
));
}
@Test public void Trace_to_str__gplx_ignore() {
fxt.Test_Trace_to_str(Bool_.Y, Bool_.N, 1, String_.Concat_lines_nl_skip_last
( "gplx.Err_.new_wo_type(Err_.java:1)" // ignore this line
, "gplx.String_.Fail(String_.java:2)" // ignore this line also
, "gplx.String_.Len(String_.java:3)"
), String_.Concat_lines_nl_skip_last
( ""
, " gplx.String_.Len(String_.java:3)"
));
}
}
class Err_fxt {
public void Test_Trace_to_str(boolean is_gplx, boolean called_by_log, int ignore_lines, String trace, String expd) {
String actl = Err.Trace_to_str(is_gplx, called_by_log, ignore_lines, trace);
Tfds.Eq_str_lines(expd, actl);
}
}

@ -1,70 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public class Exc extends RuntimeException {
private final String stack;
private Exc_msg[] msgs_ary = new Exc_msg[8]; private int msgs_len = 8, msgs_idx = 0;
public Exc(String stack, String type, String msg, Object... args) {
Msgs_add(type, msg, args);
this.stack = stack;
}
public int Stack_erase() {return stack_erase;} public Exc Stack_erase_1_() {stack_erase = 1; return this;} private int stack_erase = 0;
public Exc Args_add(Object... args) {msgs_ary[msgs_idx - 1].Args_add(args); return this;} // i - 1 to get current
@gplx.Internal protected boolean Type_match(String type) {
for (int i = 0; i < msgs_len; ++i) {
if (String_.Eq(type, msgs_ary[i].Type())) return true;
}
return false;
}
@gplx.Internal protected void Msgs_add(String type, String msg, Object[] args) {
if (msgs_idx == msgs_len) {
int new_len = msgs_len * 2;
Exc_msg[] new_ary = new Exc_msg[new_len];
Array_.CopyTo(msgs_ary, new_ary, 0);
this.msgs_ary = new_ary;
this.msgs_len = new_len;
}
msgs_ary[msgs_idx] = new Exc_msg(type, msg, args);
++msgs_idx;
}
public String To_str_all() {
String rv = "";
for (int i = msgs_idx - 1; i > -1; --i) {
rv += "[err " + Int_.Xto_str(i) + "] " + msgs_ary[i].To_str() + "\n";
}
rv += "[stack]\n " + Stack_to_str(this, stack);
return rv;
}
@Override public String getMessage() {return To_str_all();}
private static String Stack_to_str(Exception e, String stack) {
String rv = stack;
if (rv == Exc_.Stack_null) { // occurs for thrown gplx exceptions; EX: throw Exc_.new_unimplemented
rv = ""; // set to "" b/c String concat below;
String[] lines = String_.Split_lang(Exc_.Stack_lang(e), '\n');
int len = lines.length;
for (int i = 0; i < len; ++i) {
String line = lines[i];
if (String_.Has_at_bgn(line, "gplx.Exc_.new")) continue; // ignore stack frames with "gplx.Exc_.new"; EX: throw Exc_.new_unimplemented
if (String_.Len(rv) > 0) rv += "\n";
rv += line;
}
}
rv = String_.Replace(rv, "\n", "\n "); // " " is to indent stack stack
return rv;
}
}

@ -1,67 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public class Exc_ {
private static String Type__none = ""; @gplx.Internal protected static String Stack_null = null;
public static final String Type__op_canceled = "gplx.op_canceled";
public static void Noop(Exception e) {}
public static Exc as_(Object obj) {return obj instanceof Exc ? (Exc)obj : null;}
public static Exc new_(String msg, Object... args) {return new Exc(Stack_null, Type__none, msg, args);}
public static Exc new_w_type(String type, String msg, Object... args) {return new Exc(Stack_null, type, msg, args);}
public static Exc new_exc(Exception e, String type, String msg, Object... args) {
Exc rv = ClassAdp_.Eq_typeSafe(e, Exc.class) ? (Exc)e : new Exc(Exc_.Stack_lang(e), Type__none, Exc_.Message_lang(e));
rv.Msgs_add(type, msg, args);
return rv;
}
public static Exc new_unhandled(Object val) {return new Exc(Stack_null, Type__none, "val is not in switch/if", "val", val);}
public static Exc new_unimplemented() {return new Exc(Stack_null, Type__none, "method not implemented");}
public static Exc new_unimplemented_w_msg(String msg, Object... args) {return new Exc(Stack_null, Type__none, msg, args);}
public static Exc new_deprecated(String s) {return new Exc(Stack_null, Type__none, "deprecated", "method", s);}
public static Exc new_parse_type(Class<?> c, String raw) {return new_parse(ClassAdp_.FullNameOf_type(c), raw);}
public static Exc new_parse_exc(Exception e, Class<?> c, String raw) {return new_parse(ClassAdp_.FullNameOf_type(c), raw).Args_add("e", Err_.Message_lang(e));}
public static Exc new_parse(String type, String raw) {return new Exc(Stack_null, Type__none, "parse failed", "type", type, "raw", raw);}
public static Exc new_null(String s) {return new Exc(Stack_null, Type__none, "null obj", "obj", s);}
public static Exc new_missing_idx(int idx, int len) {return new Exc(Stack_null, Type__none, "index is out of bounds", "idx", idx, "len", len);}
public static Exc new_missing_key(String key) {return new Exc(Stack_null, Type__none, "key not found", "key", key);}
public static Exc new_invalid_op(String msg) {return new Exc(Stack_null, Type__none, msg);}
public static Exc new_op_canceled() {return new Exc(Stack_null, Type__op_canceled, "canceled by usr");}
public static Exc new_type_mismatch_w_exc(Exception ignore, Class<?> t, Object o) {return new_type_mismatch(t, o);}
public static Exc new_type_mismatch(Class<?> t, Object o) {return new Exc(Stack_null, Type__none, "type mismatch", "expdType", ClassAdp_.FullNameOf_type(t), "actlType", ClassAdp_.NameOf_obj(o), "actlObj", Object_.Xto_str_strict_or_null_mark(o));}
public static Exc new_cast(Exception ignore, Class<?> t, Object o) {
String o_str = "";
try {o_str = Object_.Xto_str_strict_or_null_mark(o);}
catch (Exception e) {o_str = "<ERROR>"; Exc_.Noop(e);}
return new Exc(Stack_null, Type__none, "cast failed", "type", ClassAdp_.NameOf_type(t), "obj", o_str);
}
public static String Message_lang(Exception e) {return e.getMessage();}
public static String Stack_lang(Exception e) {
String rv = "";
StackTraceElement[] ary = e.getStackTrace();
int len = ary.length;
for (int i = 0; i < len; i++) {
if (i != 0) rv += "\n";
rv += ary[i].toString();
}
return rv;
}
public static boolean Type_match(Exception e, String type) {
Exc exc = Exc_.as_(e);
return exc == null ? false : exc.Type_match(type);
}
}

@ -44,7 +44,7 @@ public class Bry_rdr {
public int Read_int_to_pipe() {return Read_int_to(Byte_ascii.Pipe);}
public int Read_int_to_nl() {return Read_int_to(Byte_ascii.Nl);}
public int Read_int_to_quote() {return Read_int_to(Byte_ascii.Quote);}
public int Read_int_to_non_num(){return Read_int_to(Byte_ascii.Nil);}
public int Read_int_to_non_num(){return Read_int_to(Byte_ascii.Null);}
public int Read_int_to(byte to_char) {
int bgn = pos;
int rv = 0;
@ -64,7 +64,7 @@ public class Bry_rdr {
break;
default: {
boolean match = b == to_char;
if (to_char == Byte_ascii.Nil) {// hack for Read_int_to_non_num
if (to_char == Byte_ascii.Null) {// hack for Read_int_to_non_num
--pos;
match = true;
}
@ -141,12 +141,12 @@ public class Bry_rdr {
int bry_len = bry.length;
boolean match = Bry_.Match(src, pos, pos + bry_len, bry);
if (match) pos += bry_len;
else throw Exc_.new_("bry.rdr:chk failed", "bry", bry, "pos", pos);
else throw Err_.new_wo_type("bry.rdr:chk failed", "bry", bry, "pos", pos);
}
public void Chk_byte_or_fail(byte b) {
boolean match = pos < src_len ? src[pos] == b : false;
if (match) ++pos;
else throw Exc_.new_("bry.rdr:chk failed", "byte", b, "pos", pos);
else throw Err_.new_wo_type("bry.rdr:chk failed", "byte", b, "pos", pos);
}
public byte[] Mid_by_len_safe(int len) {
int end = pos + len; if (end > src_len) end = src_len;

@ -51,7 +51,7 @@ public class Btrie_bwd_mgr {
}
public Btrie_bwd_mgr Add(String key, Object val) {return Add(Bry_.new_u8(key), val);}
public Btrie_bwd_mgr Add(byte[] key, Object val) {
if (val == null) throw Exc_.new_("null objects cannot be registered", "key", String_.new_u8(key));
if (val == null) throw Err_.new_wo_type("null objects cannot be registered", "key", String_.new_u8(key));
int key_len = key.length;
Btrie_slim_itm cur = root;
for (int i = key_len - 1; i > -1; i--) {

@ -48,7 +48,7 @@ public class Btrie_fast_mgr {
public Btrie_fast_mgr Add(byte key, Object val) {return Add(new byte[] {key}, val);}
public Btrie_fast_mgr Add(String key, Object val) {return Add(Bry_.new_u8(key), val);}
public Btrie_fast_mgr Add(byte[] key, Object val) {
if (val == null) throw Exc_.new_("null objects cannot be registered", "key", String_.new_u8(key));
if (val == null) throw Err_.new_wo_type("null objects cannot be registered", "key", String_.new_u8(key));
int key_len = key.length; int key_end = key_len - 1;
ByteTrieItm_fast cur = root;
for (int i = 0; i < key_len; i++) {

@ -66,7 +66,7 @@ public class Btrie_slim_mgr implements Btrie_mgr {
}
public Btrie_mgr Add_obj(String key, Object val) {return Add_obj(Bry_.new_u8(key), val);}
public Btrie_mgr Add_obj(byte[] key, Object val) {
if (val == null) throw Exc_.new_("null objects cannot be registered", "key", String_.new_u8(key));
if (val == null) throw Err_.new_wo_type("null objects cannot be registered", "key", String_.new_u8(key));
int key_len = key.length; int key_end = key_len - 1;
Btrie_slim_itm cur = root;
for (int i = 0; i < key_len; i++) {

@ -45,7 +45,7 @@ public class Btrie_utf8_mgr implements Btrie_mgr {
public void Clear() {root.Clear(); count = 0;}
public Btrie_mgr Add_obj(String key, Object val) {return Add_obj(Bry_.new_u8(key), val);}
public Btrie_mgr Add_obj(byte[] key, Object val) {
if (val == null) throw Exc_.new_("null objects cannot be registered", "key", String_.new_u8(key));
if (val == null) throw Err_.new_wo_type("null objects cannot be registered", "key", String_.new_u8(key));
int key_len = key.length;
Btrie_utf8_itm cur = root;
int c_bgn = 0;

@ -15,14 +15,14 @@ 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;
public interface ConsoleDlg {
package gplx.core.consoles; import gplx.*; import gplx.core.*;
public interface Console_adp {
boolean Enabled(); // optimization; allows Write to be skipped (since Write may Concat strings or generate arrays)
boolean CanceledChk();
int CharsPerLineMax(); void CharsPerLineMax_set(int v);
void WriteText(String s);
void WriteLineFormat(String s, Object... args);
void WriteTempText(String s);
char ReadKey(String msg);
String ReadLine(String msg);
boolean Canceled_chk();
int Chars_per_line_max(); void Chars_per_line_max_(int v);
void Write_str(String s);
void Write_fmt_w_nl(String fmt, Object... args);
void Write_tmp(String s);
char Read_key(String msg);
String Read_line(String msg);
}

@ -15,18 +15,18 @@ 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;
public class ConsoleDlg_ {
public static final ConsoleDlg Null = new ConsoleDlg_null();
public static ConsoleDlg_dev Dev() {return new ConsoleDlg_dev();}
package gplx.core.consoles; import gplx.*; import gplx.core.*;
public class Console_adp_ {
public static final Console_adp Noop = new Console_adp__noop();
public static Console_adp__mem Dev() {return new Console_adp__mem();}
}
class ConsoleDlg_null implements ConsoleDlg {
class Console_adp__noop implements Console_adp {
public boolean Enabled() {return false;}
public boolean CanceledChk() {return false;}
public int CharsPerLineMax() {return 80;} public void CharsPerLineMax_set(int v) {}
public void WriteText(String s) {}
public void WriteLineFormat(String s, Object... args) {}
public void WriteTempText(String s) {}
public char ReadKey(String msg) {return '\0';}
public String ReadLine(String msg) {return "";}
public boolean Canceled_chk() {return false;}
public int Chars_per_line_max() {return 80;} public void Chars_per_line_max_(int v) {}
public void Write_str(String s) {}
public void Write_fmt_w_nl(String s, Object... args) {}
public void Write_tmp(String s) {}
public char Read_key(String msg) {return '\0';}
public String Read_line(String msg) {return "";}
}

@ -15,25 +15,27 @@ 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;
public class ConsoleDlg_dev implements ConsoleDlg {
package gplx.core.consoles; import gplx.*; import gplx.core.*;
public class Console_adp__mem implements Console_adp {
private final List_adp written = List_adp_.new_();
private final Hash_adp ignored = Hash_adp_.new_();
public boolean Enabled() {return true;}
public boolean CanceledChk() {return false;}
public int CharsPerLineMax() {return 80;} public void CharsPerLineMax_set(int v) {}
public ConsoleDlg_dev Ignore_add(String s) {ignored.Add_as_key_and_val(s); return this;}
public void WriteText(String s) {WriteString(s);}
public void WriteLineFormat(String s, Object... args) {WriteString(String_.Format(s, args) + String_.CrLf);}
public void WriteTempText(String s) {WriteString(s);}
public String ReadLine(String msg) {return "";}
public char ReadKey(String msg) {return '\0';}
public ConsoleDlg_dev CancelWhenTextWritten(String val) {
public boolean Canceled_chk() {return false;}
public int Chars_per_line_max() {return 80;} public void Chars_per_line_max_(int v) {}
public Console_adp__mem Ignore_add(String s) {ignored.Add_as_key_and_val(s); return this;}
public void Write_str(String s) {WriteString(s);}
public void Write_fmt_w_nl(String s, Object... args) {WriteString(String_.Format(s, args) + String_.CrLf);}
public void Write_tmp(String s) {WriteString(s);}
public String Read_line(String msg) {return "";}
public char Read_key(String msg) {return '\0';}
public Console_adp__mem CancelWhenTextWritten(String val) {
cancelVal = val;
return this;
}
void WriteString(String s) {
if (ignored.Has(s)) return;
written.Add(s);
if (cancelVal != null && String_.Has(s, cancelVal)) throw Exc_.new_("canceled", "cancel_val", s);
if (cancelVal != null && String_.Has(s, cancelVal)) throw Err_.new_wo_type("canceled", "cancel_val", s);
}
String cancelVal;
@ -45,5 +47,4 @@ public class ConsoleDlg_dev implements ConsoleDlg {
actl[i] = written.Get_at(i).toString();
Tfds.Eq_ary(actl, expd);
}
List_adp written = List_adp_.new_(), erased = List_adp_.new_(); Hash_adp ignored = Hash_adp_.new_();
}

@ -0,0 +1,66 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.consoles; import gplx.*; import gplx.core.*;
public class Console_adp__sys implements Console_adp {
private String tmp_txt;
public Console_adp__sys() {
this.backspace_by_bytes = Op_sys.Cur().Tid_is_lnx(); // bash shows UTF8 by default; backspace in bytes, else multi-byte characters don't show; DATE:2014-03-04
}
public boolean Enabled() {return true;}
public boolean Canceled() {return canceled;} public void Canceled_set(boolean v) {canceled = v;} private boolean canceled = false;
public boolean Canceled_chk() {if (canceled) throw Err_.new_op_canceled(); return canceled;}
public int Chars_per_line_max() {return chars_per_line_max;} public void Chars_per_line_max_(int v) {chars_per_line_max = v;} int chars_per_line_max = 80;
public boolean Backspace_by_bytes() {return backspace_by_bytes;} public Console_adp__sys Backspace_by_bytes_(boolean v) {backspace_by_bytes = v; return this;} private boolean backspace_by_bytes;
public void Write_str(String s) {Clear_tmp(); Write_str_lang(s);}
public void Write_str_w_nl(String s) {Clear_tmp(); Write_str_w_nl_lang(s);}
public void Write_fmt_w_nl(String fmt, Object... args) {Clear_tmp(); Write_str_w_nl_lang(String_.Format(fmt, args));}
public char Read_key(String s) {Write_str(s); return Read_key_lang();}
public String Read_line(String s) {Write_str(s); return Read_line_lang();}
public void Write_tmp(String s) {
Clear_tmp();
if (String_.Has(s, "\r")) s = String_.Replace(s, "\r", " ");
if (String_.Has(s, "\n")) s = String_.Replace(s, "\n", " ");
if (String_.Len(s) >= chars_per_line_max) s = String_.Mid(s, 0, chars_per_line_max - String_.Len("...") - 1) + "..."; // NOTE: >= and -1 needed b/c line needs to be 1 less than max; ex: default cmd is 80 width, but writing 80 chars will automatically create lineBreak
tmp_txt = s;
Write_str_lang(s);
}
private void Clear_tmp() {
if (tmp_txt == null) return;
if (Env_.Mode_debug()) {Write_str_lang(String_.CrLf); return;}
int count = backspace_by_bytes ? Bry_.new_u8(tmp_txt).length : String_.Len(tmp_txt);
String moveBack = String_.Repeat("\b", count);
this.Write_str_lang(moveBack); // move cursor back to beginning of line
this.Write_str_lang(String_.Repeat(" ", count)); // overwrite tmp_txt with space
this.Write_str_lang(moveBack); // move cursor back to beginning of line (so next Write will start at beginning)
tmp_txt = null;
}
private void Write_str_lang(String s) {System.out.print(s);}
private void Write_str_w_nl_lang(String s) {System.out.println(s);}
private String Read_line_lang() {return System.console() == null ? "" : System.console().readLine();}
private char Read_key_lang() {
String text = Read_line_lang();
return String_.Len(text) == 0 ? '\0' : String_.CharAt(text, 0);
}
public void Write_str_w_nl_utf8(String s) {
java.io.PrintStream ps;
try {ps = new java.io.PrintStream(System.out, true, "UTF-8");}
catch (java.io.UnsupportedEncodingException e) {throw Err_.new_wo_type("unsupported exception");}
ps.println(s);
}
public static final Console_adp__sys I = new Console_adp__sys();
}

@ -23,7 +23,7 @@ public class Criteria_ {
public static Criteria Not(Criteria arg) {return new Criteria_not(arg);}
public static Criteria And(Criteria lhs, Criteria rhs) {return new Criteria_and(lhs, rhs);}
public static Criteria And_many(Criteria... ary) {
int len = Array_.Len(ary); if (len == 0) throw Exc_.new_("cannot AND 0 criterias;");
int len = Array_.Len(ary); if (len == 0) throw Err_.new_wo_type("cannot AND 0 criterias;");
Criteria rv = ary[0];
for (int i = 1; i < len; i++)
rv = And(rv, ary[i]);
@ -31,7 +31,7 @@ public class Criteria_ {
}
public static Criteria Or(Criteria lhs, Criteria rhs) {return new Criteria_or(lhs, rhs);}
public static Criteria Or_many(Criteria... ary) {
int len = Array_.Len(ary); if (len == 0) throw Exc_.new_("cannot OR 0 criterias;");
int len = Array_.Len(ary); if (len == 0) throw Err_.new_wo_type("cannot OR 0 criterias;");
Criteria rv = ary[0];
for (int i = 1; i < len; i++)
rv = Or(rv, ary[i]);

@ -20,7 +20,7 @@ public class Criteria_between implements Criteria {
public Criteria_between(boolean negate, Comparable lhs, Comparable rhs) {this.negate = negate; this.lhs = lhs; this.rhs = rhs;}
public byte Tid() {return Criteria_.Tid_between;}
public boolean Negated() {return negate;} private final boolean negate;
public void Val_from_args(Hash_adp args) {throw Exc_.new_unimplemented();}
public void Val_from_args(Hash_adp args) {throw Err_.new_unimplemented();}
public void Val_as_obj_(Object v) {
Object[] ary = (Object[])v;
lhs = (Comparable)ary[0];

@ -21,7 +21,7 @@ public abstract class Criteria_bool_base implements Criteria {
public abstract byte Tid();
public abstract boolean Matches(Object curVal);
public void Val_from_args(Hash_adp args) {lhs.Val_from_args(args); rhs.Val_from_args(args);}
public void Val_as_obj_(Object v) {throw Exc_.new_unimplemented();}
public void Val_as_obj_(Object v) {throw Err_.new_unimplemented();}
public String XtoStr() {return String_.Concat(lhs.XtoStr(), " ", this.op_literal, " ", rhs.XtoStr());}
public String Op_literal() {return op_literal;} private String op_literal;
public Criteria Lhs() {return lhs;} private Criteria lhs;
@ -43,7 +43,7 @@ class Criteria_const implements Criteria {
public byte Tid() {return Criteria_.Tid_const;}
public boolean Matches(Object comp) {return val;} private final boolean val;
public void Val_from_args(Hash_adp args) {;}
public void Val_as_obj_(Object v) {throw Exc_.new_unimplemented();}
public void Val_as_obj_(Object v) {throw Err_.new_unimplemented();}
public String XtoStr() {return String_.Concat(" IS ", Bool_.Xto_str_lower(val));}
}
class Criteria_not implements Criteria {

@ -21,7 +21,7 @@ public class Criteria_comp implements Criteria {
@gplx.Internal protected Criteria_comp(int comp_mode, Comparable val) {this.comp_mode = comp_mode; this.val = val;}
public byte Tid() {return Criteria_.Tid_comp;}
public Comparable Val() {return val;} private Comparable val;
public void Val_from_args(Hash_adp args) {throw Exc_.new_unimplemented();}
public void Val_from_args(Hash_adp args) {throw Err_.new_unimplemented();}
public void Val_as_obj_(Object v) {val = (Comparable)v;}
public boolean Matches(Object compObj) {
Comparable comp = CompareAble_.as_(compObj);

@ -22,10 +22,10 @@ public class Criteria_eq implements Criteria {
public boolean Negated() {return negated;} private final boolean negated;
public Object Val() {return val;} private Object val;
public void Val_as_obj_(Object v) {this.val = v;}
public void Val_from_args(Hash_adp args) {throw Exc_.new_unimplemented();}
public void Val_from_args(Hash_adp args) {throw Err_.new_unimplemented();}
public boolean Matches(Object comp) {
Class<?> val_type = ClassAdp_.ClassOf_obj(val);
if (!ClassAdp_.Eq_typeSafe(comp, val_type)) throw Exc_.new_type_mismatch(val_type, comp);
if (!ClassAdp_.Eq_typeSafe(comp, val_type)) throw Err_.new_type_mismatch(val_type, comp);
boolean rv = Object_.Eq(val, comp);
return negated ? !rv : rv;
}

@ -21,9 +21,9 @@ public class Criteria_fld implements Criteria {
public byte Tid() {return Criteria_.Tid_wrapper;}
public String Key() {return key;} private final String key;
public Criteria Crt() {return crt;} private final Criteria crt;
public void Val_as_obj_(Object v) {throw Exc_.new_unimplemented();}
public void Val_as_obj_(Object v) {throw Err_.new_unimplemented();}
public void Val_from_args(Hash_adp args) {
List_adp list = (List_adp)args.Get_by(key); if (list == null) throw Exc_.new_("criteria.fld key not found", "key", key);
List_adp list = (List_adp)args.Get_by(key); if (list == null) throw Err_.new_wo_type("criteria.fld key not found", "key", key);
Object o = Fill_val(key, crt.Tid(), list);
crt.Val_as_obj_(o);
}
@ -44,24 +44,24 @@ public class Criteria_fld implements Criteria {
case Criteria_.Tid_comp:
case Criteria_.Tid_like:
case Criteria_.Tid_iomatch:
if (len != 1) throw Exc_.new_("list.len should be 1", "key", key, "tid", tid, "len", len);
if (len != 1) throw Err_.new_wo_type("list.len should be 1", "key", key, "tid", tid, "len", len);
return list.Get_at(0);
case Criteria_.Tid_between:
if (len != 2) throw Exc_.new_("list.len should be 2", "key", key, "tid", tid, "len", len);
if (len != 2) throw Err_.new_wo_type("list.len should be 2", "key", key, "tid", tid, "len", len);
return new Object[] {list.Get_at(0), list.Get_at(1)};
case Criteria_.Tid_in:
if (len == 0) throw Exc_.new_("list.len should be > 0", "key", key, "tid", tid, "len", len);
if (len == 0) throw Err_.new_wo_type("list.len should be > 0", "key", key, "tid", tid, "len", len);
return list.To_obj_ary();
case Criteria_.Tid_const:
case Criteria_.Tid_not:
case Criteria_.Tid_and:
case Criteria_.Tid_or:
if (len != 0) throw Exc_.new_("list.len should be 0", "key", key, "tid", tid, "len", len);
if (len != 0) throw Err_.new_wo_type("list.len should be 0", "key", key, "tid", tid, "len", len);
return key; // no values to fill in; return back key
case Criteria_.Tid_wrapper: // not recursive
case Criteria_.Tid_db_obj_ary: // unsupported
case Criteria_.Tid_custom:
default: throw Exc_.new_unhandled(tid);
default: throw Err_.new_unhandled(tid);
}
}
}

@ -27,10 +27,10 @@ public class Criteria_in implements Criteria {
ary_type = ary_len == 0 ? Object.class : ClassAdp_.ClassOf_obj(ary[0]);
}
public void Val_as_obj_(Object v) {Val_as_obj_ary_((Object[])v);}
public void Val_from_args(Hash_adp args) {throw Exc_.new_unimplemented();}
public void Val_from_args(Hash_adp args) {throw Err_.new_unimplemented();}
public boolean Matches(Object comp) {
if (ary_len == 0) return false; // empty array never matches
if (!ClassAdp_.Eq_typeSafe(comp, ary_type)) throw Exc_.new_type_mismatch(ary_type, comp);
if (!ClassAdp_.Eq_typeSafe(comp, ary_type)) throw Err_.new_type_mismatch(ary_type, comp);
boolean rv = false;
for (int i = 0; i < ary_len; i++) {
Object val = ary[i];

@ -21,7 +21,7 @@ public class Criteria_ioMatch implements Criteria { // EX: url IOMATCH '*.xml|*.
public Criteria_ioMatch(boolean match, RegxPatn_cls_ioMatch pattern) {this.match = match; this.pattern = pattern;}
public byte Tid() {return Criteria_.Tid_iomatch;}
public boolean Negated() {return !match;} private final boolean match;
public void Val_from_args(Hash_adp args) {throw Exc_.new_unimplemented();}
public void Val_from_args(Hash_adp args) {throw Err_.new_unimplemented();}
public void Val_as_obj_(Object v) {this.pattern = (RegxPatn_cls_ioMatch)v;}
public RegxPatn_cls_ioMatch Pattern() {return pattern;} private RegxPatn_cls_ioMatch pattern;
public boolean Matches(Object compObj) {

@ -24,10 +24,10 @@ public class Criteria_like implements Criteria {
public byte Tid() {return Criteria_.Tid_like;}
public boolean Negated() {return negated;} private final boolean negated;
public RegxPatn_cls_like Pattern() {return pattern;} private RegxPatn_cls_like pattern;
public void Val_from_args(Hash_adp args) {throw Exc_.new_unimplemented();}
public void Val_from_args(Hash_adp args) {throw Err_.new_unimplemented();}
public void Val_as_obj_(Object v) {this.pattern = (RegxPatn_cls_like)v;}
public boolean Matches(Object compObj) {
String comp = String_.as_(compObj); if (comp == null) throw Exc_.new_type_mismatch(String.class, compObj);
String comp = String_.as_(compObj); if (comp == null) throw Err_.new_type_mismatch(String.class, compObj);
boolean rv = pattern.Matches(comp);
return negated ? !rv : rv;
}

@ -86,7 +86,7 @@ class CriteriaFxt {
public void tst_MatchesNot(Criteria crt, Object... ary) {for (Object val : ary) Tfds.Eq(false, crt.Matches(val));}
public void tst_MatchesFail(Criteria crt, Object val) {
try {crt.Matches(val);}
catch(Exception exc) {Exc_.Noop(exc); return;}
catch(Exception exc) {Err_.Noop(exc); return;}
Tfds.Fail_expdError();
}
}

@ -29,6 +29,6 @@ public class Bool_obj_val {
if (String_.Eq(raw, "y")) return Bool_obj_val.True;
else if (String_.Eq(raw, "n")) return Bool_obj_val.False;
else if (String_.Eq(raw, "")) return Bool_obj_val.Null;
else throw Exc_.new_parse_type(Bool_obj_val.class, raw);
else throw Err_.new_parse_type(Bool_obj_val.class, raw);
}
}

@ -34,7 +34,7 @@ public class Thread_adp implements Runnable {
public void Interrupt() {thread.interrupt();}
public void Join() {
try {thread.join();}
catch (Exception e) {Exc_.Noop(e);}
catch (Exception e) {Err_.Noop(e);}
}
// public void Stop() {thread.stop();}
public boolean IsAlive() {return thread.isAlive();}

@ -18,12 +18,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.core.threads; import gplx.*; import gplx.core.*;
public class Thread_adp_ {
public static void Sleep(int milliseconds) {
try {Thread.sleep(milliseconds);} catch (InterruptedException e) {throw Exc_.new_exc(e, "core", "thread interrupted", "milliseconds", milliseconds);}
try {Thread.sleep(milliseconds);} catch (InterruptedException e) {throw Err_.new_exc(e, "core", "thread interrupted", "milliseconds", milliseconds);}
}
public static void Notify_all(Object o) {o.notifyAll();}
public static void Wait(Object o) {
try {o.wait();}
catch (InterruptedException e) {throw Exc_.new_exc(e, "core", "thread wait");}
catch (InterruptedException e) {throw Err_.new_exc(e, "core", "thread wait");}
}
public static Thread_adp invk_(GfoInvkAble invk, String cmd) {return invk_(Name_null, invk, cmd);}
public static Thread_adp invk_(String name, GfoInvkAble invk, String cmd) {return new Thread_adp(name, invk, cmd, GfoMsg_.Null);}

@ -1,63 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public class Err extends RuntimeException {
@Override public String getMessage() {return Message_gplx();}
public String Key() {return key;} public Err Key_(String v) {key = v; return this;} private String key = "";
public String Hdr() {return hdr;} public Err Hdr_(String v) {hdr = v; return this;} private String hdr = "";
public List_adp Args() {return args;} List_adp args = List_adp_.new_();
public Err Add(String k, Object o) {args.Add(KeyVal_.new_(k, o)); return this;}
@gplx.Internal protected ErrProcData Proc() {return proc;} ErrProcData proc = ErrProcData.Null;
public Ordered_hash CallStack() {return callStack;} Ordered_hash callStack = Ordered_hash_.new_();
public int CallLevel() {return callLevel;} public Err CallLevel_(int val) {callLevel = val; return this;} public Err CallLevel_1_() {return CallLevel_(1);} int callLevel;
public Err Inner() {return inner;} Err inner;
@gplx.Internal protected static Err hdr_(String hdr) {
Err rv = new Err();
rv.hdr = hdr;
return rv;
} @gplx.Internal protected Err() {}
@gplx.Internal protected static Err exc_(Exception thrown, String hdr) {
Err rv = hdr_(hdr + ":" + Err_.Message_lang(thrown)); // add a better error description; DATE:2014-08-15
rv.inner = convert_(thrown);
for (int i = 0; i < rv.inner.callStack.Count(); i++) {
ErrProcData itm = (ErrProcData)rv.inner.callStack.Get_at(i);
rv.callStack.Add(itm.Raw(), itm);
}
return rv;
}
@gplx.Internal protected static Err convert_(Exception thrown) {
Err rv = Err_.as_(thrown);
if (rv == null)
rv = Err_.new_key_1(ClassAdp_.NameOf_obj(thrown), Err_.Message_lang(thrown));
CallStack_fill(rv, Err_.StackTrace_lang(rv));
return rv;
}
static void CallStack_fill(Err err, String stackTrace) {
ErrProcData[] ary = ErrProcData.parse_ary_(stackTrace); if (Array_.Len(ary) == 0) return; // no callStack; shouldn't happen, but don't throw error
err.proc = ary[0];
for (ErrProcData itm : ary) {
String key = itm.Raw();
if (err.callStack.Has(key)) continue;
err.callStack.Add(key, itm);
}
}
String Message_gplx() {
try {return Err_.Message_gplx(this);}
catch (Exception exc) {Exc_.Noop(exc); return super.getMessage();}
}
}

@ -1,112 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
import gplx.core.strings.*;
public class ErrMsgWtr {
public String Message_gplx(Exception thrown) {
Err err = Err.convert_(thrown); // convert thrown to Err to make rest of class easier
Err[] innerAry = InnerAsAry(err);
String_bldr sb = String_bldr_.new_();
WriteError(innerAry, sb, 0);
WriteInner(innerAry, sb);
WriteStack(innerAry, sb);
return sb.XtoStr();
}
public String Message_gplx_brief(Exception thrown) {
Err err = Err.convert_(thrown); // convert thrown to Err to make rest of proc easier
String_bldr sb = String_bldr_.new_();
sb.Add(err.Hdr());
if (err.Args().Count() > 0) sb.Add(" --");
for (Object kvo : err.Args()) {
KeyVal kv = (KeyVal)kvo;
String key = kv.Key(), val = kv.Val_to_str_or_empty();
sb.Add_fmt(" {0}='{1}'", key, val);
}
sb.Add_fmt(" [{0}]", err.Key());
return sb.XtoStr();
}
void WriteInner(Err[] errAry, String_bldr sb) {
int len = Array_.Len(errAry); if (len <= 1) return; // no inners; return;
for (int i = 1; i < len; i++)
WriteError(errAry, sb, i);
}
void WriteError(Err[] errAry, String_bldr sb, int i) {
Err err = errAry[i];
String msg = err.Hdr();
String typ = String_.Eq(err.Key(), "") ? "" : String_.Concat(" <", err.Key(), ">");
boolean onlyOne = errAry.length == 1;
String idxStr = onlyOne ? "" : Int_.Xto_str(i);
sb.Add(idxStr).Add("\t").Add(msg).Add(typ).Add_char_crlf(); // ex: " @count must be > 0 <gplx.arg>"
WriteKeyValAry(sb, err.Args());
sb.Add("\t").Add(err.Proc().SignatureRaw()).Add_char_crlf();
// WriteKeyValAry(sb, err.ProcArgs());
}
void WriteKeyValAry(String_bldr sb, List_adp ary) {
// calc keyMax for valIndentLen
int keyMax = 0;
for (Object o : ary) {
KeyVal kv = (KeyVal)o;
int keyLen = String_.Len(kv.Key());
if (keyLen > keyMax) keyMax = keyLen + 1; // +1 to guarantee one space between key and val
}
if (keyMax < 8)keyMax = 8; // separate by at least 8 chars
for (Object o : ary) {
KeyVal kv = (KeyVal)o;
String key = kv.Key(); int keyLen = String_.Len(key);
String valIndent = String_.Repeat(" ", keyMax - keyLen);
sb.Add("\t\t@").Add(key).Add(valIndent).Add(kv.Val_to_str_or_empty()).Add_char_crlf();
}
}
void WriteStack(Err[] errAry, String_bldr sb) {
if (Env_.Mode_testing()) return; // only write stack when not testing
int len = Array_.Len(errAry); if (len == 0) return; // shouldn't happen, but don't want to throw err
Err first = errAry[0];
boolean onlyOne = len == 1;
sb.Add_str_w_crlf(String_.Repeat("-", 80));
List_adp tmp = List_adp_.new_();
Ordered_hash callStack = first.CallStack(); int callStackCount = callStack.Count();
for (int i = 0; i < callStackCount ; i++) {
ErrProcData proc = (ErrProcData)callStack.Get_at(i);
// get procIndex
int idx = -1;
for (int j = 0; j < len; j++) {
ErrProcData comp = errAry[j].Proc();
if (String_.Eq(proc.Raw(), comp.Raw())) {idx = j; break;}
}
String idxStr = onlyOne ? "" : Int_.Xto_str(idx);
String hdr = idx == -1 ? "\t" : idxStr + "\t";
String ideAddressSpr = String_.CrLf + "\t\t";
String ideAddress = String_.Eq(proc.IdeAddress(), "") ? "" : ideAddressSpr + proc.IdeAddress(); // NOTE: ideAddress will be blank in compiled mode
String msg = String_.Concat(hdr, proc.SignatureRaw(), ideAddress);
tmp.Add(msg);
}
tmp.Reverse();
for (Object o : tmp)
sb.Add_str_w_crlf((String)o);
}
static Err[] InnerAsAry(Err err) {
List_adp errAry = List_adp_.new_();
Err cur = Err_.as_(err);
while (cur != null) {
errAry.Add(cur);
cur = cur.Inner();
}
return (Err[])errAry.To_ary(Err.class);
}
public static final ErrMsgWtr _ = new ErrMsgWtr(); ErrMsgWtr() {}
}

@ -1,67 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
class ErrProcData {
public String Raw() {return raw;} public ErrProcData Raw_(String val) {raw = val; return this;} private String raw = String_.Empty;
public String SignatureRaw() {return signatureRaw;} public ErrProcData SignatureRaw_(String val) {signatureRaw = val; return this;} private String signatureRaw = String_.Empty;
public String SourceFileRaw() {return sourceFileRaw;} public ErrProcData SourceFileRaw_(String val) {sourceFileRaw = val; return this;} private String sourceFileRaw = String_.Empty;
public int SourceLine() {return sourceLine;} public ErrProcData SourceLine_(int val) {sourceLine = val; return this;} int sourceLine;
public String IdeAddress() {return ideAddress;} public ErrProcData IdeAddress_(String val) {ideAddress = val; return this;} private String ideAddress = String_.Empty;
public static ErrProcData[] parse_ary_(String stackTrace) {
/*
.java
' at gplx.Err.new_(Err.java:92)
at gplx.Err.exc_(Err.java:43)
at gplx.Err_.err_(Err_.java:4)
at gplx._tst.Err__tst.RdrLoad(Err__tst.java:77)
at gplx._tst.Err__tst.MgrInit(Err__tst.java:76)'
.cs
' at gplx._tst.Err__tst.RdrLoad() in c:\000\200_dev\100.gplx\100.framework\100.core\gplx\tst\gplx\err__tst.cs:line 77
at gplx._tst.Err__tst.MgrInit(String s) in c:\000\200_dev\100.gplx\100.framework\100.core\gplx\tst\gplx\err__tst.cs:line 76'
*/
if (stackTrace == null) return new ErrProcData[0];
String[] lines = String_.SplitLines_any(stackTrace);
List_adp list = List_adp_.new_();
int len = Array_.Len(lines);
for (int i = 0; i < len; i++) {
ErrProcData md = ErrProcData.parse_(lines[i]);
if (md.SourceLine() == 0) break; // ASSUME: java code; not interested
if (String_.Has_at_bgn(md.signatureRaw, "gplx.Err_") || String_.Has_at_bgn(md.signatureRaw, "gplx.Err.")) continue; // java includes entire stackTrace from point of creation; only care about point of throw
list.Add(md);
}
return (ErrProcData[])list.To_ary(ErrProcData.class);
}
public static ErrProcData parse_(String raw) {
ErrProcData rv = new ErrProcData().Raw_(raw);
// ex:'gplx.Err.new_(Err.java:92)'
int sigEnd = String_.FindFwd(raw, "("); if (sigEnd == String_.Find_none) return rv;
rv.signatureRaw = String_.Mid(raw, 0, sigEnd);
int filBgn = sigEnd + 1; // 1="("
int filEnd = String_.FindFwd(raw, ":", filBgn); if (filEnd == String_.Find_none) return rv;
rv.sourceFileRaw = String_.Mid(raw, filBgn, filEnd);
int linBgn = filEnd + 1; // 1=":"
int linEnd = String_.FindFwd(raw, ")", linBgn); if (linEnd == String_.Find_none) return rv;
String linRaw = String_.Mid(raw, linBgn, linEnd);
rv.sourceLine = Int_.parse_(linRaw);
rv.ideAddress = String_.Concat("(", rv.sourceFileRaw, ":", Int_.Xto_str(rv.sourceLine), ")");
return rv;
}
public static ErrProcData new_() {return new ErrProcData();} ErrProcData() {}
public static final ErrProcData Null = new ErrProcData();
}

@ -1,48 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
import org.junit.*;
public class ErrProcData_tst {
@Test public void parse_() {
tst_parse_("gplx._tst.Err__tst.RdrLoad(MethodData_tst.java:1)"
, ErrProcData.new_()
.SignatureRaw_("gplx._tst.Err__tst.RdrLoad")
.SourceFileRaw_("MethodData_tst.java")
.SourceLine_(1)
.IdeAddress_("(MethodData_tst.java:1)")
);
}
@Test public void parse_ary_() {
String stackTrace = "";
try {ThrowException();} catch (Exception exc) {stackTrace = Err_.StackTrace_lang(exc);}
ErrProcData[] ary = ErrProcData.parse_ary_(stackTrace);
Tfds.Eq(2, Array_.Len(ary));
Tfds.Eq("gplx.ErrProcData_tst.ThrowException", ary[0].SignatureRaw());
Tfds.Eq("gplx.ErrProcData_tst.parse_ary_", ary[1].SignatureRaw());
}
Exception ThrowException() {
throw new RuntimeException("msg");
}
void tst_parse_(String raw, ErrProcData expd) {
ErrProcData actl = ErrProcData.parse_(raw);
Tfds.Eq(expd.SignatureRaw(), actl.SignatureRaw());
Tfds.Eq(expd.SourceFileRaw(), actl.SourceFileRaw());
Tfds.Eq(expd.SourceLine(), actl.SourceLine());
Tfds.Eq(expd.IdeAddress(), actl.IdeAddress());
}
}

@ -1,36 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
import gplx.core.strings.*;
public class Err_ { //_20110415
public static Err as_(Object obj) {return obj instanceof Err ? (Err)obj : null;}
@gplx.Internal protected static Err new_key_1(String key, String hdr) {return Err.hdr_(hdr).Key_(key);}
public static String Message_lang(Exception e) {return e.getMessage();}
public static String Message_gplx(Exception e) {return ErrMsgWtr._.Message_gplx(e);}
public static String Message_gplx_brief(Exception e) {return ErrMsgWtr._.Message_gplx_brief(e);}
@gplx.Internal protected static String StackTrace_lang(Exception e) {
String_bldr sb = String_bldr_.new_();
StackTraceElement[] stackTraceAry = e.getStackTrace();
int len = stackTraceAry.length;
for (int i = 0; i < len; i++) {
if (i != 0) sb.Add_char_crlf();
sb.Add(stackTraceAry[i].toString());
}
return sb.XtoStr();
}
}

@ -1,53 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public class Err_arg extends Err {
public String ArgName() {return argName;} private String argName;
public Object ArgValue() {return argValue;} Object argValue;
public static Err_arg null_(String argName) {
Err_arg rv = new Err_arg();
rv.Key_("gplx.arg").Hdr_("@" + rv.argName + " cannot be null");
rv.argName = argName;
return rv;
}
public static Err_arg cannotBe_(String msg, String argName, Object argValue) {
Err_arg rv = new Err_arg();
rv.Key_("gplx.arg");
rv.Hdr_("val cannot be " + msg);
rv.Add("key", argName);
rv.Add("val", argValue);
return rv;
}
public static Err_arg notFound_key_(String argName, Object argValue) {
Err_arg rv = new Err_arg();
rv.Key_("gplx.arg").Hdr_("arg not found").Add(argName, argValue);
rv.argName = argName;
rv.argValue = argValue;
return rv;
}
public static Err_arg outOfBounds_(String argName, int i, int count) {
Err_arg rv = new Err_arg();
rv.Key_("gplx.arg").Hdr_("arg out of bounds").Add("argName", argName).Add("argVal", i).Add("count", count);
rv.argName = argName;
rv.argValue = i;
return rv;
}
public static boolean ClassCheck(Exception e) {
return ClassAdp_.Eq_typeSafe(e, Err_arg.class);
}
}

@ -40,10 +40,10 @@ public class CompareAble_ {
return (actl * expt) > 0; // actl=More||Less; expd will match if on same side of 0 (ex: expt=Less; actl=Less; -1 * -1 = 1)
}
// public static int FindSlot(ComparerAble comparer, Object[] ary, Object itm) {return FindSlot(comparer, ary, itm, false);}
public static int FindSlot(ComparerAble comparer, Object[] ary, Object itm) {if (itm == null) throw Exc_.new_null("itm is null");
public static int FindSlot(ComparerAble comparer, Object[] ary, Object itm) {if (itm == null) throw Err_.new_null();
int aryLen = ary.length;
switch (aryLen) {
case 0: throw Exc_.new_("ary cannot have 0 itms");
case 0: throw Err_.new_wo_type("ary cannot have 0 itms");
case 1: return 0;
}
int lo = -1, hi = aryLen - 1; // NOTE: -1 is necessary; see test

@ -18,5 +18,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx;
public class RlsAble_ {
public static RlsAble as_(Object obj) {return obj instanceof RlsAble ? (RlsAble)obj : null;}
public static RlsAble cast_(Object obj) {try {return (RlsAble)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, RlsAble.class, obj);}}
public static RlsAble cast_(Object obj) {try {return (RlsAble)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, RlsAble.class, obj);}}
}

@ -77,14 +77,14 @@ public class Array_ {
public static void Set(Object ary, int i, Object o) {Array.set(ary, i, o);}
public static Object Expand(Object src, Object trg, int src_len) {
try {System.arraycopy(src, 0, trg, 0, src_len);}
catch (Exception e) {throw Exc_.new_exc(e, "core", "Array_.Expand failed", "src_len", src_len);}
catch (Exception e) {throw Err_.new_exc(e, "core", "Array_.Expand failed", "src_len", src_len);}
return trg;
}
public static void Copy(Object src, Object trg) {System.arraycopy(src, 0, trg, 0, Len(src));}
public static void CopyTo(Object src, Object trg, int trgPos) {System.arraycopy(src, 0, trg, trgPos, Len(src));}
public static void CopyTo(Object src, int srcBgn, Object trg, int trgBgn, int srcLen) {System.arraycopy(src, srcBgn, trg, trgBgn, srcLen);}
public static Class<?> ComponentType(Object ary) {
if (ary == null) throw Exc_.new_null("ary");
if (ary == null) throw Err_.new_null();
return ary.getClass().getComponentType();
}
public static Object Resize_add(Object src, Object add) {

@ -26,8 +26,8 @@ public class Bool_ implements GfoInvkAble {
public static final byte[] Y_bry = new byte[] {Byte_ascii.Ltr_y}, N_bry = new byte[] {Byte_ascii.Ltr_n};
public static final String True_str = "true", False_str = "false";
public static final byte[] True_bry = Bry_.new_a7(True_str), False_bry = Bry_.new_a7(False_str);
public static boolean cast_(Object obj) {try {return (Boolean)obj;} catch (Exception e) {throw Exc_.new_type_mismatch_w_exc(e, boolean.class, obj);}}
public static boolean cast_or_(Object obj, boolean v) {try {return (Boolean)obj;} catch (Exception e) {Exc_.Noop(e); return v;}}
public static boolean cast_(Object obj) {try {return (Boolean)obj;} catch (Exception e) {throw Err_.new_type_mismatch_w_exc(e, boolean.class, obj);}}
public static boolean cast_or_(Object obj, boolean v) {try {return (Boolean)obj;} catch (Exception e) {Err_.Noop(e); return v;}}
public static boolean By_int(int v) {return v != 0;}
public static boolean parse_(String raw) {
if ( String_.Eq(raw, "true")
@ -38,7 +38,7 @@ public class Bool_ implements GfoInvkAble {
|| String_.Eq(raw, "False")
)
return false;
throw Exc_.new_parse_type(boolean.class, raw);
throw Err_.new_parse_type(boolean.class, raw);
}
public static byte Xto_byte(boolean v) {return v ? Y_byte : N_byte;}
public static int Xto_int(boolean v) {return v ? 1 : 0;}

@ -45,7 +45,7 @@ public class Bry_ {
}
return rv;
}
catch (Exception e) {throw Exc_.new_exc(e, "core", "invalid ASCII sequence", "str", str);}
catch (Exception e) {throw Err_.new_exc(e, "core", "invalid ASCII sequence", "str", str);}
}
public static byte[] new_u8_safe(String str) {return str == null ? null : new_u8(str);}
public static byte[] new_u8(String str) {
@ -56,7 +56,7 @@ public class Bry_ {
new_u8_write(str, str_len, rv, 0);
return rv;
}
catch (Exception e) {throw Exc_.new_exc(e, "core", "invalid UTF-8 sequence", "s", str);}
catch (Exception e) {throw Err_.new_exc(e, "core", "invalid UTF-8 sequence", "s", str);}
}
public static int new_u8_by_len(String s, int s_len) {
int rv = 0;
@ -85,7 +85,7 @@ public class Bry_ {
}
else if ( (c > 55295) // 0xD800
&& (c < 56320)) { // 0xDFFF
if (i >= str_len) throw Exc_.new_("incomplete surrogate pair at end of String", "char", c);
if (i >= str_len) throw Err_.new_wo_type("incomplete surrogate pair at end of String", "char", c);
char nxt_char = str.charAt(i + 1);
int v = 0x10000 + (c - 0xD800) * 0x400 + (nxt_char - 0xDC00);
bry[bry_pos++] = (byte)(0xF0 | (v >> 18));
@ -103,9 +103,9 @@ public class Bry_ {
}
public static byte[] Coalesce(byte[] orig, byte[] val_if_not_blank) {return Bry_.Len_eq_0(orig) ? val_if_not_blank : orig;}
public static byte Get_at_end_or_fail(byte[] bry) {
if (bry == null) throw Exc_.new_("bry is null");
if (bry == null) throw Err_.new_wo_type("bry is null");
int bry_len = bry.length;
if (bry_len == 0) throw Exc_.new_("bry has 0 len");
if (bry_len == 0) throw Err_.new_wo_type("bry has 0 len");
return bry[bry_len - 1];
}
public static int While_fwd(byte[] src, byte while_byte, int bgn, int end) {
@ -325,7 +325,7 @@ public class Bry_ {
}
public static byte[] Mid_safe(byte[] src, int bgn, int end) {
try {return Mid(src, bgn, end);}
catch (Exception e) {Exc_.Noop(e); return Bry_.Add_w_dlm(Byte_ascii.Space, Bry_.XbyInt(bgn), Bry_.XbyInt(end));}
catch (Exception e) {Err_.Noop(e); return Bry_.Add_w_dlm(Byte_ascii.Space, Bry_.XbyInt(bgn), Bry_.XbyInt(end));}
}
public static byte[] Mid(byte[] src, int bgn) {return Mid(src, bgn, src.length);}
public static byte[] Mid_or(byte[] src, int bgn, int end, byte[] or) {
@ -351,7 +351,7 @@ public class Bry_ {
else if (bgn < 0 || bgn > src.length) msg = "invalid bgn";
else if (end < 0 || end > src.length) msg = "invalid end";
else if (end < bgn) msg = "end < bgn";
throw Exc_.new_exc(e, "core", msg, "bgn", bgn, "end", end, "src", src == null ? "" : String_.new_u8_by_len(src, bgn, 32));
throw Err_.new_exc(e, "core", msg, "bgn", bgn, "end", end, "src", src == null ? "" : String_.new_u8_by_len(src, bgn, 32));
}
}
public static byte[] mask_(int len, byte... itms) {
@ -372,7 +372,7 @@ public class Bry_ {
if (trim_bgn) {
for (int i = bgn; i < end; i++) {
byte b = src[i];
if (trim_ary[b & 0xFF] == Byte_ascii.Nil) {
if (trim_ary[b & 0xFF] == Byte_ascii.Null) {
txt_bgn = i;
i = end;
all_ws = false;
@ -383,7 +383,7 @@ public class Bry_ {
if (trim_end) {
for (int i = end - 1; i > -1; i--) {
byte b = src[i];
if (trim_ary[b & 0xFF] == Byte_ascii.Nil) {
if (trim_ary[b & 0xFF] == Byte_ascii.Null) {
txt_end = i + 1;
i = -1;
all_ws = false;
@ -610,7 +610,7 @@ public class Bry_ {
public static int Xto_int(byte[] ary) {return Xto_int_or(ary, null, 0, ary.length, -1);}
public static int Xto_int_or_fail(byte[] ary) {
int rv = Xto_int_or(ary, null, 0, ary.length, Int_.MinValue);
if (rv == Int_.MinValue) throw Exc_.new_("could not parse to int", "val", String_.new_u8(ary));
if (rv == Int_.MinValue) throw Err_.new_wo_type("could not parse to int", "val", String_.new_u8(ary));
return rv;
}
public static boolean Xto_bool_by_int_or_fail(byte[] ary) {
@ -618,7 +618,7 @@ public class Bry_ {
switch (rv) {
case 0: return false;
case 1: return true;
default: throw Exc_.new_("could not parse to boolean int", "val", String_.new_u8(ary));
default: throw Err_.new_wo_type("could not parse to boolean int", "val", String_.new_u8(ary));
}
}
public static int Xto_int_or(byte[] ary, int or) {return Xto_int_or(ary, null, 0, ary.length, or);}
@ -735,7 +735,7 @@ public class Bry_ {
f += (ary[bgn + 16] - Ascii_zero) * 100;
f += (ary[bgn + 17] - Ascii_zero) * 10;
f += (ary[bgn + 18] - Ascii_zero);
if (ary[bgn + 19] != lkp) throw Exc_.new_("csv date is invalid", "txt", String_.new_u8_by_len(ary, bgn, 20));
if (ary[bgn + 19] != lkp) throw Err_.new_wo_type("csv date is invalid", "txt", String_.new_u8_by_len(ary, bgn, 20));
posRef.Val_add(19 + 1); // +1=lkp.len
return DateAdp_.new_(y, M, d, H, m, s, f);
}
@ -748,10 +748,10 @@ public class Bry_ {
int pos = bgn + 1; // +1 to skip quote
if (make) bb = Bry_bfr.new_(16);
while (true) {
if (pos == aryLen) throw Exc_.new_("endOfAry reached, but no quote found", "txt", String_.new_u8_by_len(ary, bgn, pos));
if (pos == aryLen) throw Err_.new_wo_type("endOfAry reached, but no quote found", "txt", String_.new_u8_by_len(ary, bgn, pos));
byte b = ary[pos];
if (b == Dlm_quote) {
if (pos == aryLen - 1) throw Exc_.new_("endOfAry reached, quote found but lkp not", "txt", String_.new_u8_by_len(ary, bgn, pos));
if (pos == aryLen - 1) throw Err_.new_wo_type("endOfAry reached, quote found but lkp not", "txt", String_.new_u8_by_len(ary, bgn, pos));
byte next = ary[pos + 1];
if (next == Dlm_quote) { // byte followed by quote
if (make) bb.Add_byte(b);
@ -761,7 +761,7 @@ public class Bry_ {
posRef.Val_(pos + 2); // 1=endQuote;1=lkp;
return make ? bb.Xto_bry() : Bry_.Empty;
}
else throw Exc_.new_("quote found, but not doubled", "txt", String_.new_u8_by_len(ary, bgn, pos + 1));
else throw Err_.new_wo_type("quote found, but not doubled", "txt", String_.new_u8_by_len(ary, bgn, pos + 1));
}
else {
if (make) bb.Add_byte(b);
@ -776,13 +776,13 @@ public class Bry_ {
return make ? Bry_.Mid(ary, bgn, i) : Bry_.Empty;
}
}
throw Exc_.new_("lkp failed", "lkp", (char)lkp, "txt", String_.new_u8_by_len(ary, bgn, aryLen));
throw Err_.new_wo_type("lkp failed", "lkp", (char)lkp, "txt", String_.new_u8_by_len(ary, bgn, aryLen));
}
}
public static int ReadCsvInt(byte[] ary, Int_obj_ref posRef, byte lkp) {
int bgn = posRef.Val();
int pos = Bry_finder.Find_fwd(ary, lkp, bgn, ary.length);
if (pos == Bry_.NotFound) throw Exc_.new_("lkp failed", "lkp", (char)lkp, "bgn", bgn);
if (pos == Bry_.NotFound) throw Err_.new_wo_type("lkp failed", "lkp", (char)lkp, "bgn", bgn);
int rv = Bry_.Xto_int_or(ary, posRef.Val(), pos, -1);
posRef.Val_(pos + 1); // +1 = lkp.Len
return rv;
@ -790,7 +790,7 @@ public class Bry_ {
public static double ReadCsvDouble(byte[] ary, Int_obj_ref posRef, byte lkp) {
int bgn = posRef.Val();
int pos = Bry_finder.Find_fwd(ary, lkp, bgn, ary.length);
if (pos == Bry_.NotFound) throw Exc_.new_("lkp failed", "lkp", (char)lkp, "bgn", bgn);
if (pos == Bry_.NotFound) throw Err_.new_wo_type("lkp failed", "lkp", (char)lkp, "bgn", bgn);
double rv = Bry_.XtoDoubleByPos(ary, posRef.Val(), pos);
posRef.Val_(pos + 1); // +1 = lkp.Len
return rv;
@ -829,7 +829,7 @@ public class Bry_ {
switch (digit) {
case 0: return Byte_ascii.Num_0; case 1: return Byte_ascii.Num_1; case 2: return Byte_ascii.Num_2; case 3: return Byte_ascii.Num_3; case 4: return Byte_ascii.Num_4;
case 5: return Byte_ascii.Num_5; case 6: return Byte_ascii.Num_6; case 7: return Byte_ascii.Num_7; case 8: return Byte_ascii.Num_8; case 9: return Byte_ascii.Num_9;
default: throw Exc_.new_("unknown digit", "digit", digit);
default: throw Err_.new_wo_type("unknown digit", "digit", digit);
}
}
public static byte[][] Split(byte[] src, byte dlm) {return Split(src, dlm, false);}
@ -1032,6 +1032,6 @@ public class Bry_ {
public static byte[] Null_if_empty(byte[] v) {return Len_eq_0(v) ? null : v;}
public static byte Get_at_end(byte[] v) {
int v_len = v.length;
return v_len == 0 ? Byte_ascii.Nil : v[v_len - 1];
return v_len == 0 ? Byte_ascii.Null : v[v_len - 1];
}
}

@ -127,7 +127,7 @@ public class Bry__tst {
}
void tst_ReadCsvStr_err(String raw) {
try {Bry_.ReadCsvStr(Bry_.new_u8(String_.Replace(raw, "'", "\"")), Int_obj_ref.zero_(), (byte)'|');}
catch (Exception e) {Exc_.Noop(e); return;}
catch (Exception e) {Err_.Noop(e); return;}
Tfds.Fail_expdError();
}
@Test public void ReadCsvDte() {

@ -77,7 +77,7 @@ public class Bry_bfr {
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 byte Get_at_last_or_nil_if_empty() {return bfr_len == 0 ? Byte_ascii.Null : bfr[bfr_len - 1];}
public Bry_bfr Add_safe(byte[] val) {return val == null ? this : Add(val);}
public Bry_bfr Add(byte[] val) {
int val_len = val.length;
@ -89,7 +89,7 @@ public class Bry_bfr {
}
public Bry_bfr Add_mid(byte[] val, int bgn, int end) {
int len = end - bgn;
if (len < 0) throw Exc_.new_("negative len", "bgn", bgn, "end", end, "excerpt", String_.new_u8_by_len(val, bgn, bgn + 16)); // NOTE: check for invalid end < bgn, else difficult to debug errors later; DATE:2014-05-11
if (len < 0) throw Err_.new_wo_type("negative len", "bgn", bgn, "end", end, "excerpt", String_.new_u8_by_len(val, bgn, bgn + 16)); // NOTE: check for invalid end < bgn, else difficult to debug errors later; DATE:2014-05-11
if (bfr_len + len > bfr_max) Resize((bfr_max + len) * 2);
Bry_.Copy_by_pos(val, bgn, end, bfr, bfr_len);
// Array_.CopyTo(val, bgn, bfr, bfr_len, len);
@ -124,7 +124,7 @@ public class Bry_bfr {
if (trim_bgn) {
for (int i = 0; i < src_len; i++) {
byte b = src_bry[i];
if (trim_ary[b & 0xFF] == Byte_ascii.Nil) {
if (trim_ary[b & 0xFF] == Byte_ascii.Null) {
src_bgn = i;
i = src_len;
all_ws = false;
@ -135,7 +135,7 @@ public class Bry_bfr {
if (trim_end) {
for (int i = src_len - 1; i > -1; i--) {
byte b = src_bry[i];
if (trim_ary[b & 0xFF] == Byte_ascii.Nil) {
if (trim_ary[b & 0xFF] == Byte_ascii.Null) {
src_end = i + 1;
i = -1;
all_ws = false;
@ -288,7 +288,7 @@ public class Bry_bfr {
bfr_len += bry_len;
return this;
}
catch (Exception e) {throw Exc_.new_exc(e, "core", "invalid UTF-8 sequence", "s", str);}
catch (Exception e) {throw Err_.new_exc(e, "core", "invalid UTF-8 sequence", "s", str);}
}
public Bry_bfr Add_str_a7(String str) {
try {
@ -302,11 +302,12 @@ public class Bry_bfr {
bfr_len += bry_len;
return this;
}
catch (Exception e) {throw Exc_.new_exc(e, "core", "invalid UTF-8 sequence", "s", str);}
catch (Exception e) {throw Err_.new_exc(e, "core", "invalid UTF-8 sequence", "s", str);}
}
public Bry_bfr Add_kv_line(String key, Object val) {
public Bry_bfr Add_kv_dlm(boolean line, String key, Object val) {
this.Add_str_a7(key).Add_byte_colon().Add_byte_space();
this.Add(Bry_.new_u8(Object_.Xto_str_strict_or_null_mark(val))).Add_byte_nl();
this.Add(Bry_.new_u8(Object_.Xto_str_strict_or_null_mark(val)));
this.Add_byte(line ? Byte_ascii.Nl : Byte_ascii.Tab);
return this;
}
public Bry_bfr Add_float(float f) {Add_str(Float_.Xto_str(f)); return this;}

@ -46,7 +46,7 @@ public class Bry_bfr_mkr {
case Tid_b512: return mkr_b512;
case Tid_k004: return mkr_k004;
case Tid_m001: return mkr_m001;
default: throw Exc_.new_unhandled(tid);
default: throw Err_.new_unhandled(tid);
}
}
}
@ -72,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_idx_is_null()) throw Exc_.new_("failed to clear bfr", "idx", Int_.Xto_str(i));
if (!itm.Mkr_idx_is_null()) throw Err_.new_wo_type("failed to clear bfr", "idx", Int_.Xto_str(i));
itm.Clear();
}
ary[i] = null;
@ -104,9 +104,9 @@ class Bry_bfr_mkr_mgr {
int rv_idx = -1;
if (free_len > 0) {
try {rv_idx = free[--free_len];}
catch (Exception e) {throw Exc_.new_exc(e, "core", "failed to get free index", "free_len", free_len, "free.length", free.length);}
catch (Exception e) {throw Err_.new_exc(e, "core", "failed to get free index", "free_len", free_len, "free.length", free.length);}
try {rv = ary[rv_idx];}
catch (Exception e) {throw Exc_.new_exc(e, "core", "failed to get bfr", "rv_idx", rv_idx, "ary.length", ary.length);}
catch (Exception e) {throw Err_.new_exc(e, "core", "failed to get bfr", "rv_idx", rv_idx, "ary.length", ary.length);}
}
else {
if (nxt_idx == ary_max)
@ -146,7 +146,7 @@ class Bry_bfr_mkr_mgr {
// }
public void Rls(int idx) {
synchronized (thread_lock) {
if (idx == -1) throw Exc_.new_("rls called on bfr that was not created by factory");
if (idx == -1) throw Err_.new_wo_type("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;

@ -245,7 +245,7 @@ public class Bry_finder {
case Byte_ascii.Space: case Byte_ascii.Tab: ++cur; break;
default: return cur;
}
} catch (Exception e) {throw Exc_.new_exc(e, "core", "idx is invalid", "cur", cur, "src", src);}
} catch (Exception e) {throw Err_.new_exc(e, "core", "idx is invalid", "cur", cur, "src", src);}
}
}
public static int Find_fwd_while_letter(byte[] src, int cur, int end) {

@ -97,7 +97,6 @@ public class Bry_fmtr {
this.Fmt_(fmt).Bld_bfr_many(bfr, args);
return bfr.Xto_str_and_clear();
}
public String Bld_str_many(String... args) {
if (dirty) Compile();
String_bldr rv = String_bldr_.new_();
@ -172,7 +171,7 @@ public class Bry_fmtr {
else if (cur_byte == char_escape) {
if (fmt_pos == fmt_end) {
if (fail_when_invalid_escapes)
throw Exc_.new_("escape char encountered but no more chars left");
throw Err_.new_wo_type("escape char encountered but no more chars left");
else {
trg_bry[trg_pos] = cur_byte;
break;
@ -196,7 +195,7 @@ public class Bry_fmtr {
else if (nxt_byte == char_escape_nl) tmp_byte = Byte_ascii.Nl;
else if (nxt_byte == char_escape_tab) tmp_byte = Byte_ascii.Tab;
else {
if (fail_when_invalid_escapes) throw Exc_.new_("unknown escape code", "code", Char_.XbyInt(nxt_byte), "fmt_pos", fmt_pos + 1);
if (fail_when_invalid_escapes) throw Err_.new_wo_type("unknown escape code", "code", Char_.XbyInt(nxt_byte), "fmt_pos", fmt_pos + 1);
else
tmp_byte = cur_byte;
}
@ -209,7 +208,7 @@ public class Bry_fmtr {
fmt_pos += 1;
}
}
if (lkp_is_active) throw Exc_.new_("idx mode not closed");
if (lkp_is_active) throw Err_.new_wo_type("idx mode not closed");
if (trg_pos > 0) {list.Add(Bry_fmtr_itm.dat_(trg_bry, trg_pos)); trg_pos = 0;}
itms = (Bry_fmtr_itm[])list.To_ary(Bry_fmtr_itm.class);
itms_len = itms.length;
@ -217,9 +216,9 @@ public class Bry_fmtr {
}
}
int Compile_eval_cmd(byte[] fmt, int fmt_len, int eval_lhs_bgn, List_adp list) {
int eval_lhs_end = Bry_finder.Find_fwd(fmt, char_eval_end, eval_lhs_bgn + Int_.Const_dlm_len, fmt_len); if (eval_lhs_end == Bry_.NotFound) throw Exc_.new_("eval_lhs_end_invalid: could not find eval_lhs_end", "snip", String_.new_u8(fmt, eval_lhs_bgn, fmt_len));
int eval_lhs_end = Bry_finder.Find_fwd(fmt, char_eval_end, eval_lhs_bgn + Int_.Const_dlm_len, fmt_len); if (eval_lhs_end == Bry_.NotFound) throw Err_.new_wo_type("eval_lhs_end_invalid: could not find eval_lhs_end", "snip", String_.new_u8(fmt, eval_lhs_bgn, fmt_len));
byte[] eval_dlm = Bry_.Mid(fmt, eval_lhs_bgn , eval_lhs_end + Int_.Const_dlm_len);
int eval_rhs_bgn = Bry_finder.Find_fwd(fmt, eval_dlm , eval_lhs_end + Int_.Const_dlm_len, fmt_len); if (eval_rhs_bgn == Bry_.NotFound) throw Exc_.new_("eval_rhs_bgn_invalid: could not find eval_rhs_bgn", "snip", String_.new_u8(fmt, eval_lhs_end, fmt_len));
int eval_rhs_bgn = Bry_finder.Find_fwd(fmt, eval_dlm , eval_lhs_end + Int_.Const_dlm_len, fmt_len); if (eval_rhs_bgn == Bry_.NotFound) throw Err_.new_wo_type("eval_rhs_bgn_invalid: could not find eval_rhs_bgn", "snip", String_.new_u8(fmt, eval_lhs_end, fmt_len));
byte[] eval_cmd = Bry_.Mid(fmt, eval_lhs_end + Int_.Const_dlm_len, eval_rhs_bgn);
byte[] eval_rslt = eval_mgr.Eval(eval_cmd);
int eval_rhs_end = eval_rhs_bgn + Int_.Const_dlm_len + eval_dlm.length;

@ -24,13 +24,13 @@ public class Byte_ {
, Min_value = Byte.MIN_VALUE
, Max_value_127 = 127
;
public static byte cast_(Object o) {try {return (Byte)o;} catch (Exception e) {throw Exc_.new_type_mismatch_w_exc(e, byte.class, o);}}
public static byte cast_(Object o) {try {return (Byte)o;} catch (Exception e) {throw Err_.new_type_mismatch_w_exc(e, byte.class, o);}}
public static byte parse_(String raw) {return Byte.parseByte(raw);}
public static byte parse_or_(String raw, byte or) {
if (raw == null) return or;
try {
return parse_(raw);
} catch (Exception e) {Exc_.Noop(e); return or;}
} catch (Exception e) {Err_.Noop(e); return or;}
}
public static byte By_int(int v) {return v > 127 ? (byte)(v - 256) : (byte)v;} // PERF?: (byte)(v & 0xff)
public static int Xto_int(byte v) {return v < 0 ? (int)v + 256 : v;}

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx;
public class Byte_ascii {
public static final byte
Nil = 0 , Backfeed = 8, Tab = 9
Null = 0 , Backfeed = 8, Tab = 9
, Nl = 10, Formfeed = 12, Cr = 13
, Space = 32, Bang = 33, Quote = 34
, Hash = 35, Dollar = 36, Percent = 37, Amp = 38, Apos = 39

@ -71,6 +71,6 @@ public class Char_ {
public static String XtoStr(int b) {return XtoStr((char)b);}
public static String XtoStr(char c) {return String.valueOf(c);}
public static byte XtoByte(char c) {return (byte)c;}
public static char cast_(Object o) {try {return (Character)o;} catch(Exception e) {throw Exc_.new_type_mismatch_w_exc(e, char.class, o);}}
public static char parse_(String raw) {try {return raw.charAt(0);} catch(Exception exc) {throw Exc_.new_parse_exc(exc, char.class, raw);}}
public static char cast_(Object o) {try {return (Character)o;} catch(Exception e) {throw Err_.new_type_mismatch_w_exc(e, char.class, o);}}
public static char parse_(String raw) {try {return raw.charAt(0);} catch(Exception exc) {throw Err_.new_parse_exc(exc, char.class, raw);}}
}

@ -29,12 +29,12 @@ public class Double_ {
, Inf_pos_bry = Bry_.new_a7("INF")
;
public static boolean IsNaN(double v) {return Double.isNaN(v);}
public static double cast_(Object o) {try {return (Double)o;} catch(Exception e) {throw Exc_.new_type_mismatch_w_exc(e, double.class, o);}}
public static double parse_(String raw) {try {return Double.parseDouble(raw);} catch(Exception e) {throw Exc_.new_parse_exc(e, double.class, raw);}}
public static double parse_or(String raw, double v) {try {return Double.parseDouble(raw);} catch(Exception e) {Exc_.Noop(e); return v;}}
public static double cast_(Object o) {try {return (Double)o;} catch(Exception e) {throw Err_.new_type_mismatch_w_exc(e, double.class, o);}}
public static double parse_(String raw) {try {return Double.parseDouble(raw);} catch(Exception e) {throw Err_.new_parse_exc(e, double.class, raw);}}
public static double parse_or(String raw, double v) {try {return Double.parseDouble(raw);} catch(Exception e) {Err_.Noop(e); return v;}}
public static double coerce_(Object v) {
try {String s = String_.as_(v); return s == null ? Double_.cast_(v) : Double_.parse_(s);}
catch (Exception e) {throw Exc_.new_cast(e, double.class, v);}
catch (Exception e) {throw Err_.new_cast(e, double.class, v);}
}
public static String Xto_str(double v) {
int v_int = (int)v;

@ -21,8 +21,8 @@ public class Float_ {
public static final Class<?> Cls_ref_type = Float.class;
public static final float NaN = Float.NaN;;
public static boolean IsNaN(float v) {return Float.isNaN(v);}
public static float cast_(Object obj) {try {return (Float)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, float.class, obj);}}
public static float parse_(String raw) {try {return Float.parseFloat(raw);} catch(Exception exc) {throw Exc_.new_parse_exc(exc, float.class, raw);}}
public static float cast_(Object obj) {try {return (Float)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, float.class, obj);}}
public static float parse_(String raw) {try {return Float.parseFloat(raw);} catch(Exception exc) {throw Err_.new_parse_exc(exc, float.class, raw);}}
public static String Xto_str(float v) {
int v_int = (int)v;
return v - v_int == 0 ? Int_.Xto_str(v_int) : Float.toString(v);

@ -26,7 +26,7 @@ public class Int_ implements GfoInvkAble {
public static final int Null = Int_.MinValue;
public static int coerce_(Object v) {
try {String s = String_.as_(v); return s == null ? Int_.cast_(v) : Int_.parse_(s);}
catch (Exception e) {throw Exc_.new_cast(e, int.class, v);}
catch (Exception e) {throw Err_.new_cast(e, int.class, v);}
}
public static int[] Ary_empty = new int[0];
public static int[] Ary(int... v) {return v;}
@ -85,8 +85,8 @@ public class Int_ implements GfoInvkAble {
public static int Max(int lhs, int rhs) {return lhs > rhs ? lhs : rhs;}
public static int ModIfNeg1(int v, int or) {return v == -1 ? or : v;}
public static boolean RangeCheck(int v, int max) {return v >= 0 && v < max;}
public static void RangeCheckOrFail_list(int v, int max, String s) {if (v < 0 || v >= max) throw Exc_.new_("bounds check failed", "msg", s, "v", v, "min", 0, "max", max - 1);}
public static void RangeCheckOrFail(int v, int min, int max, String s) {if (v < min || v >= max) throw Exc_.new_("bounds check failed", "msg", s, "v", v, "min", min, "max", max);}
public static void RangeCheckOrFail_list(int v, int max, String s) {if (v < 0 || v >= max) throw Err_.new_wo_type("bounds check failed", "msg", s, "v", v, "min", 0, "max", max - 1);}
public static void RangeCheckOrFail(int v, int min, int max, String s) {if (v < min || v >= max) throw Err_.new_wo_type("bounds check failed", "msg", s, "v", v, "min", min, "max", max);}
public static boolean Between(int v, int lhs, int rhs) {
int lhsCompare = v == lhs ? 0 : (v < lhs ? -1 : 1);
int rhsCompare = v == rhs ? 0 : (v < rhs ? -1 : 1);
@ -131,7 +131,7 @@ public class Int_ implements GfoInvkAble {
return rv * sign;
} public static int[] Log10Ary = new int[] {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, Int_.MaxValue}; public static int Log10AryLen = 11;
public Int_ FailIfNeg1(String key, int val) {
if (val < 0) throw Exc_.new_("key must be >= 0", "key", key, "val", val);
if (val < 0) throw Err_.new_wo_type("key must be >= 0", "key", key, "val", val);
return this;
}
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"
@ -155,9 +155,9 @@ public class Int_ implements GfoInvkAble {
return bfr.Xto_str();
}
public static int read_(Object o) {String s = String_.as_(o); return s != null ? Int_.parse_(s) : Int_.cast_(o);}
public static int parse_(String raw) {try {return Integer.parseInt(raw);} catch(Exception e) {throw Exc_.new_parse_exc(e, int.class, raw);}}
public static int cast_(Object obj) {try {return (Integer)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, int.class, obj);}}
public static int cast_or_(Object obj, int or) {try {return (Integer)obj;} catch(Exception e) {Exc_.Noop(e); return or;}}
public static int parse_(String raw) {try {return Integer.parseInt(raw);} catch(Exception e) {throw Err_.new_parse_exc(e, int.class, raw);}}
public static int cast_(Object obj) {try {return (Integer)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, int.class, obj);}}
public static int cast_or_(Object obj, int or) {try {return (Integer)obj;} catch(Exception e) {Err_.Noop(e); return or;}}
public static int Xby_double_(double v) {return (int)v;}
public static String Xto_str(int v) {return new Integer(v).toString();}
public static String Xto_str_fmt(int v, String fmt) {return new java.text.DecimalFormat(fmt).format(v);}

@ -90,6 +90,6 @@ public class Int_ary_ {
return (rv_idx == rv_len) // on the off-chance that rv_len == rv_idx; EX: "1"
? rv
: (int[])Array_.Resize(rv, rv_idx);
} catch (Exception e) {Exc_.Noop(e); return or;}
} catch (Exception e) {Err_.Noop(e); return or;}
}
}

@ -31,11 +31,11 @@ public class Long_ {
, Long_.Pow(10, 15), Long_.Pow(10, 16), Long_.Pow(10, 17), Long_.Pow(10, 18), Long_.Pow(10, 19)
, Long_.MaxValue
};
public static long parse_(String raw) {try {return Long.parseLong(raw);} catch(Exception e) {throw Exc_.new_parse_exc(e, long.class, raw);}}
public static long cast_(Object obj) {try {return (Long)obj;} catch(Exception e) {throw Exc_.new_type_mismatch_w_exc(e, long.class, obj);}}
public static long parse_(String raw) {try {return Long.parseLong(raw);} catch(Exception e) {throw Err_.new_parse_exc(e, long.class, raw);}}
public static long cast_(Object obj) {try {return (Long)obj;} catch(Exception e) {throw Err_.new_type_mismatch_w_exc(e, long.class, obj);}}
public static long coerce_(Object v) {
try {String s = String_.as_(v); return s == null ? Long_.cast_(v) : Long_.parse_(s);}
catch (Exception e) {throw Exc_.new_cast(e, long.class, v);}
catch (Exception e) {throw Err_.new_cast(e, long.class, v);}
}
public static long Xby_int(int v) {return (long)v;}
public static String Xto_str(long v) {return Long.toString(v);}
@ -53,7 +53,7 @@ public class Long_ {
factor *= 10;
}
return rv;
} catch (Exception e) {Exc_.Noop(e); return or;}
} catch (Exception e) {Err_.Noop(e); return or;}
}
public static int Compare(long lhs, long rhs) {
if (lhs == rhs) return CompareAble_.Same;

@ -18,5 +18,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx;
public class Short_ {
public static final Class<?> Cls_ref_type = Short.class;
public static short cast_(Object obj) {try {return (Short)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, short.class, obj);}}
public static short cast_(Object obj) {try {return (Short)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, short.class, obj);}}
}

@ -32,7 +32,7 @@ public class String_ implements GfoInvkAble {
? null
: new String(v, bgn, end - bgn, "ASCII");
}
catch (Exception e) {throw Exc_.new_exc(e, "core", "unsupported encoding");}
catch (Exception e) {throw Err_.new_exc(e, "core", "unsupported encoding");}
}
public static String new_u8(byte[] v) {return v == null ? null : new_u8(v, 0, v.length);}
public static String new_u8(byte[] v, int bgn, int end) {
@ -41,7 +41,7 @@ public class String_ implements GfoInvkAble {
? null
: new String(v, bgn, end - bgn, "UTF-8");
}
catch (Exception e) {throw Exc_.new_exc(e, "core", "unsupported encoding");}
catch (Exception e) {throw Err_.new_exc(e, "core", "unsupported encoding");}
}
public static String new_u8_by_len(byte[] v, int bgn, int len) {
int v_len = v.length;
@ -170,7 +170,7 @@ public class String_ implements GfoInvkAble {
else if (bgn > end) msg = "@bgn > @end";
else if (bgn < 0 || bgn >= len) msg = "@bgn is invalid";
else if (end < 0 || end > len) msg = "@end is invalid";
throw Exc_.new_exc(e, "core", msg, "s", s, "bgn", bgn, "end", end, "len", len);
throw Err_.new_exc(e, "core", msg, "s", s, "bgn", bgn, "end", end, "len", len);
}
}
public static String MidByLenSafe(String s, int bgn, int len) {
@ -179,41 +179,43 @@ public class String_ implements GfoInvkAble {
}
public static String MidByLen(String s, int bgn, int len) {return Mid_lang(s, bgn, len);}
public static String GetStrBefore(String s, String spr) {
int sprPos = String_.FindFwd(s, spr); if (sprPos == String_.Find_none) throw Exc_.new_("could not find spr", "s", s, "spr", spr);
int sprPos = String_.FindFwd(s, spr); if (sprPos == String_.Find_none) throw Err_.new_wo_type("could not find spr", "s", s, "spr", spr);
return Mid(s, 0, sprPos);
}
public static String GetStrAfter(String s, String spr) {
int sprPos = String_.FindFwd(s, spr); if (sprPos == String_.Find_none) throw Exc_.new_("could not find spr", "s", s, "spr", spr);
int sprPos = String_.FindFwd(s, spr); if (sprPos == String_.Find_none) throw Err_.new_wo_type("could not find spr", "s", s, "spr", spr);
return Mid(s, sprPos + 1);
}
public static String LimitToFirst(String s, int len) {
if (len < 0) throw Err_arg.cannotBe_("< 0", "len", len);
if (len < 0) throw Err_.new_invalid_arg("< 0", "len", len);
int sLen = Len(s); if (len > sLen) return s;
return Mid_lang(s, 0, len);
}
public static String LimitToLast(String s, int len) {
if (len < 0) throw Err_arg.cannotBe_("< 0", "len", len);
if (len < 0) throw Err_.new_invalid_arg("< 0", "len", len);
int sLen = Len(s); if (len > sLen) return s;
return Mid_lang(s, sLen - len, len);
}
public static String DelBgn(String s, int count) {
if (count < 0) throw Err_arg.cannotBe_("< 0", "count", count);
if (s == null) throw Err_arg.null_("s");
int len = Len(s); if (count > len) throw Err_arg.cannotBe_("> @len", "count", count).Add("len", len);
if (count < 0) throw Err_.new_invalid_arg("< 0", "count", count);
if (s == null) throw Err_.new_null();
int len = Len(s); if (count > len) throw Err_.new_invalid_arg("> @len", "count", count, "len", len);
return String_.Mid(s, count);
}
public static String DelBgnIf(String s, String find) {
if (s == null) throw Err_arg.null_("s"); if (find == null) throw Err_arg.null_("find");
if (s == null) throw Err_.new_null();
if (find == null) throw Err_.new_null();
return Has_at_bgn(s, find) ? String_.Mid(s, Len(find)) : s;
}
public static String DelEnd(String s, int count) {
if (count < 0) throw Err_arg.cannotBe_("< 0", "count", count);
if (s == null) throw Err_arg.null_("s");
int len = Len(s); if (count > len) throw Err_arg.cannotBe_("> len", "count", count).Add("len", len);
if (count < 0) throw Err_.new_invalid_arg("< 0", "count", count);
if (s == null) throw Err_.new_null();
int len = Len(s); if (count > len) throw Err_.new_invalid_arg("> len", "count", count, "len", len);
return Mid_lang(s, 0, len + -count);
}
public static String DelEndIf(String s, String find) {
if (s == null) throw Err_arg.null_("s"); if (find == null) throw Err_arg.null_("find");
if (s == null) throw Err_.new_null();
if (find == null) throw Err_.new_null();
return Has_at_end(s, find) ? Mid_lang(s, 0, Len(s) - Len(find)) : s;
}
public static String LowerFirst(String s) {
@ -252,14 +254,14 @@ public class String_ implements GfoInvkAble {
return (last == len) ? s : Mid_lang(s, 0, last);
}
public static String Repeat(String s, int count) {
if (count < 0) throw Exc_.new_("count cannot be negative", "count", count, "s", s);
if (count < 0) throw Err_.new_wo_type("count cannot be negative", "count", count, "s", s);
String_bldr sb = String_bldr_.new_();
for (int i = 0; i < count; i++)
sb.Add(s);
return sb.XtoStr();
}
public static String Insert(String s, int pos, String toInsert) {
if (pos < 0 || pos >= String_.Len(s)) throw Exc_.new_("String_.Insert failed; pos invalid", "pos", pos, "s", s, "toInsert", toInsert);
if (pos < 0 || pos >= String_.Len(s)) throw Err_.new_wo_type("String_.Insert failed; pos invalid", "pos", pos, "s", s, "toInsert", toInsert);
return s.substring(0, pos) + toInsert + s.substring(pos);
}
public static String Format(String fmt, Object... args) {return Format_do(fmt, args);}
@ -488,7 +490,7 @@ public class String_ implements GfoInvkAble {
}
public static String read_(Object obj) {// NOTE: same as cast_; for consistent readability only
String rv = as_(obj);
if (rv == null && obj != null) throw Exc_.new_type_mismatch(String.class, obj); // NOTE: obj != null needed; EX: cast_(null) --> null
if (rv == null && obj != null) throw Err_.new_type_mismatch(String.class, obj); // NOTE: obj != null needed; EX: cast_(null) --> null
return rv;
}
public static String[] Ary(byte[]... ary) {

@ -32,7 +32,7 @@ public class String__tst {
err_LimitToFirst("abc", -1);
}
void tst_LimitToFirst(String s, int v, String expd) {Tfds.Eq(expd, String_.LimitToFirst(s, v));}
void err_LimitToFirst(String s, int v) {try {String_.LimitToFirst(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err_arg.class); return;} Tfds.Fail_expdError();}
void err_LimitToFirst(String s, int v) {try {String_.LimitToFirst(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err.class); return;} Tfds.Fail_expdError();}
@Test public void LimitToLast() {
tst_LimitToLast("abc", 0, "");
tst_LimitToLast("abc", 1, "c");
@ -42,7 +42,7 @@ public class String__tst {
err_LimitToLast("abc", -1);
}
void tst_LimitToLast(String s, int v, String expd) {Tfds.Eq(expd, String_.LimitToLast(s, v));}
void err_LimitToLast(String s, int v) {try {String_.LimitToLast(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err_arg.class); return;} Tfds.Fail_expdError();}
void err_LimitToLast(String s, int v) {try {String_.LimitToLast(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err.class); return;} Tfds.Fail_expdError();}
@Test public void DelBgn() {
tst_DelBgn("abc", 0, "abc");
tst_DelBgn("abc", 1, "bc");
@ -52,7 +52,7 @@ public class String__tst {
err_DelBgn("abc", 4);
}
void tst_DelBgn(String s, int v, String expd) {Tfds.Eq(expd, String_.DelBgn(s, v));}
void err_DelBgn(String s, int v) {try {String_.DelBgn(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err_arg.class); return;} Tfds.Fail_expdError();}
void err_DelBgn(String s, int v) {try {String_.DelBgn(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err.class); return;} Tfds.Fail_expdError();}
@Test public void DelBgnIf() {
tst_DelBgnIf("abc", "", "abc");
tst_DelBgnIf("abc", "a", "bc");
@ -64,7 +64,7 @@ public class String__tst {
err_DelBgnIf("abc", null);
}
void tst_DelBgnIf(String s, String v, String expd) {Tfds.Eq(expd, String_.DelBgnIf(s, v));}
void err_DelBgnIf(String s, String v) {try {String_.DelBgnIf(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err_arg.class); return;} Tfds.Fail_expdError();}
void err_DelBgnIf(String s, String v) {try {String_.DelBgnIf(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err.class); return;} Tfds.Fail_expdError();}
@Test public void DelEnd() {
tst_DelEnd("abc", 0, "abc");
tst_DelEnd("abc", 1, "ab");
@ -74,7 +74,7 @@ public class String__tst {
err_DelEnd("abc", 4);
}
void tst_DelEnd(String s, int v, String expd) {Tfds.Eq(expd, String_.DelEnd(s, v));}
void err_DelEnd(String s, int v) {try {String_.DelEnd(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err_arg.class); return;} Tfds.Fail_expdError();}
void err_DelEnd(String s, int v) {try {String_.DelEnd(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err.class); return;} Tfds.Fail_expdError();}
@Test public void DelEndIf() {
tst_DelEndIf("abc", "", "abc");
tst_DelEndIf("abc", "c", "ab");
@ -86,7 +86,7 @@ public class String__tst {
err_DelEndIf("", null);
}
void tst_DelEndIf(String s, String v, String expd) {Tfds.Eq(expd, String_.DelEndIf(s, v));}
void err_DelEndIf(String s, String v) {try {String_.DelEndIf(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err_arg.class); return;} Tfds.Fail_expdError();}
void err_DelEndIf(String s, String v) {try {String_.DelEndIf(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err.class); return;} Tfds.Fail_expdError();}
@Test public void MidByPos() {
tst_MidByPos("abc", 0, 0, "");
tst_MidByPos("abc", 0, 1, "a");
@ -97,7 +97,7 @@ public class String__tst {
// err_MidByPos("abc", 0, 4);
}
void tst_MidByPos(String s, int bgn, int end, String expd) {Tfds.Eq(expd, String_.Mid(s, bgn, end));}
void err_MidByPos(String s, int bgn, int end) {try {String_.Mid(s, bgn, end);} catch (Exception e) {Tfds.Err_classMatch(e, Exc.class); return;} Tfds.Fail_expdError();}
void err_MidByPos(String s, int bgn, int end) {try {String_.Mid(s, bgn, end);} catch (Exception e) {Tfds.Err_classMatch(e, Err.class); return;} Tfds.Fail_expdError();}
@Test public void TrimEnd() {
tst_TrimEnd("a", "a");
tst_TrimEnd("a ", "a");

@ -49,7 +49,7 @@ public class DateAdp implements CompareAble, GfoInvkAble {
case DateAdp_.SegIdx_dayOfWeek: return this.DayOfWeek();
case DateAdp_.SegIdx_weekOfYear: return this.WeekOfYear();
case DateAdp_.SegIdx_dayOfYear: return this.DayOfYear();
default: throw Exc_.new_unhandled(segmentIdx);
default: throw Err_.new_unhandled(segmentIdx);
}
}
public int[] XtoSegAry() {

@ -46,10 +46,10 @@ public class DateAdp_ implements GfoInvkAble {
int f = ary_len > 6 ? ary[6] : 0;
return new DateAdp(y, M, d, h, m, s, f);
}
public static DateAdp cast_(Object arg) {try {return (DateAdp)arg;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, DateAdp.class, arg);}}
public static DateAdp cast_(Object arg) {try {return (DateAdp)arg;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, DateAdp.class, arg);}}
public static DateAdp parse_iso8561_or(String raw, DateAdp or) {
try {return parse_iso8561(raw);}
catch (Exception e) {Exc_.Noop(e); return or;}
catch (Exception e) {Err_.Noop(e); return or;}
}
public static DateAdp parse_iso8561(String raw) { // NOTE: for now, same as parse_gplx
int[] ary = date_parser.Parse_iso8651_like(raw);
@ -89,7 +89,7 @@ public class DateAdp_ implements GfoInvkAble {
SimpleDateFormat sdf = new SimpleDateFormat();
Date d = null;
try {d = sdf.parse(raw);}
catch (ParseException e) {throw Exc_.new_w_type("parse", "failed to parse to DateAdp", "raw", raw);}
catch (ParseException e) {throw Err_.new_("parse", "failed to parse to DateAdp", "raw", raw);}
GregorianCalendar cal = (GregorianCalendar)Calendar.getInstance();
cal.setTime(d);
return dateTime_(cal);
@ -100,7 +100,7 @@ public class DateAdp_ implements GfoInvkAble {
SimpleDateFormat sdf = new SimpleDateFormat(fmt, Locale.US);
Date d = null;
try {d = sdf.parse(raw);}
catch (ParseException e) {throw Exc_.new_w_type("parse", "failed to parse to DateAdp", "raw", raw, "fmt", fmt);}
catch (ParseException e) {throw Err_.new_("parse", "failed to parse to DateAdp", "raw", raw, "fmt", fmt);}
GregorianCalendar cal = (GregorianCalendar)Calendar.getInstance();
cal.setTime(d);
return dateTime_(cal);

@ -33,7 +33,7 @@ public class DateAdp_parser {
int pos = bgn, rv_idx = 0, int_len = 0, max_len = max_lens[rv_idx];
while (true) {
int int_val = -1;
byte b = pos < end ? src[pos] : Byte_ascii.Nil;
byte b = pos < end ? src[pos] : Byte_ascii.Null;
switch (b) {
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
@ -58,19 +58,19 @@ public class DateAdp_parser {
}
class IntBldr {
public int Add(char c) {
if (idx > digitsLen - 1) throw Exc_.new_missing_idx(idx, digitsLen);
if (idx > digitsLen - 1) throw Err_.new_missing_idx(idx, digitsLen);
digits[idx++] = XbyChar(c);
return idx;
}
public int Add(int i) {
if (idx > digitsLen - 1) throw Exc_.new_missing_idx(idx, digitsLen);
if (idx > digitsLen - 1) throw Err_.new_missing_idx(idx, digitsLen);
digits[idx++] = i;
return idx;
}
public int Parse(String raw) {
ParseStr(raw);
try {return Bld();}
catch (Exception exc) {throw Exc_.new_parse_exc(exc, int.class, raw);}
catch (Exception exc) {throw Err_.new_parse_exc(exc, int.class, raw);}
}
public boolean ParseTry(String raw) {
ParseStr(raw);
@ -82,7 +82,7 @@ class IntBldr {
int rv = 0, exponent = 1;
for (int i = idx - 1; i > -1; i--) {
int digit = digits[i];
if (digit < 0) throw Exc_.new_("invalid char", "char", (char)-digits[i], "ascii", -digits[i]);
if (digit < 0) throw Err_.new_wo_type("invalid char", "char", (char)-digits[i], "ascii", -digits[i]);
rv += digit * exponent;
exponent *= 10;
}

@ -43,7 +43,7 @@ import java.math.BigDecimal; import java.math.MathContext; import java.math.Roun
else if (v > 999999 && v < 10000000) return 10000000;
else if (v > 9999999 && v < 100000000) return 100000000;
else if (v > 99999999 && v < 1000000000) return 1000000000;
else throw Exc_.new_("value must be between 0 and 1 billion", "v", v);
else throw Err_.new_wo_type("value must be between 0 and 1 billion", "v", v);
}
public static String CalcPctStr(long dividend, long divisor, String fmt) {
if (divisor == 0) return "%ERR";

@ -22,7 +22,7 @@ public class Io_url_ {
public static final Io_url NullPtr = null;
public static final Io_url Parser = new Io_url("", IoUrlInfo_.Nil);
public static Io_url as_(Object obj) {return obj instanceof Io_url ? (Io_url)obj : null;}
public static Io_url cast_(Object obj) {try {return (Io_url)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, Io_url.class, obj);}}
public static Io_url cast_(Object obj) {try {return (Io_url)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, Io_url.class, obj);}}
public static Io_url Usr() {
if (usr_dir == null) {
switch (Op_sys.Cur().Tid()) {
@ -30,7 +30,7 @@ public class Io_url_ {
case Op_sys.Tid_lnx: usr_dir = Io_url_.new_inf_(String_.Format("/home/{0}/", Env_.UserName()), IoUrlInfo_.Lnx); break;
case Op_sys.Tid_osx: usr_dir = Io_url_.new_inf_(String_.Format("/Users/{0}/", Env_.UserName()), IoUrlInfo_.Lnx); break;
case Op_sys.Tid_drd: usr_dir = Io_url_.new_inf_(String_.Format("/mnt/{0}/", Env_.UserName()), IoUrlInfo_.Lnx); break;
default: throw Exc_.new_unhandled(Op_sys.Cur().Tid());
default: throw Err_.new_unhandled(Op_sys.Cur().Tid());
}
}
return usr_dir;

@ -45,7 +45,7 @@ public class KeyValHash {
}
public KeyVal FetchOrNull(String key) {return KeyVal_.as_(hash.Get_by(key));}
public static KeyValHash strAry_(String[] ary) {// needed for consoleLine
int aryLen = Array_.Len(ary); if (aryLen % 2 != 0) throw Exc_.new_("array length must be divisible by 2", "aryLen", aryLen, "ary", String_.Concat_lines_crlf(ary));
int aryLen = Array_.Len(ary); if (aryLen % 2 != 0) throw Err_.new_wo_type("array length must be divisible by 2", "aryLen", aryLen, "ary", String_.Concat_lines_crlf(ary));
KeyValHash rv = new KeyValHash();
String key = null;
for (int i = 0; i < aryLen; i++) {

@ -28,7 +28,7 @@ public class KeyValHash_tst {
tst_AryVals(ary_("key1"), kv_("key1", "1"));
Tfds.Fail_expdError();
}
catch (Exception e) {Exc_.Noop(e);}
catch (Exception e) {Err_.Noop(e);}
}
void tst_AryVals(String[] ary, KeyVal... expd) {Tfds.Eq_ary_str(expd, KeyValHash.strAry_(ary).Xto_bry());}
KeyVal kv_(String key, Object val) {return KeyVal_.new_(key, val);}

@ -22,7 +22,7 @@ public class KeyVal_ {
public static KeyVal[] Ary(KeyVal... ary) {return ary;}
public static KeyVal[] Ary_cast_(Object o) {
try {return (KeyVal[])o;}
catch (Exception e) {throw Exc_.new_cast(e, KeyVal.class, o);}
catch (Exception e) {throw Err_.new_cast(e, KeyVal.class, o);}
}
public static KeyVal[] Ary_insert(KeyVal[] orig, boolean insert_at_end, KeyVal... vals) {
int orig_len = orig.length, vals_len = vals.length;

@ -157,6 +157,6 @@ public class TimeSpanAdp_ {
@gplx.Internal protected static final int Idx_Hour = 3;
static int[] ZeroPadding = {3, 2, 2, 2,};
static String[] Sprs = {".", MajorDelimiter, MajorDelimiter, "",};
public static TimeSpanAdp cast_(Object arg) {try {return (TimeSpanAdp)arg;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, TimeSpanAdp.class, arg);}}
public static TimeSpanAdp cast_(Object arg) {try {return (TimeSpanAdp)arg;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, TimeSpanAdp.class, arg);}}
public static final double Ratio_f_to_s = 1000;
}

@ -36,12 +36,12 @@ public class Yn {
case Bool_.N_int: return false;
case Bool_.Y_int: return true;
case Bool_.__int: return or;
default: throw Exc_.new_unhandled(v_int);
default: throw Err_.new_unhandled(v_int);
}
}
public static boolean parse_(String v) {
int v_int = parse_as_int(v);
if (v_int == Bool_.__int) Exc_.new_unhandled(v);
if (v_int == Bool_.__int) Err_.new_unhandled(v);
return v_int == Bool_.Y_int;
}
public static String Xto_str(boolean v) {return v ? "y" : "n";}
@ -50,7 +50,7 @@ public class Yn {
case Bool_.Y_byte: return "y";
case Bool_.N_byte: return "n";
case Bool_.__byte: return "?";
default: throw Exc_.new_unhandled(v);
default: throw Err_.new_unhandled(v);
}
}
public static byte Xto_nullable_byte(String v) {
@ -62,7 +62,7 @@ public class Yn {
case '?': return Bool_.__byte;
}
}
throw Exc_.new_unhandled(v);
throw Err_.new_unhandled(v);
}
public static boolean store_bool_or(SrlMgr mgr, String key, boolean or) {
String v = mgr.SrlStrOr(key, "");

@ -26,8 +26,8 @@ class Hash_adp_noop implements Hash_adp {
public int Count() {return 0;}
public boolean Has(Object key) {return false;}
public Object Get_by(Object key) {return null;}
public Object Get_by_or_fail(Object key) {throw Exc_.new_missing_key(Object_.Xto_str_strict_or_null_mark(key));}
public Object Get_by_or_new(Object key, NewAble proto) {throw Exc_.new_("could not add to null hash");}
public Object Get_by_or_fail(Object key) {throw Err_.new_missing_key(Object_.Xto_str_strict_or_null_mark(key));}
public Object Get_by_or_new(Object key, NewAble proto) {throw Err_.new_wo_type("could not add to null hash");}
public void Add(Object key, Object val) {}
public void Add_as_key_and_val(Object val) {}
public void Add_if_dupe_use_nth(Object key, Object val) {}

@ -177,7 +177,7 @@ class Hash_adp_bry_itm_ci_utf8 extends Hash_adp_bry_itm_base {
case Gfo_case_mgr_.Tid_ascii: if (Itm_ascii == null) Itm_ascii = new Hash_adp_bry_itm_ci_utf8(case_mgr); return Itm_ascii;
case Gfo_case_mgr_.Tid_utf8: if (Itm_utf8 == null) Itm_utf8 = new Hash_adp_bry_itm_ci_utf8(case_mgr); return Itm_utf8;
case Gfo_case_mgr_.Tid_custom: return new Hash_adp_bry_itm_ci_utf8(case_mgr);
default: throw Exc_.new_unhandled(case_mgr.Tid());
default: throw Err_.new_unhandled(case_mgr.Tid());
}
}
private static Hash_adp_bry_itm_ci_utf8 Itm_ascii, Itm_utf8;

@ -41,7 +41,7 @@ public abstract class List_adp_base implements List_adp, GfoInvkAble {
public void Add_many(Object... ary) {for (Object o : ary) Add_base(o);}
public int Count() {return count;}
public int Idx_last() {return count - 1;}
protected Object Get_at_base(int index) {if (index >= count || index < 0) throw Exc_.new_missing_idx(index, count);
protected Object Get_at_base(int index) {if (index >= count || index < 0) throw Err_.new_missing_idx(index, count);
return list[index];
}
protected void Add_base(Object o) {
@ -80,11 +80,11 @@ public abstract class List_adp_base implements List_adp, GfoInvkAble {
list[i] = null;
count = 0;
}
@gplx.Virtual public void Del_at(int index) {if (index >= count || index < 0) throw Exc_.new_missing_idx(index, count);
@gplx.Virtual public void Del_at(int index) {if (index >= count || index < 0) throw Err_.new_missing_idx(index, count);
Collapse(index);
count--;
}
public void Move_to(int src, int trg) {if (src >= count || src < 0) throw Exc_.new_missing_idx(src, count); if (trg >= count || trg < 0) throw Exc_.new_missing_idx(trg, count);
public void Move_to(int src, int trg) {if (src >= count || src < 0) throw Err_.new_missing_idx(src, count); if (trg >= count || trg < 0) throw Err_.new_missing_idx(trg, count);
if (src == trg) return; // position not changed
Object o = list[src];
int dif = trg > src ? 1 : -1;
@ -124,7 +124,7 @@ public abstract class List_adp_base implements List_adp, GfoInvkAble {
}
public String[] To_str_ary() {return (String[])To_ary(String.class);}
public Object Get_at(int i) {return Get_at_base(i);}
public Object Get_at_last() {if (count == 0) throw Exc_.new_invalid_op("cannot call Get_at_last on empty list"); return Get_at_base(count - 1);}
public Object Get_at_last() {if (count == 0) throw Err_.new_invalid_op("cannot call Get_at_last on empty list"); return Get_at_base(count - 1);}
public void Add(Object item) {Add_base(item);}
public void Add_at(int i, Object o) {AddAt_base(i, o);}
public void Del(Object item) {Del_base(item);}
@ -140,7 +140,7 @@ public abstract class List_adp_base implements List_adp, GfoInvkAble {
&& end >= 0 && end < len
&& bgn <= end
) return;
throw Exc_.new_("bounds check failed", "bgn", bgn, "end", end, "len", len);
throw Err_.new_wo_type("bounds check failed", "bgn", bgn, "end", end, "len", len);
}
void Resize_expand() {Resize_expand(count * 2);}
void Resize_expand(int newCount) {

@ -52,7 +52,7 @@ public class List_adp_tst {
}
@Test public void FetchAt_fail() {
try {list.Get_at(0);}
catch (Exception exc) {Exc_.Noop(exc); return;}
catch (Exception exc) {Err_.Noop(exc); return;}
Tfds.Fail("Get_at should fail for out of bound index");
}
@Test public void Del_at() {
@ -72,7 +72,7 @@ public class List_adp_tst {
}
@Test public void DelAt_fail() {
try {list.Del_at(0);}
catch (Exception exc) {Exc_.Noop(exc); return;}
catch (Exception exc) {Err_.Noop(exc); return;}
Tfds.Fail("Del_at should fail for out of bound index");
}
@Test public void Del() {

@ -54,11 +54,11 @@ public class Ordered_hash_base extends Hash_adp_base implements Ordered_hash, Gf
AssertCounts();
}
void AssertCounts() {
if (super.Count() != ordered.Count()) throw Exc_.new_("counts do not match", "hash", super.Count(), "list", ordered.Count());
if (super.Count() != ordered.Count()) throw Err_.new_wo_type("counts do not match", "hash", super.Count(), "list", ordered.Count());
}
public void Resize_bounds(int i) {if (locked) Lock_fail(); ordered.Resize_bounds(i);}
public void Lock() {locked = true;} private boolean locked = false;
void Lock_fail() {throw Exc_.new_("collection is locked");}
void Lock_fail() {throw Err_.new_wo_type("collection is locked");}
static final String GRP_KEY = "gplx.lists.ordered_hash";
public void Add_at(int i, Object o) {if (locked) Lock_fail(); ordered.Add_at(i, o);}
public Object Get_at(int i) {return Get_at_base(i);}

@ -41,8 +41,8 @@ public abstract class Hash_adp_base implements Hash_adp {
}
@gplx.Virtual public void Del(Object key) {Del_base(key);}
protected Object FetchOrFail_base(Object key) {
if (key == null) throw Exc_.new_("key cannot be null");
if (!Has_base(key)) throw Exc_.new_("key not found", "key", key);
if (key == null) throw Err_.new_wo_type("key cannot be null");
if (!Has_base(key)) throw Err_.new_wo_type("key not found", "key", key);
return Fetch_base(key);
}

@ -48,7 +48,7 @@ public class Utf16_ {
| ( ary[pos + 3] & 0x3f)
;
}
else throw Exc_.new_("invalid utf8 byte", "byte", b0);
else throw Err_.new_wo_type("invalid utf8 byte", "byte", b0);
}
public static byte[] Encode_hex_to_bry(String raw) {return Encode_hex_to_bry(Bry_.new_a7(raw));}
public static byte[] Encode_hex_to_bry(byte[] raw) {
@ -75,7 +75,7 @@ public class Utf16_ {
}
else if((c > 55295) // 0xD800
&& (c < 56320)) { // 0xDFFF
if (c_pos >= c_ary.length) throw Exc_.new_("incomplete surrogate pair at end of String", "char", c);
if (c_pos >= c_ary.length) throw Err_.new_wo_type("incomplete surrogate pair at end of String", "char", c);
char nxt_char = c_ary[c_pos + 1];
int v = Surrogate_merge(c, nxt_char);
b_ary[b_pos] = (byte)(0xF0 | (v >> 18));
@ -115,7 +115,7 @@ public class Utf16_ {
src[++pos] = (byte)(0x80 | (c & 0x3F));
return 4;
}
else throw Exc_.new_("UTF-16 int must be between 0 and 2097152", "char", c);
else throw Err_.new_wo_type("UTF-16 int must be between 0 and 2097152", "char", c);
}
private static int Len_by_int(int c) {
if ((c > -1)
@ -123,7 +123,7 @@ public class Utf16_ {
else if (c < 2048) return 2; // 1 << 11
else if (c < 65536) return 3; // 1 << 16
else if (c < 2097152) return 4;
else throw Exc_.new_("UTF-16 int must be between 0 and 2097152", "char", c);
else throw Err_.new_wo_type("UTF-16 int must be between 0 and 2097152", "char", c);
}
public static int Len_by_char(int c) {
if ((c > -1)
@ -132,6 +132,6 @@ public class Utf16_ {
else if((c > 55295) // 0xD800
&& (c < 56320)) return 4; // 0xDFFF
else if (c < 65536) return 3; // 1 << 16
else throw Exc_.new_("UTF-16 int must be between 0 and 65536", "char", c);
else throw Err_.new_wo_type("UTF-16 int must be between 0 and 65536", "char", c);
}
}

@ -51,7 +51,7 @@ public class Utf8_ {
return 3;
case 240: case 241: case 242: case 243: case 244: case 245: case 246: case 247:
return 4;
default: throw Exc_.new_("invalid initial utf8 byte", "byte", b);
default: throw Err_.new_wo_type("invalid initial utf8 byte", "byte", b);
}
}
public static byte[] Get_char_at_pos_as_bry(byte[] bry, int pos) {

@ -23,7 +23,7 @@ public class CharStream {
public boolean AtBgn() {return pos <= BgnPos;}
public boolean AtEnd() {return pos >= len;}
public boolean AtMid() {return pos > BgnPos && pos < len;}
public char Cur() {try {return ary[pos];} catch (Exception exc) {Exc_.Noop(exc); throw Exc_.new_missing_idx(pos, this.Len());}}
public char Cur() {try {return ary[pos];} catch (Exception exc) {Err_.Noop(exc); throw Err_.new_missing_idx(pos, this.Len());}}
public void MoveNext() {pos++;}
public void MoveNextBy(int offset) {pos += offset;}
public void MoveBack() {pos--;}

@ -46,7 +46,7 @@ public class HexDecUtl {
return rv;
}
public static int parse_(String raw) {
int rv = parse_or_(raw, -1); if (rv == -1) throw Exc_.new_parse("HexDec", "raw");
int rv = parse_or_(raw, -1); if (rv == -1) throw Err_.new_parse("HexDec", "raw");
return rv;
}
public static String XtoStr(int val, int pad) {
@ -74,7 +74,7 @@ public class HexDecUtl {
case 0: return '0'; case 1: return '1'; case 2: return '2'; case 3: return '3'; case 4: return '4';
case 5: return '5'; case 6: return '6'; case 7: return '7'; case 8: return '8'; case 9: return '9';
case 10: return 'A'; case 11: return 'B'; case 12: return 'C'; case 13: return 'D'; case 14: return 'E'; case 15: return 'F';
default: throw Exc_.new_parse("hexstring", Int_.Xto_str(val));
default: throw Err_.new_parse("hexstring", Int_.Xto_str(val));
}
}
static byte Xto_byte(int v) {
@ -82,7 +82,7 @@ public class HexDecUtl {
case 0: return Byte_ascii.Num_0; case 1: return Byte_ascii.Num_1; case 2: return Byte_ascii.Num_2; case 3: return Byte_ascii.Num_3; case 4: return Byte_ascii.Num_4;
case 5: return Byte_ascii.Num_5; case 6: return Byte_ascii.Num_6; case 7: return Byte_ascii.Num_7; case 8: return Byte_ascii.Num_8; case 9: return Byte_ascii.Num_9;
case 10: return Byte_ascii.Ltr_A; case 11: return Byte_ascii.Ltr_B; case 12: return Byte_ascii.Ltr_C; case 13: return Byte_ascii.Ltr_D; case 14: return Byte_ascii.Ltr_E; case 15: return Byte_ascii.Ltr_F;
default: throw Exc_.new_parse("hexstring", Int_.Xto_str(v));
default: throw Err_.new_parse("hexstring", Int_.Xto_str(v));
}
}
public static void Write(byte[] bry, int bgn, int end, int val) {

@ -23,7 +23,7 @@ public class RegxPatn_cls_ioMatch_ {
public static final RegxPatn_cls_ioMatch All = RegxPatn_cls_ioMatch_.parse_(Wildcard, false);
public static final String ImpossiblePath = "<>"; //"<>" should be an impossible url; NOTE: do not pick * or | or : or \
public static final RegxPatn_cls_ioMatch None = RegxPatn_cls_ioMatch_.parse_(RegxPatn_cls_ioMatch_.ImpossiblePath, false);
public static RegxPatn_cls_ioMatch cast_(Object obj) {try {return (RegxPatn_cls_ioMatch)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, RegxPatn_cls_ioMatch.class, obj);}}
public static RegxPatn_cls_ioMatch cast_(Object obj) {try {return (RegxPatn_cls_ioMatch)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, RegxPatn_cls_ioMatch.class, obj);}}
public static RegxPatn_cls_ioMatch parse_(String raw, boolean caseSensitive) {
String compiled = RegxPatn_cls_ioMatch_.Compile(raw);
return new RegxPatn_cls_ioMatch(raw, compiled, caseSensitive);

@ -33,7 +33,7 @@ public class RegxPatn_cls_like_ {
if (c == escape) { // escape: ignore cur, append next
i++;
if (i < rawLen) sb.Add(String_.CharAt(raw, i));
else throw Exc_.new_("escape cannot be last char", "raw", raw, "escape", escape, "i", i);
else throw Err_.new_wo_type("escape cannot be last char", "raw", raw, "escape", escape, "i", i);
}
else if (c == Wildcard) { // % -> .*
sb.Add(RegxBldr.Tkn_AnyChar).Add(RegxBldr.Tkn_Wild_0Plus);

@ -42,7 +42,7 @@ public class StringTableBldr {
String[] row = (String[])rows.Get_at(rowI);
for (int colI = 0; colI < row.length; colI++) {
if (colI != 0) sb.Add(" ");
StringTableCol col = StringTableCol.as_(cols.Get_at(colI)); if (col == null) throw Exc_.new_missing_idx(colI, cols.Count());
StringTableCol col = StringTableCol.as_(cols.Get_at(colI)); if (col == null) throw Err_.new_missing_idx(colI, cols.Count());
sb.Add(col.PadCell(row[colI]));
}
sb.Add(String_.CrLf);

@ -31,9 +31,9 @@ public class StringTableCol {
if (val == StringTableColAlign.Left.Val()) return cell + String_.Repeat(" ", diff);
else if (val == StringTableColAlign.Right.Val()) return String_.Repeat(" ", diff) + cell;
else if (val == StringTableColAlign.Mid.Val()) return String_.Concat(String_.Repeat(" ", diff / 2), cell, String_.Repeat(" ", (diff / 2) + (diff % 2)));
else throw Exc_.new_unhandled(halign.Val());
else throw Err_.new_unhandled(halign.Val());
}
public static StringTableCol new_() {return new StringTableCol();} StringTableCol() {}
public static StringTableCol as_(Object obj) {return obj instanceof StringTableCol ? (StringTableCol)obj : null;}
public static StringTableCol cast_(Object obj) {try {return (StringTableCol)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, StringTableCol.class, obj);}}
public static StringTableCol cast_(Object obj) {try {return (StringTableCol)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, StringTableCol.class, obj);}}
}

@ -16,9 +16,10 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.security; import gplx.*;
import gplx.core.consoles.*;
import gplx.ios.*; /*IoStream*/
public interface HashAlgo {
String Key();
String CalcHash(ConsoleDlg dialog, IoStream stream);
String CalcHash(Console_adp dialog, IoStream stream);
byte[] Calc_hash_bry(byte[] v);
}

@ -19,6 +19,7 @@ package gplx.security; import gplx.*;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import gplx.core.consoles.*;
import gplx.ios.*; /*IoStream*/import gplx.texts.*; /*Base32Converter*/
public class HashAlgo_ {
public static final HashAlgo Null = new HashAlgo_null();
@ -26,12 +27,12 @@ public class HashAlgo_ {
public static final HashAlgo Md5 = HashAlgo_md5.new_();
public static final HashAlgo Tth192 = HashAlgo_tth192.new_();
public static HashAlgo as_(Object obj) {return obj instanceof HashAlgo ? (HashAlgo)obj : null;}
public static HashAlgo cast_(Object obj) {if (obj == null) return null; HashAlgo rv = as_(obj); if (rv == null) throw Exc_.new_type_mismatch(HashAlgo.class, obj); return rv;}
public static HashAlgo cast_(Object obj) {if (obj == null) return null; HashAlgo rv = as_(obj); if (rv == null) throw Err_.new_type_mismatch(HashAlgo.class, obj); return rv;}
public static HashAlgo fetch_(String key) {
if (key == HashAlgo_md5.KEY) return Md5;
else if (key == HashAlgo_sha1.KEY) return Sha1;
else if (key == HashAlgo_tth192.KEY) return Tth192;
else throw Exc_.new_unhandled(key);
else throw Err_.new_unhandled(key);
}
public static HashAlgo store_orSelf_(SrlMgr mgr, String key, HashAlgo or) {
String algoType = mgr.SrlStrOr(key, or.Key());
@ -40,26 +41,26 @@ public class HashAlgo_ {
}
class HashAlgo_null implements HashAlgo {
public String Key() {return "HashAlgo_null";}
public byte[] Calc_hash_bry(byte[] v) {return Bry_.new_a7(CalcHash(ConsoleDlg_.Null, gplx.ios.IoStream_.ary_(v)));}
public String CalcHash(ConsoleDlg dialog, IoStream stream) {return "NullAlgoHash";}
public byte[] Calc_hash_bry(byte[] v) {return Bry_.new_a7(CalcHash(Console_adp_.Noop, gplx.ios.IoStream_.ary_(v)));}
public String CalcHash(Console_adp dialog, IoStream stream) {return "NullAlgoHash";}
}
class HashAlgo_md5 implements HashAlgo {
public String Key() {return KEY;} public static final String KEY = "md5";
public byte[] Calc_hash_bry(byte[] v) {return Bry_.new_a7(CalcHash(ConsoleDlg_.Null, gplx.ios.IoStream_.ary_(v)));}
public String CalcHash(ConsoleDlg dialog, IoStream stream) {return HashAlgoUtl.CalcHashAsString(dialog, stream, "MD5");}
public byte[] Calc_hash_bry(byte[] v) {return Bry_.new_a7(CalcHash(Console_adp_.Noop, gplx.ios.IoStream_.ary_(v)));}
public String CalcHash(Console_adp dialog, IoStream stream) {return HashAlgoUtl.CalcHashAsString(dialog, stream, "MD5");}
public static HashAlgo_md5 new_() {return new HashAlgo_md5();} HashAlgo_md5() {}
}
class HashAlgo_sha1 implements HashAlgo {
public String Key() {return KEY;} public static final String KEY = "sha1";
public byte[] Calc_hash_bry(byte[] v) {return Bry_.new_a7(CalcHash(ConsoleDlg_.Null, gplx.ios.IoStream_.ary_(v)));}
public String CalcHash(ConsoleDlg dialog, IoStream stream) {return HashAlgoUtl.CalcHashAsString(dialog, stream, "SHA1");}
public byte[] Calc_hash_bry(byte[] v) {return Bry_.new_a7(CalcHash(Console_adp_.Noop, gplx.ios.IoStream_.ary_(v)));}
public String CalcHash(Console_adp dialog, IoStream stream) {return HashAlgoUtl.CalcHashAsString(dialog, stream, "SHA1");}
public static HashAlgo_sha1 new_() {return new HashAlgo_sha1();} HashAlgo_sha1() {}
}
class HashAlgoUtl {
public static String CalcHashAsString(ConsoleDlg dialog, IoStream stream, String key) {
public static String CalcHashAsString(Console_adp dialog, IoStream stream, String key) {
MessageDigest md = null;
try {md = MessageDigest.getInstance(key);}
catch (NoSuchAlgorithmException e) {throw Err_arg.notFound_key_("key", key);}
catch (NoSuchAlgorithmException e) {throw Err_.new_missing_key(key);}
byte[] buffer = new byte[8192];
int read = 0;
long pos = 0, len = stream.Len(); // pos and len must be long, else will not hash files > 2 GB

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.security; import gplx.*;
import org.junit.*;
import gplx.ios.*; /*IoStream*/
import gplx.core.consoles.*; import gplx.ios.*; /*IoStream*/
public class HashAlgo_md5_tst {
@Test public void Empty() {
tst_CalcBase16FromString("", "d41d8cd98f00b204e9800998ecf8427e");
@ -37,7 +37,7 @@ public class HashAlgo_md5_tst {
}
void tst_CalcBase16FromString(String raw, String expd) {
IoStream stream = IoStream_.mem_txt_(Io_url_.Empty, raw);
String actl = HashAlgo_.Md5.CalcHash(ConsoleDlg_.Null, stream);
String actl = HashAlgo_.Md5.CalcHash(Console_adp_.Noop, stream);
Tfds.Eq(expd, actl);
}
/*

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.security; import gplx.*;
import org.junit.*;
import gplx.ios.*; /*IoStream*/
import gplx.core.consoles.*; import gplx.ios.*; /*IoStream*/
public class HashAlgo_sha1_tst {
@Test public void Empty() {
tst_CalcBase16FromString("", "da39a3ee5e6b4b0d3255bfef95601890afd80709");
@ -37,7 +37,7 @@ public class HashAlgo_sha1_tst {
}
void tst_CalcBase16FromString(String raw, String expd) {
IoStream stream = IoStream_.mem_txt_(Io_url_.Empty, raw);
String actl = HashAlgo_.Sha1.CalcHash(ConsoleDlg_.Null, stream);
String actl = HashAlgo_.Sha1.CalcHash(Console_adp_.Noop, stream);
Tfds.Eq(expd, actl);
}
/*

@ -16,12 +16,13 @@ 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.security; import gplx.*;
import gplx.core.consoles.*;
import gplx.ios.*; /*IoStream*/
public class HashAlgo_tth192 implements HashAlgo {
public String Key() {return KEY;} public static final String KEY = "tth192";
public int BlockSize() {return blockSize;} public void BlockSize_set(int v) {blockSize = v;} int blockSize = 1024;
public byte[] Calc_hash_bry(byte[] v) {return Bry_.new_a7(CalcHash(ConsoleDlg_.Null, gplx.ios.IoStream_.ary_(v)));}
public String CalcHash(ConsoleDlg dialog, IoStream stream) {
public byte[] Calc_hash_bry(byte[] v) {return Bry_.new_a7(CalcHash(Console_adp_.Noop, gplx.ios.IoStream_.ary_(v)));}
public String CalcHash(Console_adp dialog, IoStream stream) {
int leafCount = (int)(stream.Len() / blockSize);
HashDlgWtr dialogWtr = HashDlgWtr_.Current;
dialogWtr.Bgn(dialog, stream.Url(), CalcWorkUnits(stream.Len()));
@ -136,7 +137,7 @@ public class HashAlgo_tth192 implements HashAlgo {
}
interface HashDlgWtr {
boolean Canceled();
void Bgn(ConsoleDlg dialog, Io_url url, int total);
void Bgn(Console_adp dialog, Io_url url, int total);
void Do(int increment);
void End();
void Fail(IoStream stream);
@ -148,9 +149,9 @@ class HashDlgWtrDefault implements HashDlgWtr {
public int Total() {return total;} int total;
public int LastPercentage() {return lastPercentage;} int lastPercentage = 0;
public int Current() {return current;} int current = 0;
public boolean Canceled() {return dialog.CanceledChk();}
public boolean Canceled() {return dialog.Canceled_chk();}
String p;
public void Bgn(ConsoleDlg dialog, Io_url url, int total) {
public void Bgn(Console_adp dialog, Io_url url, int total) {
this.dialog = dialog; this.total = total;
p = url.Xto_api() + " - hash: ";
this.lastPercentage = 0; this.current = 0;
@ -159,14 +160,14 @@ class HashDlgWtrDefault implements HashDlgWtr {
current += increment;
int percentage = (current * 100) / total;
if (percentage <= lastPercentage) return;
dialog.WriteTempText(String_.LimitToFirst(p, dialog.CharsPerLineMax()) + Int_.Xto_str(percentage) + "%");
dialog.Write_tmp(String_.LimitToFirst(p, dialog.Chars_per_line_max()) + Int_.Xto_str(percentage) + "%");
lastPercentage = percentage;
}
public void End() {}
public void Fail(IoStream stream) {
// stream.Dispose();
}
ConsoleDlg dialog;
Console_adp dialog;
public static HashDlgWtrDefault new_() {return new HashDlgWtrDefault();}
}
class Tiger192 extends BaseHash {

@ -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.security; import gplx.*;
import org.junit.*; import gplx.ios.*; /*IoStream*/
import org.junit.*; import gplx.core.consoles.*; import gplx.ios.*; /*IoStream*/
public class HashAlgo_tth192_tst {
@Test public void Char0000() {tst_CalcBase32FromString("", "LWPNACQDBZRYXW3VHJVCJ64QBZNGHOHHHZWCLNQ");}
@Test public void Char0001() {tst_CalcBase32FromString("\0", "VK54ZIEEVTWNAUI5D5RDFIL37LX2IQNSTAXFKSA");}
@ -33,7 +33,7 @@ public class HashAlgo_tth192_tst {
}
void tst_CalcBase32FromString(String raw, String expd) {
IoStream stream = IoStream_.mem_txt_(Io_url_.Empty, raw);
String actl = HashAlgo_.Tth192.CalcHash(ConsoleDlg_.Null, stream);
String actl = HashAlgo_.Tth192.CalcHash(Console_adp_.Noop, stream);
Tfds.Eq(expd, actl);
}
}

@ -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.security; import gplx.*;
import org.junit.*; import gplx.ios.*; /*IoStream*/
import org.junit.*; import gplx.core.consoles.*; import gplx.ios.*; /*IoStream*/
public class HashDlgWtr_tst {
@Before public void setup() {
HashAlgo_tth192 algo = HashAlgo_tth192.new_();
@ -29,7 +29,7 @@ public class HashDlgWtr_tst {
tst_Status(30, stringAry_(" - hash: 40%", " - hash: 60%", " - hash: 100%"));
}
void tst_Status(int count, String[] expdWritten) {
ConsoleDlg_dev dialog = ConsoleDlg_.Dev();
Console_adp__mem dialog = Console_adp_.Dev();
String data = String_.Repeat("A", count);
IoStream stream = IoStream_.mem_txt_(Io_url_.Empty, data);
calc.CalcHash(dialog, stream);

@ -20,7 +20,7 @@ import gplx.core.primitives.*; import gplx.ios.*; /*IoItmFil, IoItmDir..*/
public class Io_mgr { // exists primarily to gather all cmds under gplx namespace; otherwise need to use gplx.ios whenever copying/deleting file
public boolean Exists(Io_url url) {return url.Type_dir() ? ExistsDir(url) : ExistsFil(url);}
public boolean ExistsFil(Io_url url) {return IoEnginePool._.Get_by(url.Info().EngineKey()).ExistsFil_api(url);}
public void ExistsFilOrFail(Io_url url) {if (!ExistsFil(url)) throw Exc_.new_("could not find file", "url", url);}
public void ExistsFilOrFail(Io_url url) {if (!ExistsFil(url)) throw Err_.new_wo_type("could not find file", "url", url);}
public void SaveFilStr(String url, String text) {SaveFilStr_args(Io_url_.new_fil_(url), text).Exec();}
public void SaveFilStr(Io_url url, String text) {SaveFilStr_args(url, text).Exec();}
public IoEngine_xrg_saveFilStr SaveFilStr_args(Io_url url, String text) {return IoEngine_xrg_saveFilStr.new_(url, text);}
@ -96,7 +96,7 @@ public class Io_mgr { // exists primarily to gather all cmds under gplx namespac
stream.ReadAry(ary);
return ary;
}
catch (Exception e) {throw Exc_.new_("failed to load file", "url", url.Xto_api(), "e", Err_.Message_lang(e));}
catch (Exception e) {throw Err_.new_wo_type("failed to load file", "url", url.Xto_api(), "e", Err_.Message_lang(e));}
finally {stream.Rls();}
}
public byte[] LoadFilBry_loose(Io_url url) {return Bry_.new_u8(LoadFilStr_loose(url));}

@ -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.ios; import gplx.*;
import gplx.core.criterias.*;
import gplx.core.consoles.*; import gplx.core.criterias.*;
public interface IoEngine {
String Key();
boolean ExistsFil_api(Io_url url);
@ -57,7 +57,7 @@ class IoEngineUtl {
engine.MoveDirDeep(IoEngine_xrg_xferDir.move_(xrg.Url(), recycleUrl).Overwrite_(false).ReadOnlyFails_(true));
}
public void DeleteDirDeep(IoEngine engine, Io_url dirUrl, IoEngine_xrg_deleteDir args) {
ConsoleDlg usrDlg = args.UsrDlg();
Console_adp usrDlg = args.UsrDlg();
IoItmDir dir = engine.QueryDir(dirUrl); if (!dir.Exists()) return;
for (Object subDirObj : dir.SubDirs()) {
IoItmDir subDir = (IoItmDir)subDirObj;
@ -69,12 +69,12 @@ class IoEngineUtl {
if (!args.MatchCrt().Matches(subFil)) continue;
Io_url subFilUrl = subFil.Url();
try {engine.DeleteFil_api(IoEngine_xrg_deleteFil.new_(subFilUrl).ReadOnlyFails_(args.ReadOnlyFails()));}
catch (Exception exc) {usrDlg.WriteLineFormat(Err_.Message_lang(exc));}
catch (Exception exc) {usrDlg.Write_fmt_w_nl(Err_.Message_lang(exc));}
}
// all subs deleted; now delete dir
if (!args.MatchCrt().Matches(dir)) return;
try {engine.DeleteDir(dir.Url());}
catch (Exception exc) {usrDlg.WriteLineFormat(Err_.Message_lang(exc));}
catch (Exception exc) {usrDlg.Write_fmt_w_nl(Err_.Message_lang(exc));}
}
public void XferDir(IoEngine srcEngine, Io_url src, IoEngine trgEngine, Io_url trg, IoEngine_xrg_xferDir args) {
trgEngine.CreateDir(trg);
@ -118,9 +118,9 @@ class IoEngineUtl {
rv.Exists_set(QueryDirDeepCore(rv, args.Url(), engine, args.Recur(), args.SubDirScanCrt(), args.DirCrt(), args.FilCrt(), args.UsrDlg(), args.DirInclude()));
return rv;
}
static boolean QueryDirDeepCore(IoItmDir ownerDir, Io_url url, IoEngine engine, boolean recur, Criteria subDirScanCrt, Criteria dirCrt, Criteria filCrt, ConsoleDlg usrDlg, boolean dirInclude) {
if (usrDlg.CanceledChk()) return false;
if (usrDlg.Enabled()) usrDlg.WriteTempText(String_.Concat("scan: ", url.Raw()));
static boolean QueryDirDeepCore(IoItmDir ownerDir, Io_url url, IoEngine engine, boolean recur, Criteria subDirScanCrt, Criteria dirCrt, Criteria filCrt, Console_adp usrDlg, boolean dirInclude) {
if (usrDlg.Canceled_chk()) return false;
if (usrDlg.Enabled()) usrDlg.Write_tmp(String_.Concat("scan: ", url.Raw()));
IoItmDir scanDir = engine.QueryDir(url);
for (Object subDirObj : scanDir.SubDirs()) {
IoItmDir subDir = (IoItmDir)subDirObj;

@ -30,7 +30,7 @@ public class IoEngine_memory extends IoEngine_base {
@Override public void XferFil(IoEngine_xrg_xferFil args) {utl.XferFil(this, args);}
@Override public void MoveFil(IoEngine_xrg_xferFil args) {
Io_url src = args.Src(), trg = args.Trg(); boolean overwrite = args.Overwrite();
if (String_.Eq(src.Xto_api(), trg.Xto_api())) throw Exc_.new_("move failed; src is same as trg", "raw", src.Raw());
if (String_.Eq(src.Xto_api(), trg.Xto_api())) throw Err_.new_wo_type("move failed; src is same as trg", "raw", src.Raw());
CheckTransferArgs("move", src, trg, overwrite);
if (overwrite) DeleteFil(trg);
IoItmFil_mem curFil = FetchFil(src); curFil.Name_(trg.NameAndExt());
@ -120,7 +120,7 @@ public class IoEngine_memory extends IoEngine_base {
}
@Override public void XferDir(IoEngine_xrg_xferDir args) {Io_url trg = args.Trg(); utl.XferDir(this, args.Src(), IoEnginePool._.Get_by(trg.Info().EngineKey()), trg, args);}
@Override public void MoveDirDeep(IoEngine_xrg_xferDir args) {Io_url trg = args.Trg(); utl.XferDir(this, args.Src(), IoEnginePool._.Get_by(trg.Info().EngineKey()), trg, args);}
@Override public void MoveDir(Io_url src, Io_url trg) {if (ExistsDir(trg)) throw Exc_.new_("trg already exists", "trg", trg);
@Override public void MoveDir(Io_url src, Io_url trg) {if (ExistsDir(trg)) throw Err_.new_wo_type("trg already exists", "trg", trg);
IoItmDir dir = FetchDir(src); dir.Name_(trg.NameAndExt());
for (Object filObj : dir.SubFils()) { // move all subFiles
IoItmFil fil = (IoItmFil)filObj;
@ -168,8 +168,8 @@ public class IoEngine_memory extends IoEngine_base {
return rv;
}
void CheckTransferArgs(String op, Io_url src, Io_url trg, boolean overwrite) {
if (!ExistsFil_api(src)) throw Exc_.new_("src does not exist", "src", src);
if (ExistsFil_api(trg) && !overwrite) throw Exc_.new_invalid_op("trg already exists").Args_add("op", op, "overwrite", false, "src", src, "trg", trg);
if (!ExistsFil_api(src)) throw Err_.new_wo_type("src does not exist", "src", src);
if (ExistsFil_api(trg) && !overwrite) throw Err_.new_invalid_op("trg already exists").Args_add("op", op, "overwrite", false, "src", src, "trg", trg);
}
public void Clear() {dirs.Clear();}
@Override public boolean DownloadFil(IoEngine_xrg_downloadFil xrg) {

@ -67,7 +67,7 @@ public class IoEngine_system extends IoEngine_base {
catch (IOException e) {
Closeable_close(fc, url, false);
Closeable_close(fos, url, false);
throw Exc_.new_exc(e, "io", "write data to file failed", "url", url.Xto_api());
throw Err_.new_exc(e, "io", "write data to file failed", "url", url.Xto_api());
}
if (!Op_sys.Cur().Tid_is_drd()) {
File fil = new File(url.Xto_api());
@ -118,7 +118,7 @@ public class IoEngine_system extends IoEngine_base {
reader.close();
}
catch (IOException e2) {}
throw Exc_.new_exc(e, "io", "read data from file failed", "url", url_str, "pos", pos);
throw Err_.new_exc(e, "io", "read data from file failed", "url", url_str, "pos", pos);
}
if (pos == -1) break;
sw.write(readerBuffer, 0, pos);
@ -135,7 +135,7 @@ public class IoEngine_system extends IoEngine_base {
File dir = new File(url.Xto_api());
if (!dir.exists()) return;
boolean rv = dir.delete();
if (!rv) throw Exc_.new_w_type(IoEngineArgs._.Err_IoException, "delete dir failed", "url", url.Xto_api());
if (!rv) throw Err_.new_(IoEngineArgs._.Err_IoException, "delete dir failed", "url", url.Xto_api());
}
@Override public IoItmDir QueryDir(Io_url url) {
IoItmDir rv = IoItmDir_.scan_(url);
@ -185,7 +185,7 @@ public class IoEngine_system extends IoEngine_base {
if (!Op_sys.Cur().Tid_is_drd())
IoEngine_system_xtn.SetWritable(f, true);
}
if (!rv) throw Exc_.new_w_type(IoEngineArgs._.Err_IoException, "set file attribute failed", "attribute", "readOnly", "cur", Fil_ReadOnly(f), "new", atr.ReadOnly(), "url", url.Xto_api());
if (!rv) throw Err_.new_(IoEngineArgs._.Err_IoException, "set file attribute failed", "attribute", "readOnly", "cur", Fil_ReadOnly(f), "new", atr.ReadOnly(), "url", url.Xto_api());
}
if (atr.Hidden() != f.isHidden()) {
//Runtime.getRuntime().exec("attrib +H myHiddenFile.java");
@ -208,7 +208,7 @@ public class IoEngine_system extends IoEngine_base {
finally {
UpdateFilAttrib(url, IoItmAttrib.readOnly_());
}
if (!success) throw Exc_.new_("could not update file modified time", "url", url.Xto_api(), "modifiedTime", modified.XtoStr_gplx_long());
if (!success) throw Err_.new_wo_type("could not update file modified time", "url", url.Xto_api(), "modifiedTime", modified.XtoStr_gplx_long());
}
}
}
@ -242,7 +242,7 @@ public class IoEngine_system extends IoEngine_base {
rv = false;
}
if (!rv)
throw Exc_.new_("create file failed", "trg", trgUrl.Xto_api());
throw Err_.new_wo_type("create file failed", "trg", trgUrl.Xto_api());
}
FileInputStream srcStream = null; FileOutputStream trgStream = null;
FileChannel srcChannel = null, trgChannel = null;
@ -264,7 +264,7 @@ public class IoEngine_system extends IoEngine_base {
// transfer data
long pos = 0, count = 0, read = 0;
try {count = srcChannel.size();}
catch (IOException e) {throw Exc_.new_exc(e, "io", "size failed", "src", srcUrl.Xto_api());}
catch (IOException e) {throw Err_.new_exc(e, "io", "size failed", "src", srcUrl.Xto_api());}
int totalBufferSize = IoEngineArgs._.LoadFilStr_BufferSize;
long transferSize = (count > totalBufferSize) ? totalBufferSize : count; // transfer as much as fileSize, but limit to LoadFilStr_BufferSize
while (pos < count) {
@ -274,7 +274,7 @@ public class IoEngine_system extends IoEngine_base {
Closeable_close(trgChannel, trgUrl, false);
Closeable_close(srcStream, srcUrl, false);
Closeable_close(trgStream, srcUrl, false);
throw Exc_.new_exc(e, "io", "transfer data failed", "src", srcUrl.Xto_api(), "trg", trgUrl.Xto_api());
throw Err_.new_exc(e, "io", "transfer data failed", "src", srcUrl.Xto_api(), "trg", trgUrl.Xto_api());
}
if (read == -1) break;
pos += read;
@ -341,12 +341,12 @@ public class IoEngine_system extends IoEngine_base {
}
void Chk_TrgFil_Overwrite(boolean overwrite, Io_url trg) {
if (!overwrite)
throw Exc_.new_invalid_op("trgFile exists but overwriteFlag not set").Args_add("trg", trg.Xto_api());
throw Err_.new_invalid_op("trgFile exists but overwriteFlag not set").Args_add("trg", trg.Xto_api());
}
@Override public void MoveDir(Io_url src, Io_url trg) {
String srcStr = src.Xto_api(), trgStr = trg.Xto_api();
File srcFil = new File(srcStr), trgFil = new File(trgStr);
if (trgFil.exists()) {throw Exc_.new_invalid_op("cannot move dir if trg exists").Args_add("src", src, "trg", trg);}
if (trgFil.exists()) {throw Err_.new_invalid_op("cannot move dir if trg exists").Args_add("src", src, "trg", trg);}
if (String_.Eq(src.OwnerRoot().Raw(), trg.OwnerRoot().Raw())) {
srcFil.renameTo(trgFil);
}
@ -360,7 +360,7 @@ public class IoEngine_system extends IoEngine_base {
try {closeable.close();}
catch (IOException e) {
if (throwErr)
throw Exc_.new_exc(e, "io", "close object failed", "class", ClassAdp_.NameOf_obj(closeable), "url", url_str);
throw Err_.new_exc(e, "io", "close object failed", "class", ClassAdp_.NameOf_obj(closeable), "url", url_str);
// else
// UsrDlg_._.Finally("failed to close FileChannel", "url", url, "apiErr", Err_.Message_err_arg(e));
}
@ -374,8 +374,8 @@ public class IoEngine_system extends IoEngine_base {
if (!Op_sys.Cur().Tid_is_drd())
IoEngine_system_xtn.SetWritable(fil, true);
}
private static Exc Err_text_unsupported_encoding(String encodingName, String text, String url_str, Exception e) {
return Exc_.new_exc(e, "io", "text is in unsupported encoding").Args_add("encodingName", encodingName, "text", text, "url", url_str);
private static Err Err_text_unsupported_encoding(String encodingName, String text, String url_str, Exception e) {
return Err_.new_exc(e, "io", "text is in unsupported encoding").Args_add("encodingName", encodingName, "text", text, "url", url_str);
}
boolean user_agent_needs_resetting = true;
@Override public Io_stream_rdr DownloadFil_as_rdr(IoEngine_xrg_downloadFil xrg) {
@ -449,7 +449,7 @@ public class IoEngine_system extends IoEngine_base {
trg_stream.Rls();
DeleteFil_api(IoEngine_xrg_deleteFil.new_(xrg.Trg()));
}
catch (Exception e2) {Exc_.Noop(e2);}
catch (Exception e2) {Err_.Noop(e2);}
}
return false;
}
@ -460,22 +460,22 @@ public class IoEngine_system extends IoEngine_base {
if (src_conn != null) src_conn.disconnect();
src_conn.getInputStream().close();
} catch (Exception exc) {
Exc_.Noop(exc);
Err_.Noop(exc);
}
if (trg_stream != null) trg_stream.Rls();
}
} Io_url session_fil; Bry_bfr prog_fmt_bfr;
byte[] download_bfr; static final int Download_bfr_len = Io_mgr.Len_kb * 128;
public static Exc Err_Fil_NotFound(Io_url url) {
return Exc_.new_w_type(IoEngineArgs._.Err_FileNotFound, "file not found", "url", url.Xto_api()).Stack_erase_1_();
public static Err Err_Fil_NotFound(Io_url url) {
return Err_.new_(IoEngineArgs._.Err_FileNotFound, "file not found", "url", url.Xto_api()).Trace_ignore_add_1_();
}
public static Exc Err_Fil_NotFound(Exception e, Io_url url) {
return Exc_.new_exc(e, "io", "file not found", "url", url.Xto_api()).Stack_erase_1_();
public static Err Err_Fil_NotFound(Exception e, Io_url url) {
return Err_.new_exc(e, "io", "file not found", "url", url.Xto_api()).Trace_ignore_add_1_();
}
void MarkFileWritable(File fil, Io_url url, boolean readOnlyFails, String op) {
if (Fil_ReadOnly(fil)) {
if (readOnlyFails) // NOTE: java will always allow final files to be deleted; programmer api is responsible for check
throw Exc_.new_w_type(IoEngineArgs._.Err_ReadonlyFileNotWritable, "writable operation attempted on readOnly file", "op", op, "url", url.Xto_api());
throw Err_.new_(IoEngineArgs._.Err_ReadonlyFileNotWritable, "writable operation attempted on readOnly file", "op", op, "url", url.Xto_api());
else
Fil_Writable(fil);
}
@ -483,7 +483,7 @@ public class IoEngine_system extends IoEngine_base {
void DeleteFil_lang(File fil, Io_url url) {
boolean rv = Fil_Delete(fil);
if (!rv)
throw Exc_.new_w_type(IoEngineArgs._.Err_IoException, "file not deleted", "url", url.Xto_api());
throw Err_.new_(IoEngineArgs._.Err_IoException, "file not deleted", "url", url.Xto_api());
}
IoEngineUtl utl = IoEngineUtl.new_();
public static IoEngine_system new_() {return new IoEngine_system();} IoEngine_system() {}
@ -610,10 +610,10 @@ class Io_stream_rdr_http implements Io_stream_rdr {
}
xrg.Prog_running_(false);
}
catch (Exception e) {Exc_.Noop(e);} // ignore close errors; also Err_handle calls Rls() so it would be circular
catch (Exception e) {Err_.Noop(e);} // ignore close errors; also Err_handle calls Rls() so it would be circular
finally {
try {if (src_stream != null) src_stream.close();}
catch (Exception e) {Exc_.Noop(e);} // ignore failures when cleaning up
catch (Exception e) {Err_.Noop(e);} // ignore failures when cleaning up
if (src_conn != null) src_conn.disconnect();
src_stream = null;
src_conn = null;

@ -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.ios; import gplx.*;
import gplx.core.criterias.*;
import gplx.core.consoles.*; import gplx.core.criterias.*;
public class IoEngine_xrg_deleteDir {
public Io_url Url() {return url;} public IoEngine_xrg_deleteDir Url_(Io_url val) {url = val; return this;} Io_url url;
public boolean Recur() {return recur;} public IoEngine_xrg_deleteDir Recur_() {return Recur_(true);} public IoEngine_xrg_deleteDir Recur_(boolean v) {recur = v; return this;} private boolean recur = false;
@ -24,7 +24,7 @@ public class IoEngine_xrg_deleteDir {
public boolean MissingIgnored() {return missingIgnored;} public IoEngine_xrg_deleteDir MissingIgnored_() {return MissingIgnored_(true);} public IoEngine_xrg_deleteDir MissingIgnored_(boolean v) {missingIgnored = v; return this;} private boolean missingIgnored = true;
public Criteria MatchCrt() {return matchCrt;} public IoEngine_xrg_deleteDir MatchCrt_(Criteria v) {matchCrt = v; return this;} Criteria matchCrt = Criteria_.All;
public Criteria SubDirScanCrt() {return subDirScanCrt;} public IoEngine_xrg_deleteDir SubDirScanCrt_(Criteria v) {subDirScanCrt = v; return this;} Criteria subDirScanCrt = Criteria_.All;
public ConsoleDlg UsrDlg() {return usrDlg;} public IoEngine_xrg_deleteDir UsrDlg_(ConsoleDlg v) {usrDlg = v; return this;} ConsoleDlg usrDlg = ConsoleDlg_.Null;
public Console_adp UsrDlg() {return usrDlg;} public IoEngine_xrg_deleteDir UsrDlg_(Console_adp v) {usrDlg = v; return this;} Console_adp usrDlg = Console_adp_.Noop;
public void Exec() {IoEnginePool._.Get_by(url.Info().EngineKey()).DeleteDirDeep(this);}
public static IoEngine_xrg_deleteDir new_(Io_url url) {
IoEngine_xrg_deleteDir rv = new IoEngine_xrg_deleteDir();

@ -22,7 +22,7 @@ public class IoEngine_xrg_downloadFil {
public byte Rslt() {return rslt;} public IoEngine_xrg_downloadFil Rslt_(byte v) {rslt = v; return this;} private byte rslt = Rslt_pass;
public Exception Rslt_err() {return rslt_err;} public IoEngine_xrg_downloadFil Rslt_err_(Exception v) {rslt_err = v; return this;} private Exception rslt_err;
public String Rslt_err_str() {
return rslt_err == null ? "none" : Err_.Message_gplx_brief(rslt_err);
return rslt_err == null ? "none" : Err_.Message_gplx_full(rslt_err);
}
public String User_agent() {return user_agent;} public IoEngine_xrg_downloadFil User_agent_(String v) {user_agent = v; return this;} private String user_agent;
public Gfo_usr_dlg Prog_dlg() {return prog_dlg;} public IoEngine_xrg_downloadFil Prog_dlg_(Gfo_usr_dlg v) {prog_dlg = v; download_fmt.Ctor(prog_dlg); return this;} private Gfo_usr_dlg prog_dlg;

@ -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.ios; import gplx.*;
import gplx.core.criterias.*;
import gplx.core.consoles.*; import gplx.core.criterias.*;
public class IoEngine_xrg_queryDir {
public Io_url Url() {return url;} public IoEngine_xrg_queryDir Url_(Io_url val) {url = val; return this;} Io_url url;
public boolean Recur() {return recur;} public IoEngine_xrg_queryDir Recur_() {return Recur_(true);} public IoEngine_xrg_queryDir Recur_(boolean val) {recur = val; return this;} private boolean recur = false;
@ -30,7 +30,7 @@ public class IoEngine_xrg_queryDir {
return this;
}
public ConsoleDlg UsrDlg() {return usrDlg;} public IoEngine_xrg_queryDir UsrDlg_(ConsoleDlg val) {usrDlg = val; return this;} ConsoleDlg usrDlg = ConsoleDlg_.Null;
public Console_adp UsrDlg() {return usrDlg;} public IoEngine_xrg_queryDir UsrDlg_(Console_adp val) {usrDlg = val; return this;} Console_adp usrDlg = Console_adp_.Noop;
public IoEngine_xrg_queryDir FilPath_(String val) {
Criteria_ioMatch crt = Criteria_ioMatch.parse_(true, val, url.Info().CaseSensitive());
filCrt = Criteria_fld.new_(IoItm_base_.Prop_Path, crt);

@ -20,11 +20,11 @@ public class IoErr {
public static String Namespace = "gplx.ios.";
public static String FileIsReadOnly_key = Namespace + "FileIsReadOnlyError";
public static String FileNotFound_key = Namespace + "FileNotFoundError";
public static Exc FileIsReadOnly(Io_url url) {
return Exc_.new_w_type(FileIsReadOnly_key, "file is read-only", "url", url.Xto_api()).Stack_erase_1_();
public static Err FileIsReadOnly(Io_url url) {
return Err_.new_(FileIsReadOnly_key, "file is read-only", "url", url.Xto_api()).Trace_ignore_add_1_();
}
public static Exc FileNotFound(String op, Io_url url) {
public static Err FileNotFound(String op, Io_url url) {
// file is missing -- op='copy' file='C:\a.txt' copyFile_target='D:\a.txt'
return Exc_.new_w_type(FileNotFound_key, "file not found", "op", op, "file", url.Xto_api()).Stack_erase_1_();
return Err_.new_(FileNotFound_key, "file not found", "op", op, "file", url.Xto_api()).Trace_ignore_add_1_();
}
}

@ -25,7 +25,7 @@ public class IoItmClassXtn extends ClassXtn_base implements ClassXtn {
String rawLower = String_.Lower(raw);
if (String_.Eq(rawLower, "dir")) return IoItmDir.Type_Dir;
else if (String_.Eq(rawLower, "fil")) return IoItmFil.Type_Fil;
else throw Exc_.new_unhandled(raw);
else throw Err_.new_unhandled(raw);
}
@Override public Object XtoDb(Object obj) {return Int_.cast_(obj);}
public static final IoItmClassXtn _ = new IoItmClassXtn(); IoItmClassXtn() {}

@ -20,7 +20,7 @@ public abstract class IoItm_base implements GfoInvkAble, CompareAble {
public abstract int TypeId(); public abstract boolean Type_dir(); public abstract boolean Type_fil();
public Io_url Url() {return ownerDir == null ? url : ownerDir.Url().GenSubFil(name); /*NOTE: must call .Url*/} Io_url url;
public IoItmDir OwnerDir() {return ownerDir;} IoItmDir ownerDir;
public void OwnerDir_set(IoItmDir v) {if (v == this) throw Exc_.new_("dir cannot be its own owner", "url", v.url.Raw());
public void OwnerDir_set(IoItmDir v) {if (v == this) throw Err_.new_wo_type("dir cannot be its own owner", "url", v.url.Raw());
url = v == null && ownerDir != null
? ownerDir.url.GenSubFil(name) // create url, since ownerDir will soon be null; NOTE: must call .url
: Io_url_.Empty; // delete url, since ownerDir will be avail

@ -23,7 +23,7 @@ public class IoRecycleBin {
public void Recover(Io_url url) {
String_bldr sb = String_bldr_.new_();
List_adp list = Regy_search(url, sb);
int listCount = list.Count(); if (listCount > 1) throw Exc_.new_("found more than 1 url", "count", list.Count());
int listCount = list.Count(); if (listCount > 1) throw Err_.new_wo_type("found more than 1 url", "count", list.Count());
Io_url trgUrl = (Io_url)list.Get_at(0);
IoEngine_xrg_xferFil.move_(url, trgUrl).ReadOnlyFails_(true).Overwrite_(false).Exec();
IoEngine_xrg_saveFilStr.new_(FetchRegistryUrl(url), sb.XtoStr()).Exec();

@ -36,7 +36,7 @@ public class IoStream_ {
public static Object input_stream_(Io_url url) {
try {
return new java.io.FileInputStream(url.Raw());
} catch (Exception e) {throw Exc_.new_("file not found", "url", url.Raw());}
} catch (Exception e) {throw Err_.new_wo_type("file not found", "url", url.Raw());}
}
}
class IoStream_null implements IoStream {
@ -76,7 +76,7 @@ class IoStream_base implements IoStream {
int rv = under.read(array, offset, count);
return rv == -1 ? 0 : rv; // NOTE: fis returns -1 if nothing read; .NET returned 0; Hash will fail if -1 returned (will try to create array of 0 length)
} // NOTE: fis keeps track of offset, only need to pass in array (20110606: this NOTE no longer seems to make sense; deprecate)
catch (IOException e) {throw Exc_.new_exc(e, "io", "file read failed", "url", url);}
catch (IOException e) {throw Err_.new_exc(e, "io", "file read failed", "url", url);}
}
public long Seek(long seek_pos) {
try {
@ -84,7 +84,7 @@ class IoStream_base implements IoStream {
pos = under.getFilePointer();
return pos;
}
catch (IOException e) {throw Exc_.new_exc(e, "io", "seek failed", "url", url);}
catch (IOException e) {throw Err_.new_exc(e, "io", "seek failed", "url", url);}
}
@gplx.Virtual public void Write(byte[] array, int offset, int count) {bfr.Add_mid(array, offset, offset + count); this.Flush();} Bry_bfr bfr = Bry_bfr.reset_(16);
public void Write_and_flush(byte[] bry, int bgn, int end) {
@ -103,7 +103,7 @@ class IoStream_base implements IoStream {
for (int i = 0; i < buffer_len; i++)
buffer[i] = bry[i + buffer_bgn];
try {under.write(buffer, 0, buffer_len);}
catch (IOException e) {throw Exc_.new_exc(e, "io", "write failed", "url", url);}
catch (IOException e) {throw Err_.new_exc(e, "io", "write failed", "url", url);}
buffer_bgn = buffer_end;
}
// this.Rls();
@ -126,9 +126,9 @@ class IoStream_base implements IoStream {
if (mode_is_append) under.seek(under.length());
// else under.seek(0);
}
catch (IOException e) {throw Exc_.new_exc(e, "io", "seek failed", "url", url);}
catch (IOException e) {throw Err_.new_exc(e, "io", "seek failed", "url", url);}
try {under.write(bfr.Bfr(), 0, bfr.Len());}
catch (IOException e) {throw Exc_.new_exc(e, "io", "write failed", "url", url);}
catch (IOException e) {throw Err_.new_exc(e, "io", "write failed", "url", url);}
bfr.Clear();
}
@gplx.Virtual public void Rls() {
@ -155,10 +155,10 @@ class IoStream_base implements IoStream {
break;
}
try {rv.under = new RandomAccessFile(file, ctor_mode);}
catch (FileNotFoundException e) {throw Exc_.new_exc(e, "io", "file open failed", "url", url);}
catch (FileNotFoundException e) {throw Err_.new_exc(e, "io", "file open failed", "url", url);}
if (mode == IoStream_.Mode_wtr_create) {
try {rv.under.setLength(0);}
catch (IOException e) {throw Exc_.new_exc(e, "io", "file truncate failed", "url", url);}
catch (IOException e) {throw Err_.new_exc(e, "io", "file truncate failed", "url", url);}
}
rv.length = file.length();
return rv;

@ -19,7 +19,7 @@ package gplx.ios; import gplx.*;
import gplx.texts.*; /*Encoding_*/
class IoStream_mem extends IoStream_base {
@Override public Io_url Url() {return url;} Io_url url;
@Override public Object UnderRdr() {throw Exc_.new_unimplemented();} // NOTE: should not use System.IO.MemoryStream, b/c resized data will not be captured in this instance's buffer
@Override public Object UnderRdr() {throw Err_.new_unimplemented();} // NOTE: should not use System.IO.MemoryStream, b/c resized data will not be captured in this instance's buffer
@Override public long Len() {return Array_.Len(buffer);}
public int Position() {return position;} public void Position_set(int v) {position = v;} int position;
public byte[] Buffer() {return buffer;} private byte[] buffer = new byte[0];

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

Loading…
Cancel
Save