X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altoslib%2FAltosJson.java;h=b981c36513939a7de503de3ce111473bf2b13a4e;hp=9191be68004d6297d4fea25ae61747669478816c;hb=eaf2ee0f498b519d64e1664a2b8c66c52ac1497c;hpb=17e20a6d2dab1f4bd1375bfd9e1c5230ee2c1119 diff --git a/altoslib/AltosJson.java b/altoslib/AltosJson.java index 9191be68..b981c365 100644 --- a/altoslib/AltosJson.java +++ b/altoslib/AltosJson.java @@ -16,7 +16,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_11; +package org.altusmetrum.altoslib_13; import java.io.*; import java.util.*; @@ -63,18 +63,22 @@ class JsonUtil { result.append("\t"); return result; } - static NumberFormat get_nf_json() { - DecimalFormat nf = (DecimalFormat) NumberFormat.getNumberInstance(Locale.ROOT); - nf.setParseIntegerOnly(false); - nf.setGroupingUsed(false); - nf.setMaximumFractionDigits(17); - nf.setMinimumFractionDigits(0); - nf.setMinimumIntegerDigits(1); - nf.setDecimalSeparatorAlwaysShown(false); - return nf; - } - static NumberFormat nf_json = get_nf_json(); + NumberFormat _nf_json; + + NumberFormat nf_json() { + if (_nf_json == null) { + DecimalFormat nf = (DecimalFormat) NumberFormat.getNumberInstance(Locale.ROOT); + nf.setParseIntegerOnly(false); + nf.setGroupingUsed(false); + nf.setMaximumFractionDigits(17); + nf.setMinimumFractionDigits(0); + nf.setMinimumIntegerDigits(1); + nf.setDecimalSeparatorAlwaysShown(false); + _nf_json = nf; + } + return _nf_json; + } } class JsonHash extends JsonUtil { @@ -255,7 +259,7 @@ class JsonToken { * Lexer for json */ class JsonLexer extends JsonUtil { - Reader f; + InputStream f; int line; int ungot = -2; StringBuffer pending_token; @@ -372,7 +376,7 @@ class JsonLexer extends JsonUtil { String dstr = dbuf.toString(); double dval; try { - dval = nf_json.parse(dstr).doubleValue(); + dval = nf_json().parse(dstr).doubleValue(); } catch (ParseException pe) { return new JsonToken(JsonToken._error, dstr); } @@ -445,12 +449,12 @@ class JsonLexer extends JsonUtil { } JsonLexer(String s) { - f = new StringReader(s); + f = new AltosStringInputStream(s); line = 1; token = null; } - JsonLexer(Reader f) { + JsonLexer(InputStream f) { this.f = f; line = 1; token = null; @@ -570,7 +574,7 @@ class JsonParse { lexer = new JsonLexer(s); } - JsonParse(Reader f) { + JsonParse(InputStream f) { lexer = new JsonLexer(f); } } @@ -612,7 +616,7 @@ public class AltosJson extends JsonUtil { } else if (Double.isNaN(d_number)) { result.append("NaN"); } else { - String dval = nf_json.format(d_number); + String dval = nf_json().format(d_number); if (dval.equals("-0")) dval = "0"; result.append(dval); @@ -670,7 +674,7 @@ public class AltosJson extends JsonUtil { } } - public static AltosJson fromReader(Reader f) { + public static AltosJson fromInputStream(InputStream f) { JsonParse parse = new JsonParse(f); try { return parse.parse();