58 public PermissionCollection getPermissions(ProtectionDomain pd) { 59 return perms; 60 } 61 62 @Override 63 public boolean implies(ProtectionDomain pd, Permission p) { 64 return perms.implies(p); 65 } 66 } 67 68 /** 69 * Sanity test that properties saved with Properties#storeToXML can be 70 * read with Properties#loadFromXML. 71 */ 72 static void testLoadAndStore(String encoding) throws IOException { 73 System.out.println("testLoadAndStore, encoding=" + encoding); 74 75 Properties props = new Properties(); 76 props.put("k1", "foo"); 77 props.put("k2", "bar"); 78 79 ByteArrayOutputStream out = new ByteArrayOutputStream(); 80 props.storeToXML(out, null, encoding); 81 82 Properties p = new Properties(); 83 ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); 84 p.loadFromXML(in); 85 86 if (!p.equals(props)) { 87 System.err.println("stored: " + props); 88 System.err.println("loaded: " + p); 89 throw new RuntimeException("Test failed"); 90 } 91 } 92 93 /** 94 * Test loadFromXML with a document that does not have an encoding declaration 95 */ 96 static void testLoadWithoutEncoding() throws IOException { 97 System.out.println("testLoadWithoutEncoding"); | 58 public PermissionCollection getPermissions(ProtectionDomain pd) { 59 return perms; 60 } 61 62 @Override 63 public boolean implies(ProtectionDomain pd, Permission p) { 64 return perms.implies(p); 65 } 66 } 67 68 /** 69 * Sanity test that properties saved with Properties#storeToXML can be 70 * read with Properties#loadFromXML. 71 */ 72 static void testLoadAndStore(String encoding) throws IOException { 73 System.out.println("testLoadAndStore, encoding=" + encoding); 74 75 Properties props = new Properties(); 76 props.put("k1", "foo"); 77 props.put("k2", "bar"); 78 props.put("k3", "\\u0020\\u0391\\u0392\\u0393\\u0394\\u0395\\u0396\\u0397"); 79 props.put("k4", "\u7532\u9aa8\u6587"); 80 props.put("k5", "<java.home>/lib/jaxp.properties"); 81 82 ByteArrayOutputStream out = new ByteArrayOutputStream(); 83 props.storeToXML(out, null, encoding); 84 85 Properties p = new Properties(); 86 ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); 87 p.loadFromXML(in); 88 89 if (!p.equals(props)) { 90 System.err.println("stored: " + props); 91 System.err.println("loaded: " + p); 92 throw new RuntimeException("Test failed"); 93 } 94 } 95 96 /** 97 * Test loadFromXML with a document that does not have an encoding declaration 98 */ 99 static void testLoadWithoutEncoding() throws IOException { 100 System.out.println("testLoadWithoutEncoding"); |