home *** CD-ROM | disk | FTP | other *** search
- package java.util;
-
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.io.PrintStream;
-
- public class Properties extends Hashtable {
- protected Properties defaults;
-
- public Properties() {
- this((Properties)null);
- }
-
- public Properties(Properties defaults) {
- this.defaults = defaults;
- }
-
- public synchronized void load(InputStream in) throws IOException {
- in = Runtime.getRuntime().getLocalizedInputStream(in);
- int ch = in.read();
-
- label136:
- while(true) {
- StringBuffer key;
- switch (ch) {
- case 35:
- case 33:
- while(true) {
- ch = in.read();
- if (ch < 0 || ch == 10 || ch == 13) {
- continue label136;
- }
- }
- case -1:
- return;
- case 32:
- case 13:
- case 10:
- case 9:
- ch = in.read();
- continue;
- default:
- key = new StringBuffer();
- }
-
- while(ch >= 0 && ch != 61 && ch != 58 && ch != 32 && ch != 9 && ch != 10 && ch != 13) {
- key.append((char)ch);
- ch = in.read();
- }
-
- while(ch == 32 && ch == 9) {
- ch = in.read();
- }
-
- if (ch == 61 || ch == 58) {
- ch = in.read();
- }
-
- while(ch == 32 && ch == 9) {
- ch = in.read();
- }
-
- StringBuffer val = new StringBuffer();
-
- label96:
- while(ch >= 0 && ch != 10 && ch != 13) {
- if (ch == 92) {
- switch (ch = in.read()) {
- case 117:
- while((ch = in.read()) == 117) {
- }
-
- int d = 0;
-
- label83:
- for(int i = 0; i < 4; ch = in.read()) {
- switch (ch) {
- case 100:
- case 99:
- case 98:
- case 97:
- case 102:
- case 101:
- d = (d << 4) + 10 + ch - 97;
- break;
- case 70:
- case 69:
- case 68:
- case 67:
- case 66:
- case 65:
- d = (d << 4) + 10 + ch - 65;
- break;
- case 57:
- case 56:
- case 55:
- case 54:
- case 53:
- case 52:
- case 51:
- case 50:
- case 49:
- case 48:
- d = (d << 4) + ch - 48;
- break;
- default:
- break label83;
- }
-
- ++i;
- }
-
- ch = d;
- break;
- case 116:
- ch = 9;
- break;
- case 114:
- ch = 13;
- break;
- case 10:
- while(true) {
- while((ch = in.read()) == 32) {
- }
-
- if (ch != 9) {
- continue label96;
- }
- }
- case 110:
- ch = 10;
- }
- }
-
- val.append((char)ch);
- ch = in.read();
- }
-
- ((Hashtable)this).put(key.toString(), val.toString());
- }
- }
-
- public synchronized void save(OutputStream out, String header) {
- OutputStream localOut = Runtime.getRuntime().getLocalizedOutputStream(out);
- PrintStream prnt = new PrintStream(localOut, false);
- boolean localize = localOut != out;
- if (header != null) {
- prnt.write(35);
- prnt.println(header);
- }
-
- prnt.write(35);
- prnt.println(new Date());
- Enumeration e = ((Hashtable)this).keys();
-
- while(e.hasMoreElements()) {
- String key = (String)e.nextElement();
- prnt.print(key);
- prnt.write(61);
- String val = (String)((Hashtable)this).get(key);
- int len = val.length();
- boolean empty = false;
-
- for(int i = 0; i < len; ++i) {
- int ch = val.charAt(i);
- switch (ch) {
- case 92:
- prnt.write(92);
- prnt.write(92);
- break;
- case 13:
- prnt.write(92);
- prnt.write(114);
- break;
- case 10:
- prnt.write(92);
- prnt.write(110);
- break;
- case 9:
- prnt.write(92);
- prnt.write(116);
- break;
- default:
- if (ch < 32 || ch >= 127 || empty && ch == 32) {
- if (ch > 255 && localize) {
- prnt.write(ch);
- } else {
- prnt.write(92);
- prnt.write(117);
- prnt.write(ch >> 12 & 15);
- prnt.write(ch >> 8 & 15);
- prnt.write(ch >> 4 & 15);
- prnt.write(ch & 15);
- }
- } else {
- prnt.write(ch);
- }
- }
-
- empty = false;
- }
-
- prnt.write(10);
- }
-
- }
-
- public String getProperty(String key) {
- String val = (String)super.get(key);
- return val == null && this.defaults != null ? this.defaults.getProperty(key) : val;
- }
-
- public String getProperty(String key, String defaultValue) {
- String val = this.getProperty(key);
- return val == null ? defaultValue : val;
- }
-
- public Enumeration propertyNames() {
- Hashtable h = new Hashtable();
- this.enumerate(h);
- return h.keys();
- }
-
- public void list(PrintStream out) {
- out.println("-- listing properties --");
- Hashtable h = new Hashtable();
- this.enumerate(h);
-
- String key;
- String val;
- for(Enumeration e = h.keys(); e.hasMoreElements(); out.println(key + "=" + val)) {
- key = (String)e.nextElement();
- val = (String)h.get(key);
- if (val.length() > 40) {
- val = val.substring(0, 37) + "...";
- }
- }
-
- }
-
- private synchronized void enumerate(Hashtable h) {
- if (this.defaults != null) {
- this.defaults.enumerate(h);
- }
-
- Enumeration e = ((Hashtable)this).keys();
-
- while(e.hasMoreElements()) {
- String key = (String)e.nextElement();
- h.put(key, ((Hashtable)this).get(key));
- }
-
- }
- }
-