- Timestamp:
- 2010-01-04T17:40:03+13:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.