1 24 25 package org.objectweb.cjdbc.common.util; 26 27 import java.util.ArrayList ; 28 import java.util.Enumeration ; 29 import java.util.Hashtable ; 30 31 37 public class ReadWrite 38 { 39 40 47 public static String write(Hashtable table, boolean prefix) 48 { 49 if (table == null) 50 return ""; 51 StringBuffer buffer = new StringBuffer (); 52 Enumeration e = table.keys(); 53 Object o; 54 while (e.hasMoreElements()) 55 { 56 o = e.nextElement(); 57 if (o.toString().indexOf(".path") != -1) 58 { 59 buffer.append(o + " = " + System.getProperty("line.separator")); 61 String substring = (String ) table.get(o); 62 int index; 63 while (true) 64 { 65 index = substring.indexOf(':'); 66 if (index == -1) 67 break; 68 if (prefix) 69 buffer.append("\t\t"); 70 buffer.append(substring.substring(0, index) 71 + System.getProperty("line.separator")); 72 substring = substring.substring(index + 1); 73 } 74 if (prefix) 75 buffer.append("\t\t"); 76 buffer.append(substring + System.getProperty("line.separator")); 77 } 78 else 79 { 80 buffer.append(o + " = " + table.get(o) 81 + System.getProperty("line.separator")); 82 } 83 } 84 return buffer.toString(); 85 } 86 87 95 public static String write(ArrayList list, String listName, 96 boolean writeCountKey) 97 { 98 if (list == null) 99 return ""; 100 StringBuffer buffer = new StringBuffer (); 101 int size = list.size(); 102 if (writeCountKey) 103 buffer.append(listName + ".items.count=" + size 104 + System.getProperty("line.separator")); 105 for (int i = 0; i < size; i++) 106 buffer.append(listName + "." + i + "=" + list.get(i) 107 + System.getProperty("line.separator")); 108 return buffer.toString(); 109 } 110 } | Popular Tags |