fiftyone.device.example.illustration
Class OfflineProcessingExample

java.lang.Object
  extended by fiftyone.device.example.illustration.OfflineProcessingExample
All Implemented Interfaces:
Closeable

public class OfflineProcessingExample
extends Object
implements Closeable

Example of using 51Degrees Pattern Detection to process a file containing User-Agent header values and output a CSV file containing the same header values with various properties detected by 51Degrees.

The example illustrates:

  1. Loading a Provider from a Disk-based (Stream) Pattern Dataset
      
          provider = new Provider(StreamFactory.create
          (Shared.getLitePatternV32(), false));
      
      
  2. Matching a User-Agent header value
    1. By creating a match and using it repeatedly (for efficiency)
            
                Match match = provider.createMatch();
            
            
            
                provider.match(userAgentString, match);
            
            
    2. By having the provider create a new Match for each detection
            
                Match match = provider.match(userAgentString);
            
            
  3. Getting the values for some properties of the matched User-Agent header
      
          Values isMobile = match.getValues("IsMobile");
      
      

    A property may have multiple values. Helper methods convert the list of values into a Boolean, Double etc. For example:

      
          isMobile.toBool();
      
      
You can run MetadataExample.main(java.lang.String[]) for a listing of which properties are available in the dataset supplied with this distribution.

The 51 Degrees Property Dictionary contains a description of each of the properties and the editions in which they are available.

main assumes it is being run with a working directory at root of project or of this module.


Field Summary
 String outputFilePath
           
 
Constructor Summary
OfflineProcessingExample()
          Initialises the device detection Provider with the included Lite data file.
 
Method Summary
 void close()
          Closes the Dataset by releasing data file readers and freeing the data file from locks.
protected  String getValueForDisplay(Values values)
          Match values may be null.
static void main(String[] args)
          Instantiates this class and starts processCsv(java.lang.String, java.lang.String) with default parameters.
 void processCsv(String inputFileName, String outputFilename)
          Reads a CSV file containing User-Agents and adds the IsMobile, PlatformName and PlatformVersion information for the first 20 lines.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

outputFilePath

public String outputFilePath
Constructor Detail

OfflineProcessingExample

public OfflineProcessingExample()
                         throws IOException
Initialises the device detection Provider with the included Lite data file. For more data see: compare data options

Throws:
IOException - if there was a problem reading from the data file.
Method Detail

processCsv

public void processCsv(String inputFileName,
                       String outputFilename)
                throws IOException
Reads a CSV file containing User-Agents and adds the IsMobile, PlatformName and PlatformVersion information for the first 20 lines. For a full list of properties and the files they are available in please see: Property Dictionary

Parameters:
inputFileName - the CSV file to read from.
outputFilename - where to save the file with extra entries.
Throws:
IOException - if there was a problem reading from the data file.

getValueForDisplay

protected String getValueForDisplay(Values values)
Match values may be null. A helper method to get something displayable

Parameters:
values - a Values to render
Returns:
a non-null String

close

public void close()
           throws IOException
Closes the Dataset by releasing data file readers and freeing the data file from locks. This method should only be used when the Dataset is no longer required, i.e. when device detection functionality is no longer required, or the data file needs to be freed.

Specified by:
close in interface Closeable
Throws:
IOException - if there was a problem accessing the data file.

main

public static void main(String[] args)
                 throws IOException
Instantiates this class and starts processCsv(java.lang.String, java.lang.String) with default parameters.

Parameters:
args - command line arguments.
Throws:
IOException - if there was a problem accessing the data file.


Copyright © 2017 51Degrees. All rights reserved.