一、前言
关于apache的ftpserver的核心源码包ftpserver-core中org.apache.ftpserver.util.OS操作系统工具类, 对于不同operating system操作系统(os/400、z/os、z/os、mac、win9x、openvms等)识别及版本名称处理。
二、源码说明
package org.apache.ftpserver.util;@b@@b@import java.util.Locale;@b@@b@public final class OS@b@{@b@ private static final String FAMILY_OS_400 = "os/400";@b@ private static final String FAMILY_Z_OS = "z/os";@b@ private static final String FAMILY_WIN9X = "win9x";@b@ private static final String FAMILY_OPENVMS = "openvms";@b@ private static final String FAMILY_UNIX = "unix";@b@ private static final String FAMILY_TANDEM = "tandem";@b@ private static final String FAMILY_MAC = "mac";@b@ private static final String FAMILY_DOS = "dos";@b@ private static final String FAMILY_NETWARE = "netware";@b@ private static final String FAMILY_OS_2 = "os/2";@b@ private static final String FAMILY_WINDOWS = "windows";@b@ private static final String OS_NAME = System.getProperty("os.name").toLowerCase(Locale.US);@b@ private static final String OS_ARCH = System.getProperty("os.arch").toLowerCase(Locale.US);@b@ private static final String OS_VERSION = System.getProperty("os.version").toLowerCase(Locale.US);@b@ private static final String PATH_SEP = System.getProperty("path.separator");@b@@b@ private static boolean isFamily(String family)@b@ {@b@ return isOs(family, null, null, null);@b@ }@b@@b@ public static boolean isFamilyDOS() {@b@ return isFamily("dos");@b@ }@b@@b@ public static boolean isFamilyMac() {@b@ return isFamily("mac");@b@ }@b@@b@ public static boolean isFamilyNetware() {@b@ return isFamily("netware");@b@ }@b@@b@ public static boolean isFamilyOS2() {@b@ return isFamily("os/2");@b@ }@b@@b@ public static boolean isFamilyTandem() {@b@ return isFamily("tandem");@b@ }@b@@b@ public static boolean isFamilyUnix() {@b@ return isFamily("unix");@b@ }@b@@b@ public static boolean isFamilyWindows() {@b@ return isFamily("windows");@b@ }@b@@b@ public static boolean isFamilyWin9x() {@b@ return isFamily("win9x");@b@ }@b@@b@ public static boolean isFamilyZOS() {@b@ return isFamily("z/os");@b@ }@b@@b@ public static boolean isFamilyOS400() {@b@ return isFamily("os/400");@b@ }@b@@b@ public static boolean isFamilyOpenVms() {@b@ return isFamily("openvms");@b@ }@b@@b@ public static boolean isName(String name)@b@ {@b@ return isOs(null, name, null, null);@b@ }@b@@b@ public static boolean isArch(String arch)@b@ {@b@ return isOs(null, null, arch, null);@b@ }@b@@b@ public static boolean isVersion(String version)@b@ {@b@ return isOs(null, null, null, version);@b@ }@b@@b@ public static boolean isOs(String family, String name, String arch, String version)@b@ {@b@ boolean retValue = false;@b@@b@ if ((family != null) || (name != null) || (arch != null) || (version != null))@b@ {@b@ boolean isFamily = true;@b@ boolean isName = true;@b@ boolean isArch = true;@b@ boolean isVersion = true;@b@@b@ if (family != null) {@b@ if (family.equals("windows"))@b@ isFamily = OS_NAME.indexOf("windows") > -1;@b@ else if (family.equals("os/2"))@b@ isFamily = OS_NAME.indexOf("os/2") > -1;@b@ else if (family.equals("netware"))@b@ isFamily = OS_NAME.indexOf("netware") > -1;@b@ else if (family.equals("dos")) {@b@ isFamily = (PATH_SEP.equals(";")) && (!(isFamily("netware")));@b@ }@b@ else if (family.equals("mac"))@b@ isFamily = OS_NAME.indexOf("mac") > -1;@b@ else if (family.equals("tandem"))@b@ isFamily = OS_NAME.indexOf("nonstop_kernel") > -1;@b@ else if (family.equals("unix")) {@b@ isFamily = (PATH_SEP.equals(":")) && (!(isFamily("openvms"))) && (((!(isFamily("mac"))) || (OS_NAME.endsWith("x"))));@b@ }@b@ else if (family.equals("win9x")) {@b@ isFamily = (isFamily("windows")) && (((OS_NAME.indexOf("95") >= 0) || (OS_NAME.indexOf("98") >= 0) || (OS_NAME.indexOf("me") >= 0) || (OS_NAME.indexOf("ce") >= 0)));@b@ }@b@ else if (family.equals("z/os")) {@b@ isFamily = (OS_NAME.indexOf("z/os") > -1) || (OS_NAME.indexOf("os/390") > -1);@b@ }@b@ else if (family.equals("os/400"))@b@ isFamily = OS_NAME.indexOf("os/400") > -1;@b@ else if (family.equals("openvms"))@b@ isFamily = OS_NAME.indexOf("openvms") > -1;@b@ else {@b@ throw new IllegalArgumentException("Don't know how to detect os family \"" + family + "\"");@b@ }@b@@b@ }@b@@b@ if (name != null)@b@ isName = name.equals(OS_NAME);@b@@b@ if (arch != null)@b@ isArch = arch.equals(OS_ARCH);@b@@b@ if (version != null)@b@ isVersion = version.equals(OS_VERSION);@b@@b@ retValue = (isFamily) && (isName) && (isArch) && (isVersion);@b@ }@b@ return retValue;@b@ }@b@}