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

com.truthbean.common.mini.util.OsUtils Maven / Gradle / Ivy

There is a newer version: 0.5.4-RELEASE
Show newest version
/**
 * Copyright (c) 2021 TruthBean(Rogar·Q)
 * Debbie is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
package com.truthbean.common.mini.util;

/**
 * 

系统相关的工具类

* * @author TruthBean * @since 0.0.2 * Created on 2019/08/20 22:49. * @version 0.0.2 */ public class OsUtils { private static final System.Logger LOGGER = System.getLogger(OsUtils.class.getName()); private static final String OS_NAME; private static final boolean IS_LINUX_OS; private static final boolean IS_WIN_OS; private static final boolean IS_MAC_OS; private static final String OS_ARCH; private static final String JAVA_VERSION; private static final int JVM_VERSION; static { String osName = System.getProperty("os.name").toLowerCase(); LOGGER.log(System.Logger.Level.DEBUG, () -> " system property:" + System.getProperties().getProperty("os.name")); String javaVersion = System.getProperty("java.version"); LOGGER.log(System.Logger.Level.DEBUG, () -> " java version:" + javaVersion); String osArch = System.getProperty("os.arch"); LOGGER.log(System.Logger.Level.DEBUG, () -> " os arch:" + osArch); String jvmVersion = System.getProperty("java.vm.specification.version"); int version = 0; try { version = Integer.parseInt(jvmVersion); } catch (NumberFormatException e) { e.printStackTrace(); } JVM_VERSION = version; osName = osName.toLowerCase(); IS_LINUX_OS = osName.contains("linux"); IS_WIN_OS = osName.contains("win"); IS_MAC_OS = osName.contains("mac"); OS_NAME = osName; JAVA_VERSION = javaVersion; OS_ARCH = osArch; } private OsUtils() { } /** *

getOsName.

* * @return a {@link java.lang.String} object. */ public static String getOsName() { return OS_NAME; } /** *

getJavaVersion.

* * @return a {@link java.lang.String} object. */ public static String getJavaVersion() { return JAVA_VERSION; } /** *

isIsJava11.

* * @return a boolean. */ public static boolean isIsJava11() { return JVM_VERSION == 11; } /** *

isIsJava12.

* * @return a boolean. */ public static boolean isIsJava12() { return JVM_VERSION == 12; } /** *

isIsJava13.

* * @return a boolean. */ public static boolean isIsJava13() { return JVM_VERSION == 13; } /** *

isIsJava14.

* * @return a boolean. */ public static boolean isIsJava14() { return JVM_VERSION == 14; } /** *

isIsJava15.

* * @return a boolean. */ public static boolean isIsJava15() { return JVM_VERSION == 15; } /** *

isIsJava16.

* * @return a boolean. */ public static boolean isIsJava16() { return JVM_VERSION == 16; } /** *

isIsJava17.

* * @return a boolean. */ public static boolean isIsJava17() { return JVM_VERSION == 17; } /** *

getOsArch.

* * @return a {@link java.lang.String} object. */ public static String getOsArch() { return OS_ARCH; } /** *

isLinuxOs.

* * @return a boolean. */ public static boolean isLinuxOs() { return IS_LINUX_OS; } /** *

isWinOs.

* * @return a boolean. */ public static boolean isWinOs() { return IS_WIN_OS; } /** *

isMacOs.

* * @return a boolean. */ public static boolean isMacOs() { return IS_MAC_OS; } /** *

getLf.

* * @return a {@link java.lang.String} object. */ public static String getLf() { if (isWinOs()) { return "\r\n"; } else if (isLinuxOs()) { return "\n"; } else { return "\n"; } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy