Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

com.github.codesorcery:juan

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

com.github.codesorcery:juan

Fast and dependency-free Java 8 user agent analyzer

  • 0.2.0
  • Source
  • Maven
  • Socket score

Version published
Maintainers
1
Source

Java Useragent ANalyzer

Build Status Quality Gate Coverage License Maven Central

A fast, thread-safe and dependency-free user agent parser for Java 8+.

Usage

Simply add the library to the dependency section of your pom.xml (if you're using Maven):

<dependency>
  <groupId>com.github.codesorcery</groupId>
  <artifactId>juan</artifactId>
  <version>0.1.1</version>
</dependency>

Or add it to your build.gradle (if you're using Gradle):

dependencies {
  compile('com.github.codesorcery:juan:0.1.1')
}

The library can then be used as follows:

import com.github.codesorcery.juan.UserAgentParser;
import com.github.codesorcery.juan.ParsedUserAgent;

import java.io.IOException;
import java.net.URL;
import java.nio.charset.Charset;

public class UserAgentParserExample {
    private final UserAgentParser userAgentParser;
    
    public UserAgentParserExample() throws IOException {
        // To detect the device name and vendor for Android devices, we use Google's device list:
        URL deviceList =
                new URL("http://storage.googleapis.com/play_public/supported_devices.csv");
        userAgentParser =
                UserAgentParser.withPlayStoreDeviceList(deviceList, Charset.forName("UTF-16"));
        
        // If you do not need Android device info, you can use the parser without the device list:
        // userAgentParser = UserAgentParser.withoutPlayStoreDeviceList();
    }
    
    public void parsingExample() {
        String userAgentString =
                "Mozilla/5.0 (Linux; Android 7.0; SM-G892A Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/60.0.3112.107 Mobile Safari/537.36";
        ParsedUserAgent parsed =
                userAgentParser.parse(userAgentString);
        
        parsed.agent().getVendor(); // => Google
        parsed.agent().getName(); // => Chrome Mobile
        parsed.agent().getVersion(); // => 60.0.3112.107
        parsed.agent().getType(); // => Browser (mobile)
        
        parsed.os().getVendor(); // => Google
        parsed.os().getName(); // => Android
        parsed.os().getVersion(); // => 7.0
        parsed.os().getType(); // => Mobile
        
        parsed.device().getVendor(); // => Samsung
        parsed.device().getName(); // => Galaxy S8 Active
    }
    
}

Benchmark

Benchmark performed on an Intel® Core™ 2 Duo P8600 CPU @ 2.4GHz:

BenchmarkModeCntScoreErrorUnits
UserAgentParserBenchmark.amazonKindleFireSilkBrowseravgt54.641± 0.136us/op
UserAgentParserBenchmark.curlavgt51.699± 0.069us/op
UserAgentParserBenchmark.iPadMobileSafariavgt56.370± 0.266us/op
UserAgentParserBenchmark.iPhoneInstagramavgt55.257± 1.164us/op
UserAgentParserBenchmark.linuxFirefoxavgt53.522± 0.120us/op
UserAgentParserBenchmark.macOsSafariavgt53.126± 0.022us/op
UserAgentParserBenchmark.samsungGalaxyS8ChromeMobileavgt55.375± 0.102us/op
UserAgentParserBenchmark.windows10Edgeavgt53.962± 0.065us/op
UserAgentParserBenchmark.windowsPhoneavgt59.555± 0.190us/op

FAQs

Package last updated on 13 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc