Package net.i2p.client.naming
Class SingleFileNamingService
- java.lang.Object
-
- net.i2p.client.naming.NamingService
-
- net.i2p.client.naming.SingleFileNamingService
-
public class SingleFileNamingService extends NamingService
A naming service based on a single file using the "hosts.txt" format. Supports adds, removes, and listeners. All methods here are case-sensitive. Conversion to lower case is done in HostsTxtNamingService. This does NOT provide .b32.i2p or {b64} resolution. It also does not do any caching. Use from HostsTxtNamingService or chain with another NamingService via MetaNamingService if you need those features.- Since:
- 0.8.7
-
-
Field Summary
-
Fields inherited from class net.i2p.client.naming.NamingService
_context, _listeners, _log, _updaters, PROP_IMPL
-
-
Constructor Summary
Constructors Constructor Description SingleFileNamingService(I2PAppContext context, String filename)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
export(Writer out, Properties options)
Overridden for efficiency.Map<String,String>
getBase64Entries(Properties options)
Overridden since we store base64 natively.Map<String,Destination>
getEntries(Properties options)
Warning - This will bring the whole database into memory if options is null, empty, or unsupported, use with caution.String
getName()
Set<String>
getNames(Properties options)
Destination
lookup(String hostname, Properties lookupOptions, Properties storedOptions)
Will strip a "www." prefix and retry if lookup failsboolean
put(String hostname, Destination d, Properties options)
Add a hostname and Destination to the addressbook.boolean
putIfAbsent(String hostname, Destination d, Properties options)
Add a hostname and Destination to the addressbook.boolean
remove(String hostname, Properties options)
Delete the entry.String
reverseLookup(Destination dest, Properties options)
Same as reverseLookup(dest) but with options This implementation returns null.void
shutdown()
Parent will call when removed.int
size(Properties options)
This implementation returns -1.static void
writeOptions(Properties options, Writer out)
Write the subscription options part of the line (including the #!).-
Methods inherited from class net.i2p.client.naming.NamingService
addDestination, addDestination, addNamingService, addNamingService, createInstance, export, getConfiguration, getEntries, getNames, getNamingServices, getParent, lookup, lookup, lookupAll, lookupAll, lookupBase32, lookupBase64, put, putAll, putIfAbsent, registerListener, registerUpdater, remove, remove, remove, removeNamingService, requestUpdate, reverseLookup, reverseLookup, reverseLookupAll, reverseLookupAll, reverseLookupAll, setConfiguration, size, start, toString, unregisterListener, unregisterUpdater, update
-
-
-
-
Constructor Detail
-
SingleFileNamingService
public SingleFileNamingService(I2PAppContext context, String filename)
-
-
Method Detail
-
getName
public String getName()
- Overrides:
getName
in classNamingService
- Returns:
- the file's absolute path
-
lookup
public Destination lookup(String hostname, Properties lookupOptions, Properties storedOptions)
Will strip a "www." prefix and retry if lookup fails- Specified by:
lookup
in classNamingService
- Parameters:
hostname
- case-sensitive; caller should convert to lower caselookupOptions
- ignoredstoredOptions
- ignored- Returns:
- dest or null
-
reverseLookup
public String reverseLookup(Destination dest, Properties options)
Description copied from class:NamingService
Same as reverseLookup(dest) but with options This implementation returns null. Subclasses implementing reverse lookups should override.- Overrides:
reverseLookup
in classNamingService
- Parameters:
options
- ignoreddest
- non-null- Returns:
- hostname or null
-
put
public boolean put(String hostname, Destination d, Properties options)
Description copied from class:NamingService
Add a hostname and Destination to the addressbook. Overwrites old entry if it exists. See also putIfAbsent() and update().- Overrides:
put
in classNamingService
- Parameters:
hostname
- case-sensitive; caller should convert to lower caseoptions
- if non-null, any prefixed with '=' will be appended in subscription format- Returns:
- success
-
putIfAbsent
public boolean putIfAbsent(String hostname, Destination d, Properties options)
Description copied from class:NamingService
Add a hostname and Destination to the addressbook. Fails if entry previously exists. See also put() and update().- Overrides:
putIfAbsent
in classNamingService
- Parameters:
hostname
- case-sensitive; caller should convert to lower caseoptions
- if non-null, any prefixed with '=' will be appended in subscription format- Returns:
- success
-
writeOptions
public static void writeOptions(Properties options, Writer out) throws IOException
Write the subscription options part of the line (including the #!). Only options starting with '=' (if any) are written (with the '=' stripped). Does not write a newline.- Parameters:
options
- non-null- Throws:
IOException
- Since:
- 0.9.26, package private since 0.9.30, public since 0.9.31
-
remove
public boolean remove(String hostname, Properties options)
Description copied from class:NamingService
Delete the entry.- Overrides:
remove
in classNamingService
- Parameters:
hostname
- case-sensitive; caller should convert to lower caseoptions
- ignored- Returns:
- true if removed successfully, false on error or if it did not exist
-
getEntries
public Map<String,Destination> getEntries(Properties options)
Description copied from class:NamingService
Warning - This will bring the whole database into memory if options is null, empty, or unsupported, use with caution.- Overrides:
getEntries
in classNamingService
- Parameters:
options
- null OK, or as follows: Key "search": return only those matching substring Key "startsWith": return only those starting with ("[0-9]" allowed)- Returns:
- all mappings (matching the options if non-null) or empty Map if none; Returned Map is not necessarily sorted, implementation dependent
-
getBase64Entries
public Map<String,String> getBase64Entries(Properties options)
Overridden since we store base64 natively.- Overrides:
getBase64Entries
in classNamingService
- Parameters:
options
- null OK, or as follows: Key "search": return only those matching substring Key "startsWith": return only those starting with ("[0-9]" allowed)- Returns:
- all mappings (matching the options if non-null) or empty Map if none. Returned Map is not sorted.
- Since:
- 0.9.20
-
export
public void export(Writer out, Properties options) throws IOException
Overridden for efficiency. Output is not sorted.- Overrides:
export
in classNamingService
- Parameters:
options
- ignored- Throws:
IOException
- Since:
- 0.9.20
-
getNames
public Set<String> getNames(Properties options)
- Overrides:
getNames
in classNamingService
- Parameters:
options
- ignored- Returns:
- all known hostnames, unsorted
-
size
public int size(Properties options)
Description copied from class:NamingService
This implementation returns -1. Most subclasses should override.- Overrides:
size
in classNamingService
- Parameters:
options
- ignored- Returns:
- number of entries (matching the options if non-null) or -1 if unknown
-
shutdown
public void shutdown()
Description copied from class:NamingService
Parent will call when removed. If this is the root naming service, the core will stop it. Should not be called by others.- Overrides:
shutdown
in classNamingService
-
-