Changeset 7edbd3a
- Timestamp:
- Mar 11, 2011 12:29:34 AM (10 years ago)
- Branches:
- master
- Children:
- 41fc9cf
- Parents:
- de815e2
- Location:
- core/java/src/net/i2p/client/naming
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
core/java/src/net/i2p/client/naming/MetaNamingService.java
rde815e2 r7edbd3a 4 4 import java.util.ArrayList; 5 5 import java.util.Collections; 6 import java.util. Iterator;6 import java.util.HashMap; 7 7 import java.util.List; 8 import java.util.Map; 8 9 import java.util.Properties; 9 10 import java.util.StringTokenizer; … … 153 154 return rv; 154 155 } 156 157 /** 158 * All services aggregated 159 */ 160 @Override 161 public Map<String, Destination> getEntries(Properties options) { 162 Map<String, Destination> rv = new HashMap(); 163 for (NamingService ns : _services) { 164 rv.putAll(ns.getEntries(options)); 165 } 166 return rv; 167 } 168 169 /** 170 * All services aggregated 171 */ 172 @Override 173 public int size(Properties options) { 174 int rv = 0; 175 for (NamingService ns : _services) { 176 int s = ns.size(options); 177 if (s > 0) 178 rv += s; 179 } 180 return rv; 181 } 155 182 } -
core/java/src/net/i2p/client/naming/SingleFileNamingService.java
rde815e2 r7edbd3a 14 14 import java.io.InputStreamReader; 15 15 import java.io.IOException; 16 import java.io.OutputStream; 17 import java.io.OutputStreamWriter; 18 import java.util.Collections; 19 import java.util.HashMap; 16 20 import java.util.Iterator; 17 21 import java.util.List; 18 import java.io.OutputStream; 19 import java.io.OutputStreamWriter; 22 import java.util.Map; 20 23 import java.util.Properties; 21 24 import java.util.Set; … … 284 287 } 285 288 289 /** 290 * @param options As follows: 291 * Key "startsWith": return only those starting with 292 */ 293 @Override 294 public Map<String, Destination> getEntries(Properties options) { 295 if (!_file.exists()) 296 return Collections.EMPTY_MAP; 297 String startsWith = ""; 298 if (options != null) { 299 startsWith = options.getProperty("startsWith"); 300 } 301 BufferedReader in = null; 302 getReadLock(); 303 try { 304 in = new BufferedReader(new InputStreamReader(new FileInputStream(_file), "UTF-8"), 16*1024); 305 String line = null; 306 String search = startsWith + '='; 307 Map<String, Destination> rv = new HashMap(); 308 while ( (line = in.readLine()) != null) { 309 if ((!startsWith.equals("")) && !line.startsWith(search)) 310 continue; 311 if (line.startsWith("#")) 312 continue; 313 if (line.indexOf('#') > 0) // trim off any end of line comment 314 line = line.substring(0, line.indexOf('#')).trim(); 315 int split = line.indexOf('='); 316 String key = line.substring(split); 317 String b64 = line.substring(split+1); //.trim() ?????????????? 318 try { 319 Destination dest = new Destination(b64); 320 rv.put(key, dest); 321 } catch (DataFormatException dfe) {} 322 } 323 return rv; 324 } catch (IOException ioe) { 325 _log.error("getEntries error", ioe); 326 return Collections.EMPTY_MAP; 327 } finally { 328 if (in != null) try { in.close(); } catch (IOException ioe) {} 329 releaseReadLock(); 330 } 331 } 332 333 /** 334 * @param options ignored 335 */ 336 @Override 337 public int size(Properties options) { 338 if (!_file.exists()) 339 return 0; 340 BufferedReader in = null; 341 getReadLock(); 342 try { 343 in = new BufferedReader(new InputStreamReader(new FileInputStream(_file), "UTF-8"), 16*1024); 344 String line = null; 345 int rv = 0; 346 while ( (line = in.readLine()) != null) { 347 if (line.startsWith("#")) 348 continue; 349 rv++; 350 } 351 return rv; 352 } catch (IOException ioe) { 353 _log.error("size() error", ioe); 354 return -1; 355 } finally { 356 if (in != null) try { in.close(); } catch (IOException ioe) {} 357 releaseReadLock(); 358 } 359 } 360 286 361 private static boolean rename(File from, File to) { 287 362 boolean success = false;
Note: See TracChangeset
for help on using the changeset viewer.