fiftyone.mobile.detection.webapp.binary.Reader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of 51Degrees.mobi.detection.webapp Show documentation
Show all versions of 51Degrees.mobi.detection.webapp Show documentation
51Degrees.mobi's WebApp library to be used with the core solution for extra functionality
/* *********************************************************************
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0.
*
* If a copy of the MPL was not distributed with this file, You can obtain
* one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
* ********************************************************************* */
package fiftyone.mobile.detection.webapp.binary;
import fiftyone.mobile.detection.Constants;
import fiftyone.mobile.detection.binary.BinaryException;
import fiftyone.mobile.detection.webapp.Provider;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
/**
*
* @author 51Degrees.mobi
* @version 2.1.17.1
*/
public class Reader extends fiftyone.mobile.detection.binary.Reader {
/**
*
* Reads in the data held in the embedded lite binary file and populates the
* systems data structures.
*
* @return A filled webapp Provider object.
* @throws BinaryException
*/
public static Provider create() throws BinaryException {
Provider provider = new Provider();
try {
add((fiftyone.mobile.detection.Provider) provider, new DataInputStream(new GZIPInputStream(fiftyone.mobile.detection.binary.Reader.class.getResourceAsStream(Constants.DATA_FILE_PATH))));
return provider;
} catch (IOException e) {
System.err.println("IO Exception reading GZIP File \"" + Constants.DATA_FILE_PATH + "\": " + e);
//need to return something so return un-filled provider
return provider;
}
}
/**
*
* Attempts to read in the data file located at the path provided and
* populates the systems data structures. This is used to upgrade the system
* to premium data by supplying the path to the premium data file.
*
* @param datafile The path to the premium data file.
* @return A filled web app Provider object.
* @throws BinaryException
* @throws IOException
*/
public static Provider create(String datafile) throws BinaryException, IOException {
Provider provider = new Provider();
add((fiftyone.mobile.detection.Provider) provider, new DataInputStream(new GZIPInputStream(new FileInputStream(new File(datafile)))));
return provider;
}
}