X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fdolda%2Fjsvc%2Futil%2FMisc.java;h=9b7f8e184f9ac6cd05832fbf7f7548d5d0dc8290;hb=b9089d950e376b3f48c63e69c72a32d4efeba7b0;hp=a86735ae80b7dffb79e600e1d66ba6c8f37ec562;hpb=efa9722bc37910a6224346bb20210205c96ecc47;p=jsvc.git diff --git a/src/dolda/jsvc/util/Misc.java b/src/dolda/jsvc/util/Misc.java index a86735a..9b7f8e1 100644 --- a/src/dolda/jsvc/util/Misc.java +++ b/src/dolda/jsvc/util/Misc.java @@ -6,6 +6,7 @@ import java.io.*; public class Misc { public static final java.nio.charset.Charset utf8 = java.nio.charset.Charset.forName("UTF-8"); + public static final java.nio.charset.Charset ascii = java.nio.charset.Charset.forName("US-ASCII"); private static Map stext = new HashMap(); static { @@ -37,6 +38,25 @@ public class Misc { return(p); } + static byte[] readall(InputStream in) throws IOException { + byte[] buf = new byte[4096]; + int off = 0; + while(true) { + if(off == buf.length) { + byte[] n = new byte[buf.length * 2]; + System.arraycopy(buf, 0, n, 0, buf.length); + buf = n; + } + int ret = in.read(buf, off, buf.length - off); + if(ret < 0) { + byte[] n = new byte[off]; + System.arraycopy(buf, 0, n, 0, off); + return(n); + } + off += ret; + } + } + public static void cpstream(InputStream in, OutputStream out) throws IOException { byte[] buf = new byte[4096]; while(true) { @@ -103,4 +123,23 @@ public class Misc { } return(buf.toString()); } + + public static boolean boolval(String val) { + val = val.trim().toLowerCase(); + if(val.equals("1") || val.equals("on") || val.equals("true") || val.equals("yes") || val.equals("\u22a4")) + return(true); + if(val.equals("0") || val.equals("off") || val.equals("false") || val.equals("no") || val.equals("\u22a5")) + return(false); + throw(new IllegalArgumentException("value not recognized as boolean: " + val)); + } + + public static void eatws(PushbackReader in) throws IOException { + int c; + do { + c = in.read(); + if(c < 0) + return; + } while(Character.isWhitespace(c)); + in.unread(c); + } }