1 16 19 20 package org.apache.pluto.portalImpl.util; 21 22 import java.io.BufferedReader ; 23 import java.io.IOException ; 24 import java.io.InputStream ; 25 import java.io.InputStreamReader ; 26 import java.util.Iterator ; 27 28 33 34 public class Properties extends NameValuePairs 35 { 36 37 40 41 public void load (InputStream aInputStream) throws IOException 42 { 43 if (aInputStream == null) 44 return; 45 46 BufferedReader reader = new BufferedReader (new InputStreamReader (aInputStream, "UTF-8")); 47 48 String line; 49 50 while ((line = reader.readLine ()) != null) 51 { 52 if (line.startsWith ("#") || 53 line.startsWith ("//")) 54 { 55 continue; 56 } 57 58 int index = line.indexOf ('='); 59 60 if (index > 0) 61 { 62 String name = line.substring (0, index).trim (); 63 64 if (name.length () == 0) 65 name = null; 66 67 String value = null; 68 69 if (index + 1 < line.length ()) 70 { 71 value = line.substring (index + 1).trim (); 72 73 if (value.length () == 0) 74 value = null; 75 } 76 77 if (name != null && value != null) 78 { 79 add (name, value); 80 } 81 } 82 } 83 } 84 85 86 98 99 public Properties getSubSet (String aNamePrefix) 100 { 101 Properties subset = new Properties(); 102 int prefixLength = aNamePrefix.length(); 103 String name; 104 105 for (Iterator iter = this.names (); iter.hasNext () ; ) 106 { 107 name = (String ) iter.next (); 108 109 if (name.startsWith(aNamePrefix)) 110 { 111 subset.add( name.substring(prefixLength), getStrings(name)); 112 } 113 } 114 return (subset); 115 } 116 } 117 | Popular Tags |