Changeset 28667 for main/trunk
- Timestamp:
- 2013-11-21T18:56:48+13:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/common-src/src/jdbmedit/Jdb2Txt.java
r21403 r28667 27 27 import jdbm.RecordManagerFactory; 28 28 import jdbm.helper.FastIterator; 29 import jdbm.helper.StringComparator; 29 30 import jdbm.htree.HTree; 30 31 … … 33 34 import java.io.OutputStreamWriter; 34 35 import java.io.PrintWriter; 36 import java.util.Collections; 37 import java.util.Iterator; 35 38 import java.util.Properties; 39 import java.util.Vector; 36 40 37 41 … … 42 46 RecordManager recman_; 43 47 HTree hashtable_; 48 boolean sort_; 44 49 45 50 static private PrintWriter utf8out = null; … … 56 61 } 57 62 63 // the default constructor retains default behaviour of not sorting the keys 58 64 public Jdb2Txt(String db_filename) 59 65 throws IOException 60 66 { 67 this(db_filename, false); 68 } 69 70 public Jdb2Txt(String db_filename, boolean sort) 71 throws IOException 72 { 73 this.sort_ = sort; 74 61 75 if (db_filename.endsWith(".jdb")) { 62 76 // remove file extension as JDBM does not expect it … … 86 100 String key; 87 101 String val; 102 103 Vector keylist = sort_ ? new Vector() : null; 88 104 89 105 iter = hashtable_.keys(); … … 91 107 while (key != null) { 92 108 val = (String) hashtable_.get(key); 93 utf8out.println("[" + key + "]"); 94 utf8out.println(val); 95 // 70 hypens 96 utf8out.println("----------------------------------------------------------------------"); 109 110 if(sort_) { 111 keylist.add(key); 112 } 113 else { 114 print_entry(key, val); 115 } 97 116 key = (String) iter.next(); 98 117 } 99 118 119 if(sort_) { 120 Collections.sort(keylist, new StringComparator()); 121 Iterator i = keylist.iterator(); 122 while(i.hasNext()) { 123 key = (String)i.next(); 124 val = (String) hashtable_.get(key); 125 print_entry(key, val); 126 } 127 } 128 100 129 recman_.close(); 101 130 } 102 131 132 public static void print_entry(String key, String value) { 133 utf8out.println("[" + key + "]"); 134 utf8out.println(value); 135 // 70 hypens 136 utf8out.println("----------------------------------------------------------------------"); 137 138 } 103 139 104 140 public static void print_usage() 105 141 { 106 System.err.println("Usage: java Jdb2Txt database-name"); 142 System.err.println("Usage: java Jdb2Txt [options] database-name"); 143 System.err.println("options: "); 144 System.err.println(" -sort\tsort the keys to the database before output\n"); 107 145 System.exit(-1); 108 146 } … … 111 149 public static void main(String[] args) 112 150 { 113 if (args.length != 1) {151 if (args.length < 1 || args.length > 2) { 114 152 print_usage(); 115 153 } 116 154 117 155 String dbname = args[0]; 156 boolean sort = false; 157 158 if(args.length == 2) { 159 if(args[0].equals("-sort")) { 160 sort = true; 161 dbname = args[1]; 162 } else { 163 System.err.println(args[0] + " is not a valid option\n"); 164 print_usage(); 165 } 166 } 118 167 119 168 try { 120 169 121 Jdb2Txt table = new Jdb2Txt(dbname );170 Jdb2Txt table = new Jdb2Txt(dbname, sort); 122 171 table.db2txt(); 123 172 }
Note:
See TracChangeset
for help on using the changeset viewer.