32 import java.io.OutputStream; |
32 import java.io.OutputStream; |
33 import java.io.Reader; |
33 import java.io.Reader; |
34 import java.io.Writer; |
34 import java.io.Writer; |
35 import java.io.OutputStreamWriter; |
35 import java.io.OutputStreamWriter; |
36 import java.io.BufferedWriter; |
36 import java.io.BufferedWriter; |
|
37 import java.lang.reflect.*; |
37 |
38 |
38 /** |
39 /** |
39 * The <code>Properties</code> class represents a persistent set of |
40 * The <code>Properties</code> class represents a persistent set of |
40 * properties. The <code>Properties</code> can be saved to a stream |
41 * properties. The <code>Properties</code> can be saved to a stream |
41 * or loaded from a stream. Each key and its corresponding value in |
42 * or loaded from a stream. Each key and its corresponding value in |
1109 |
1110 |
1110 /** A table of hex digits */ |
1111 /** A table of hex digits */ |
1111 private static final char[] hexDigit = { |
1112 private static final char[] hexDigit = { |
1112 '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' |
1113 '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' |
1113 }; |
1114 }; |
|
1115 |
|
1116 |
|
1117 private static class XMLUtils { |
|
1118 private static Method load = null; |
|
1119 private static Method save = null; |
|
1120 static { |
|
1121 try { |
|
1122 // reference sun.util.xml.Utils reflectively |
|
1123 // to allow the Properties class be compiled in |
|
1124 // the absence of XML |
|
1125 Class<?> c = Class.forName("sun.util.xml.XMLUtils", true, null); |
|
1126 load = c.getMethod("load", Properties.class, InputStream.class); |
|
1127 save = c.getMethod("save", Properties.class, OutputStream.class, |
|
1128 String.class, String.class); |
|
1129 } catch (ClassNotFoundException cnf) { |
|
1130 throw new AssertionError(cnf); |
|
1131 } catch (NoSuchMethodException e) { |
|
1132 throw new AssertionError(e); |
|
1133 } |
|
1134 } |
|
1135 |
|
1136 static void invoke(Method m, Object... args) throws IOException { |
|
1137 try { |
|
1138 m.invoke(null, args); |
|
1139 } catch (IllegalAccessException e) { |
|
1140 throw new AssertionError(e); |
|
1141 } catch (InvocationTargetException e) { |
|
1142 Throwable t = e.getCause(); |
|
1143 if (t instanceof RuntimeException) |
|
1144 throw (RuntimeException)t; |
|
1145 |
|
1146 if (t instanceof IOException) { |
|
1147 throw (IOException)t; |
|
1148 } else { |
|
1149 throw new AssertionError(t); |
|
1150 } |
|
1151 } |
|
1152 } |
|
1153 |
|
1154 static void load(Properties props, InputStream in) |
|
1155 throws IOException, InvalidPropertiesFormatException |
|
1156 { |
|
1157 if (load == null) |
|
1158 throw new InternalError("sun.util.xml.XMLUtils not found"); |
|
1159 invoke(load, props, in); |
|
1160 } |
|
1161 |
|
1162 static void save(Properties props, OutputStream os, String comment, |
|
1163 String encoding) |
|
1164 throws IOException |
|
1165 { |
|
1166 if (save == null) |
|
1167 throw new InternalError("sun.util.xml.XMLUtils not found"); |
|
1168 invoke(save, props, os, comment, encoding); |
|
1169 } |
|
1170 } |
1114 } |
1171 } |