public class OnlineUpdater
extends java.lang.Thread
The updated UA strings are cached on disk. If no cached copy is found on start, one will be fetched immediately. If this initial update fails, it will fallback to an included copy.
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
CACHE_FILENAME |
protected java.io.File |
cacheFile |
protected int |
currentVersion |
protected static java.lang.String |
DATA_RETRIVE_URL |
protected UASparser |
parser |
static java.lang.String |
PROPERTIES_FILENAME |
protected java.io.File |
propsFile |
protected long |
updateInterval |
protected static java.lang.String |
VERSION_CHECK_URL |
| Constructor and Description |
|---|
OnlineUpdater(UASparser parser)
Create a new updater with the default interval of 1 day
|
OnlineUpdater(UASparser parser,
java.lang.String cacheDir,
long interval,
java.util.concurrent.TimeUnit units)
Create a new updater
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
copyFile(java.io.File src,
java.io.File dest)
Copy source file to destination
|
static java.io.InputStream |
getVendoredInputStream()
Retrieve an
InputStream to the vendored copy of the UA strings file. |
protected int |
getVersionFromServer()
Gets the current version from user-agent-string.info
|
void |
init()
Initialize the parser with cached data.
|
protected java.util.List<Section> |
loadDataFromInternet()
Loads the data file from user-agent-string.info and caches it on disk
|
void |
run()
Update loop
|
boolean |
update()
Fetch latest UA file if a newer one is available
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yieldpublic static final java.lang.String CACHE_FILENAME
public static final java.lang.String PROPERTIES_FILENAME
protected static final java.lang.String DATA_RETRIVE_URL
protected static final java.lang.String VERSION_CHECK_URL
protected final long updateInterval
protected int currentVersion
protected UASparser parser
protected java.io.File cacheFile
protected java.io.File propsFile
public OnlineUpdater(UASparser parser)
parser - Parser instance to updatepublic OnlineUpdater(UASparser parser, java.lang.String cacheDir, long interval, java.util.concurrent.TimeUnit units)
parser - Parser instance to updatecacheDir - directory where file should be cached. If null, uses system temp dirinterval - number of intervals for the given unitsunits - unit typepublic void init()
public static java.io.InputStream getVendoredInputStream()
InputStream to the vendored copy of the UA strings file.InputStreampublic boolean update()
public void run()
run in interface java.lang.Runnablerun in class java.lang.Threadprotected java.util.List<Section> loadDataFromInternet() throws java.io.IOException
java.io.IOExceptionprotected void copyFile(java.io.File src,
java.io.File dest)
throws java.io.FileNotFoundException,
java.io.IOException
src - dest - java.io.FileNotFoundExceptionjava.io.IOExceptionprotected int getVersionFromServer()
throws java.io.IOException
java.io.IOException{@link - NumberFormatException}