All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arch.util.OperationSystemUtils Maven / Gradle / Ivy

There is a newer version: 18.12.0
Show newest version
package com.arch.util;

import com.arch.type.OperationSystemType;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Locale;

public final class OperationSystemUtils {

    private OperationSystemUtils() {
        //
    }

    public static boolean linux() {
        return getOperationSystem() == OperationSystemType.LINUX;
    }

    public static boolean windows() {
        return getOperationSystem() == OperationSystemType.WINDOWS;
    }

    public static String computerName() throws UnknownHostException {
        InetAddress addr = InetAddress.getLocalHost();
        return addr.getHostName();
    }

    public static String hostAddress() throws UnknownHostException {
        InetAddress addr = InetAddress.getLocalHost();
        return addr.getHostAddress();
    }

    public static OperationSystemType getOperationSystem() {
        String osName = System.getProperty("os.name");

        if (osName.toLowerCase(Locale.ENGLISH).contains("windows")) {
            return OperationSystemType.WINDOWS;
        } else {
            return OperationSystemType.LINUX;
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy