import java. util. Locale ;
public class OSUtils { private final static PlatformEnum OPERATING_SYSTEM_NAME ; private final static String OPERATING_SYSTEM_ARCH ; private static String normalize ( String value) { return value == null ? "" : value. toLowerCase ( Locale . US ) . replaceAll ( "[^a-z0-9]+" , "" ) ; } private static String normalizeArch ( String value) { value = normalize ( value) ; if ( value. matches ( "^(x8664|amd64|ia32e|em64t|x64)$" ) ) { return "x86_64" ; } else if ( value. matches ( "^(x8632|x86|i[3-6]86|ia32|x32)$" ) ) { return "x86_32" ; } else if ( value. matches ( "^(ia64w?|itanium64)$" ) ) { return "itanium_64" ; } else if ( "ia64n" . equals ( value) ) { return "itanium_32" ; } else if ( value. matches ( "^(sparc|sparc32)$" ) ) { return "sparc_32" ; } else if ( value. matches ( "^(sparcv9|sparc64)$" ) ) { return "sparc_64" ; } else if ( value. matches ( "^(arm|arm32)$" ) ) { return "arm_32" ; } else if ( "aarch64" . equals ( value) ) { return "aarch_64" ; } else if ( value. matches ( "^(mips|mips32)$" ) ) { return "mips_32" ; } else if ( value. matches ( "^(mipsel|mips32el)$" ) ) { return "mipsel_32" ; } else if ( "mips64" . equals ( value) ) { return "mips_64" ; } else if ( "mips64el" . equals ( value) ) { return "mipsel_64" ; } else if ( value. matches ( "^(ppc|ppc32)$" ) ) { return "ppc_32" ; } else if ( value. matches ( "^(ppcle|ppc32le)$" ) ) { return "ppcle_32" ; } else if ( "ppc64" . equals ( value) ) { return "ppc_64" ; } else if ( "ppc64le" . equals ( value) ) { return "ppcle_64" ; } else if ( "s390" . equals ( value) ) { return "s390_32" ; } else { return "s390x" . equals ( value) ? "s390_64" : value; } } static { String name = System . getProperty ( "os.name" ) . toLowerCase ( Locale . ENGLISH ) ; String arch = System . getProperty ( "os.arch" ) . toLowerCase ( Locale . ENGLISH ) ; if ( name. startsWith ( "linux" ) ) { OPERATING_SYSTEM_NAME = PlatformEnum . LINUX ; } else if ( ! name. startsWith ( "mac" ) && ! name. startsWith ( "darwin" ) ) { if ( name. startsWith ( "windows" ) ) { OPERATING_SYSTEM_NAME = PlatformEnum . WINDOWS ; } else { OPERATING_SYSTEM_NAME = PlatformEnum . UNKNOWN ; } } else { OPERATING_SYSTEM_NAME = PlatformEnum . MACOSX ; } OPERATING_SYSTEM_ARCH = normalizeArch ( arch) ; } public enum PlatformEnum { WINDOWS , LINUX , MACOSX , UNKNOWN ; } public static void main ( String [ ] args) { System . out. println ( OSUtils . OPERATING_SYSTEM_NAME . name ( ) ) ; System . out. println ( OSUtils . OPERATING_SYSTEM_ARCH ) ; }
}