A blazingly fast and memory efficient (thread-safe) Java client on top of the BrowsCap CSV source files.
A blazingly fast and memory efficient (thread-safe) Java client on top of the BrowsCap CSV source files.
The BrowsCap version currently shipped is: 6001007.
This library can be used to parse useragent headers in order to extract information about the used browser, browser version, platform, platform version and device type. Very useful to determine if the client is a desktop, tablet or mobile device or to determine if the client is on Windows or Mac OS (just to name a few examples).
We got some questions on the how and why of our algorithm and why it is “blazingly fast and efficient”.
In short, this is how our algorithm works:
Possible new features we’re thinking of (and are not yet present):
Add this to the dependencies in your pom.xml.
<dependency>
<groupId>com.blueconic</groupId>
<artifactId>browscap-java</artifactId>
<version>1.4.4</version>
</dependency>
import com.blueconic.browscap.BrowsCapField;
import com.blueconic.browscap.Capabilities;
import com.blueconic.browscap.ParseException;
import com.blueconic.browscap.UserAgentParser;
import com.blueconic.browscap.UserAgentService;
// ... class definition
// create a parser with the default fields
final UserAgentParser parser = new UserAgentService().loadParser(); // handle IOException and ParseException
// or create a parser with a custom defined field list
// the list of available fields can be seen inthe BrowsCapField enum
final UserAgentParser parser =
new UserAgentService().loadParser(Arrays.asList(BrowsCapField.BROWSER, BrowsCapField.BROWSER_TYPE,
BrowsCapField.BROWSER_MAJOR_VERSION,
BrowsCapField.DEVICE_TYPE, BrowsCapField.PLATFORM, BrowsCapField.PLATFORM_VERSION,
BrowsCapField.RENDERING_ENGINE_VERSION, BrowsCapField.RENDERING_ENGINE_NAME,
BrowsCapField.PLATFORM_MAKER, BrowsCapField.RENDERING_ENGINE_MAKER));
// It's also possible to supply your own ZIP file by supplying a correct path to a ZIP file in the constructor.
// This can be used when a new BrowsCap version is released which is not yet bundled in this package.
// final UserAgentParser parser = new UserAgentService("E:\\anil\\browscap.zip").loadParser();
// parser can be re-used for multiple lookup calls
final String userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36";
final Capabilities capabilities = parser.parse(userAgent);
// the default fields have getters
final String browser = capabilities.getBrowser();
final String browserType = capabilities.getBrowserType();
final String browserMajorVersion = capabilities.getBrowserMajorVersion();
final String deviceType = capabilities.getDeviceType();
final String platform = capabilities.getPlatform();
final String platformVersion = capabilities.getPlatformVersion();
// the custom defined fields are available
final String renderingEngineMaker = capabilities.getValue(BrowsCapField.RENDERING_ENGINE_MAKER);
// do something with the values