fiftyone.mobile.detection
Class AutoUpdate

java.lang.Object
  extended by fiftyone.mobile.detection.AutoUpdate

public class AutoUpdate
extends Object


Constructor Summary
AutoUpdate()
           
 
Method Summary
private static byte[] decompressData(byte[] content)
           
private static byte[] download(String[] licenseKeys, long lastModified)
          Downloads and validates data, returning a byte array or null if download or validation was unsuccessful.
private static URL fullUrl(String[] licenseKeys)
          Constructs the URL needed to download Premium data.
private static String getMd5Hash(byte[] value)
          Calculates the MD5 hash of the given data array.
private static Dataset getNewDataset(String[] licenseKeys, String dataFilePath)
          Downloads the latest Premium data and saves to disk if the data has been downloaded correctly and is newer than data currently in that position (if any) in that path.
private static String[] getValidKeys(String[] licenseKeys)
           
private static String joinString(String seperator, String[] strings)
           
static boolean update(String[] licenseKeys, String dataFilePath)
          Uses the given license key to perform a device data update, writing the data to the file system and filling providers from this factory instance with it.
static boolean update(String licenseKey, String dataFilePath)
          Uses the given license key to perform a device data update, writing the data to the file system and filling providers from this factory instance with it.
private static boolean validateMD5(HttpURLConnection client, byte[] data)
          Verifies that the data has been downloaded correctly by comparing an MD5 hash off the downloaded data with one taken before the data was sent, which is stored in a response header.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AutoUpdate

public AutoUpdate()
Method Detail

getNewDataset

private static Dataset getNewDataset(String[] licenseKeys,
                                     String dataFilePath)
                              throws AutoUpdateException
Downloads the latest Premium data and saves to disk if the data has been downloaded correctly and is newer than data currently in that position (if any) in that path.

Throws:
AutoUpdateException

getMd5Hash

private static String getMd5Hash(byte[] value)
Calculates the MD5 hash of the given data array.

Parameters:
value - Data to calculate the hash with.
Returns:
The MD5 hash of the given data.

validateMD5

private static boolean validateMD5(HttpURLConnection client,
                                   byte[] data)
Verifies that the data has been downloaded correctly by comparing an MD5 hash off the downloaded data with one taken before the data was sent, which is stored in a response header.

Parameters:
client - The Premium data download connection.
data - the data that has been downloaded.
Returns:
True if the hashes match, else false.

joinString

private static String joinString(String seperator,
                                 String[] strings)

fullUrl

private static URL fullUrl(String[] licenseKeys)
                    throws MalformedURLException
Constructs the URL needed to download Premium data.

Returns:
Premium data download url.
Throws:
MalformedURLException

update

public static boolean update(String licenseKey,
                             String dataFilePath)
                      throws AutoUpdateException
Uses the given license key to perform a device data update, writing the data to the file system and filling providers from this factory instance with it.

Parameters:
licenseKey - the licence key to submit to the server
Returns:
true for a successful update. False can indicate that data was unavailable, corrupt, older than the current data or not enough memory was available. In that case the current data is used.
Throws:
AutoUpdateException

update

public static boolean update(String[] licenseKeys,
                             String dataFilePath)
                      throws AutoUpdateException
Uses the given license key to perform a device data update, writing the data to the file system and filling providers from this factory instance with it.

Parameters:
licenseKeys - the licence keys to submit to the server
Returns:
true for a successful update. False can indicate that data was unavailable, corrupt, older than the current data or not enough memory was available. In that case the current data is used.
Throws:
AutoUpdateException

getValidKeys

private static String[] getValidKeys(String[] licenseKeys)

download

private static byte[] download(String[] licenseKeys,
                               long lastModified)
                        throws AutoUpdateException
Downloads and validates data, returning a byte array or null if download or validation was unsuccessful.

Parameters:
licenseKeys - an array of keys to fetch a new data file with.
Returns:
a decompressed byte array containing the data.
Throws:
AutoUpdateException

decompressData

private static byte[] decompressData(byte[] content)
                              throws IOException,
                                     DataFormatException
Throws:
IOException
DataFormatException