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