public class MemoryFactory extends Object
The memory usage of the resulting data set following initialisation will be consistent. The performance of the data set will be very fast compared to the stream based implementation as all required data is loaded into memory and references between related objects set at initialisation. However overall memory usage will be higher than the stream based implementation on lightly loaded environments.
Initialisation may take several seconds depending on system performance. Initialisation calculates all the references between entities. If initialisation is not performed then references will be calculated when needed. As such avoiding initialisation improves the time taken to create the data set, at the expense of performance for the initial detections. The default setting is not to initialise the data set.
Create a fully initialised Dataset:
Dataset ds = MemoryFactory.create("path_to_file", true);
The resulting dataset can then be used to work with data or used in a
Provider to perform device detections. Use in provider like:
Provider p = new Provider(ds);
This is a factory that creates a memory resident version of the 51Degrees device data in the form of a Dataset object.
| Constructor and Description |
|---|
MemoryFactory() |
| Modifier and Type | Method and Description |
|---|---|
static Dataset |
create(byte[] data)
Creates a new Dataset from the byte array.
|
static Dataset |
create(byte[] data,
boolean init)
Creates a new Dataset from the byte array.
|
static Dataset |
create(FileInputStream fileInputStream)
Creates a lazily initialised
Dataset from a
FileInputStream. |
static Dataset |
create(FileInputStream fileInputStream,
boolean init)
Creates an optionally initialised
Dataset from a
FileInputStream. |
static Dataset |
create(FileInputStream fileInputStream,
boolean init,
Date lastModified)
Creates an optionally initialised
Dataset from a
FileInputStream. |
static Dataset |
create(String filename)
Creates a new DataSet from the file provided.
|
static Dataset |
create(String filename,
boolean init)
Creates a new DataSet from the file provided.
|
static Dataset |
create(String filename,
boolean init,
Date lastModified)
Creates a new Dataset from the file provided.
|
static void |
load(Dataset dataSet,
BinaryReader reader,
boolean init)
Creates a new DataSet from the binary reader provided.
|
public static Dataset create(byte[] data) throws IOException
data - Array of bytes to build the data set from.IOException - if there was a problem accessing data file.public static Dataset create(byte[] data, boolean init) throws IOException
data - Array of bytes to build the data set from.init - True to indicate that the data set should be filling
initialised..IOException - if there was a problem accessing data file.public static Dataset create(String filename) throws IOException
filename - Uncompressed file containing the data for the data set.IOException - if there was a problem accessing data file.public static Dataset create(String filename, boolean init) throws IOException
filename - Uncompressed file containing the data for the data set.init - True to indicate that the data set should be
fully initialised.IOException - if there was a problem accessing data file.public static Dataset create(String filename, boolean init, Date lastModified) throws IOException
filename - Uncompressed file containing the data for the data set.init - True to indicate that the data set should be filling
initialised.lastModified - Date and time the source data was last modified.IOException - if there was a problem accessing data file.public static Dataset create(FileInputStream fileInputStream) throws IOException
Dataset from a
FileInputStream.
It is the caller's responsibility to close the passed fileInputStream.
fileInputStream - Source of data.IOException - if there was a problem accessing data file.public static Dataset create(FileInputStream fileInputStream, boolean init) throws IOException
Dataset from a
FileInputStream.
It is the caller's responsibility to close the passed fileInputStream
Initialisation increases load time and initial memory footprint, but improves run time performance.
fileInputStream - Source of data.init - preemptive initialise if true.IOException - if there was a problem accessing data file.public static Dataset create(FileInputStream fileInputStream, boolean init, Date lastModified) throws IOException
Dataset from a
FileInputStream.
It is the caller's responsibility to close the passed fileInputStream
Initialisation increases load time and initial memory footprint, but improves run time performance.
fileInputStream - Source of data.init - preemptive initialise if true.lastModified - the date of data update.IOException - if there was a problem accessing data file.public static void load(Dataset dataSet, BinaryReader reader, boolean init) throws IOException
A DataSet is constructed using the reader to retrieve the header information. This is then passed to the Read methods to create the lists before reading the data into memory. Finally it initialise is required references between entities are worked out and stored.
dataSet - The data set to be loaded with data from the reader.reader - BinaryReader connected to the source data structure and
positioned to start reading.init - True to indicate that the data set should be fully
initialised.IOException - if there was a problem accessing data file.Copyright © 2017 51Degrees. All rights reserved.