Changeset 21403
- Timestamp:
- 2010-01-04T17:40:03+13:00 (14 years ago)
- Location:
- main/trunk/greenstone2/common-src/src/jdbmedit
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/common-src/src/jdbmedit/Jdb2Txt.java
r21395 r21403 30 30 31 31 import java.io.IOException; 32 import java.io.UnsupportedEncodingException; 33 import java.io.OutputStreamWriter; 34 import java.io.PrintWriter; 32 35 import java.util.Properties; 33 36 … … 40 43 HTree hashtable_; 41 44 45 static private PrintWriter utf8out = null; 46 47 static 48 { 49 try { 50 OutputStreamWriter osw = new OutputStreamWriter(System.out, "UTF-8"); 51 utf8out = new PrintWriter(osw, true); 52 } 53 catch (UnsupportedEncodingException e) { 54 System.out.println(e); 55 } 56 } 42 57 43 58 public Jdb2Txt(String db_filename) 44 59 throws IOException 45 60 { 61 if (db_filename.endsWith(".jdb")) { 62 // remove file extension as JDBM does not expect it 63 db_filename = db_filename.substring(0,db_filename.length()-4); 64 } 65 46 66 // create or open a record manager 47 67 Properties props = new Properties(); … … 71 91 while (key != null) { 72 92 val = (String) hashtable_.get(key); 73 System.out.println("[" + key + "]");74 System.out.println(val);93 utf8out.println("[" + key + "]"); 94 utf8out.println(val); 75 95 // 70 hypens 76 System.out.println("----------------------------------------------------------------------");96 utf8out.println("----------------------------------------------------------------------"); 77 97 key = (String) iter.next(); 78 98 } -
main/trunk/greenstone2/common-src/src/jdbmedit/JdbGet.java
r21402 r21403 30 30 31 31 import java.io.IOException; 32 import java.io.UnsupportedEncodingException; 33 import java.io.OutputStreamWriter; 34 import java.io.PrintWriter; 32 35 import java.util.Properties; 33 36 … … 35 38 public class JdbGet 36 39 { 40 static private PrintWriter utf8out = null; 41 42 static 43 { 44 try { 45 OutputStreamWriter osw = new OutputStreamWriter(System.out, "UTF-8"); 46 utf8out = new PrintWriter(osw, true); 47 } 48 catch (UnsupportedEncodingException e) { 49 System.out.println(e); 50 } 51 } 37 52 38 53 public static void print_usage() … … 56 71 JdbmAPI jdbm_api = new JdbmAPI(dbname,true); 57 72 String val = jdbm_api.get(key); 58 System.out.println(val);73 utf8out.println(val); 59 74 60 75 jdbm_api.close(); -
main/trunk/greenstone2/common-src/src/jdbmedit/JdbKeys.java
r21402 r21403 25 25 26 26 import java.io.IOException; 27 import java.io.UnsupportedEncodingException; 28 import java.io.OutputStreamWriter; 29 import java.io.PrintWriter; 27 30 import java.util.Properties; 28 31 import java.util.ArrayList; … … 35 38 public class JdbKeys 36 39 { 40 static private PrintWriter utf8out = null; 41 42 static 43 { 44 try { 45 OutputStreamWriter osw = new OutputStreamWriter(System.out, "UTF-8"); 46 utf8out = new PrintWriter(osw, true); 47 } 48 catch (UnsupportedEncodingException e) { 49 System.out.println(e); 50 } 51 } 52 37 53 public static void print_usage() 38 54 { … … 51 67 52 68 try { 53 54 69 JdbmAPI jdbm_api = new JdbmAPI(dbname,true); 55 70 56 71 ArrayList keys = jdbm_api.get_keys(); 57 72 58 73 int keys_len = keys.size(); 59 74 for (int i=0; i<keys_len; i++) { 60 75 String key = (String) keys.get(i); 61 System.out.println(key);76 utf8out.println(key); 62 77 } 63 78 -
main/trunk/greenstone2/common-src/src/jdbmedit/JdbmAPI.java
r21402 r21403 27 27 import java.io.InputStreamReader; 28 28 import java.io.IOException; 29 import java.io.UnsupportedEncodingException; 30 import java.io.OutputStreamWriter; 31 import java.io.PrintWriter; 29 32 30 33 import java.util.Properties; … … 45 48 HTree hashtable_; 46 49 50 static private PrintWriter utf8out = null; 51 52 static 53 { 54 try { 55 OutputStreamWriter osw = new OutputStreamWriter(System.out, "UTF-8"); 56 utf8out = new PrintWriter(osw, true); 57 } 58 catch (UnsupportedEncodingException e) { 59 System.out.println(e); 60 } 61 } 62 47 63 public JdbmAPI(String db_filename,boolean must_exist) 48 64 throws IOException 49 65 { 66 if (db_filename.endsWith(".jdb")) { 67 // remove file extension as JDBM does not expect it 68 db_filename = db_filename.substring(0,db_filename.length()-4); 69 } 70 50 71 // create or open a record manager 51 72 Properties props = new Properties(); … … 197 218 JdbmAPI jdbm_api = new JdbmAPI(dbname); 198 219 199 InputStreamReader isr=new InputStreamReader(System.in );220 InputStreamReader isr=new InputStreamReader(System.in,"UTF-8"); 200 221 BufferedReader brin = new BufferedReader(isr); 201 222 … … 208 229 209 230 int keys_len = keys.size(); 210 System.out.println(keys_len);231 utf8out.println(keys_len); 211 232 212 233 for (int i=0; i<keys_len; i++) { 213 234 String key = (String) keys.get(i); 214 System.out.println(key);235 utf8out.println(key); 215 236 } 216 237 } … … 221 242 if (cmd.equals("Get")) { 222 243 String val = jdbm_api.get(key); 223 System.out.println(val.length());224 System.out.println(val);244 utf8out.println(val.length()); 245 utf8out.println(val); 225 246 } 226 247 else { -
main/trunk/greenstone2/common-src/src/jdbmedit/Txt2Jdb.java
r21395 r21403 26 26 import java.io.BufferedInputStream; 27 27 import java.io.InputStream; 28 import java.io.IOException; 29 import java.io.InputStreamReader; 30 import java.io.BufferedReader; 31 import java.util.Properties; 28 32 29 33 import jdbm.RecordManager; … … 32 36 import jdbm.htree.HTree; 33 37 34 import java.io.IOException;35 import java.util.Properties;36 37 38 38 39 public class Txt2Jdb … … 47 48 throws IOException 48 49 { 50 if (db_filename.endsWith(".jdb")) { 51 // remove file extension as JDBM does not expect it 52 db_filename = db_filename.substring(0,db_filename.length()-4); 53 } 54 49 55 // create or open a record manager 50 56 Properties props = new Properties(); … … 75 81 // Assumes InputStream is a file or standard-in 76 82 // (no some other form of IO mapped device) 77 public boolean eof(InputStream is) 83 //public boolean eof(InputStream is) 84 public boolean eof(int c) 78 85 throws IOException 79 86 { 80 return ( is.available() == 0);87 return (c == -1); 81 88 } 82 89 … … 95 102 boolean delkey = false; 96 103 97 BufferedInputStream bis = new BufferedInputStream(System.in); 98 104 105 InputStreamReader isr = new InputStreamReader(System.in,"UTF-8"); 106 BufferedReader bis = new BufferedReader(isr); 107 99 108 int c = bis.read(); 100 while (!eof( bis)) {109 while (!eof(c)) { 101 110 num_dashes = 0; 102 111 key = new StringBuffer(); … … 106 115 107 116 // scan for first occurrence of [ 108 while (!eof( bis) && c != '[') {109 c = bis.read(); 110 } 111 112 113 if (!eof( bis)) {117 while (!eof(c) && c != '[') { 118 c = bis.read(); 119 } 120 121 122 if (!eof(c)) { 114 123 c = bis.read(); // skip [ 115 124 } … … 117 126 118 127 // now look for closing ], building up 'key' as we go 119 while (!eof( bis) && c != ']') {128 while (!eof(c) && c != ']') { 120 129 key.append ((char)c); 121 130 c = bis.read(); 122 131 } 123 132 124 if (!eof( bis)) {133 if (!eof(c)) { 125 134 // most likely an eol char, but if '-', then signifies record 126 135 // is to be deleted, not added … … 134 143 } 135 144 136 while (!eof( bis) && (c == '\n' || c == '\r')) {145 while (!eof(c) && (c == '\n' || c == '\r')) { 137 146 c = bis.read(); 138 147 } … … 140 149 // look for 70 dashes 141 150 tmp = new StringBuffer(); 142 while (!eof( bis) && (num_dashes < 70)) {151 while (!eof(c) && (num_dashes < 70)) { 143 152 if (c == '\n') { 144 153 tmp.append((char)c);
Note:
See TracChangeset
for help on using the changeset viewer.