⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 miscutils.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    continue;                }                try {                    Class clazz = loader.loadClass(className);                    if (clazz.isInterface()) {                        continue;                    }                    String name = getImplementedClass(clazz, interfaceName);                    if (name != null) {                        clazzes.add(className);                    }                    if (!interfaceOnly) {                        Class _clazz = clazz;                        Class superClazz = null;                                                while ((superClazz = _clazz.getSuperclass()) != null) {                            name = superClazz.getName();                            if (interfaceName.compareTo(name) == 0) {                                clazzes.add(clazz.getName());                                break;                            }                            _clazz = superClazz;                        }                                            }                                    }                // ignore - noticed with oracle 10g driver only                catch (NoClassDefFoundError e) {}                 // ignore and continue                catch (Exception e) {}            }                    }        return (String[])clazzes.toArray(new String[clazzes.size()]);    }        public static String getImplementedClass(Class clazz, String implementation) {        Class[] interfaces = clazz.getInterfaces();        for (int k = 0; k < interfaces.length; k++) {            String interfaceName = interfaces[k].getName();            if (interfaceName.compareTo(implementation) == 0) {                return clazz.getName();            }        }        Class superClazz = clazz.getSuperclass();                if (superClazz != null) {            return getImplementedClass(superClazz, implementation);        }        return null;    }        public static URL[] loadURLs(String paths) throws MalformedURLException {        String token = ";";        Vector pathsVector = new Vector();        if (paths.indexOf(token) != -1) {            StringTokenizer st = new StringTokenizer(paths, token);            while (st.hasMoreTokens()) {                pathsVector.add(st.nextToken());            }        }         else {            pathsVector.add(paths);        }        URL[] urls = new URL[pathsVector.size()];        for (int i = 0; i < urls.length; i++) {            File f = new File((String)pathsVector.elementAt(i));            urls[i] = f.toURL();        }         return urls;    }        public static String formatNumber(long number, String pattern) {        NumberFormat nf = NumberFormat.getNumberInstance();        DecimalFormat df = (DecimalFormat)nf;        df.applyPattern(pattern);        return df.format(number);    }        public static String keyStrokeToString(KeyStroke keyStroke) {        String value = null;        if (keyStroke != null) {            int mod = keyStroke.getModifiers();            value = KeyEvent.getKeyModifiersText(mod);                        if (!MiscUtils.isNull(value)) {                value += ACTION_DELIMETER;            }                        String keyText = KeyEvent.getKeyText(keyStroke.getKeyCode());                        if (!MiscUtils.isNull(keyText)) {                value += keyText;            }                    }        return value;    }        /**     * Returns the system properties from <code>System.getProperties()</code>     * as a 2 dimensional array of key/name.     */    public static String[][] getSystemProperties() {        Properties sysProps = System.getProperties();        String[] keys = new String[sysProps.size()];                int count = 0;        for (Enumeration i = sysProps.propertyNames(); i.hasMoreElements();) {            keys[count++] = (String)i.nextElement();                    }        Arrays.sort(keys);        String[][] properties = new String[keys.length][2];        for (int i = 0; i < keys.length; i++) {            properties[i][0] = keys[i];            properties[i][1] = sysProps.getProperty(keys[i]);        }        return properties;    }        /**      * Prints the system properties as [key: name].     */    public static void printSystemProperties() {        String[][] properties = getSystemProperties();        for (int i = 0; i < properties.length; i++) {            System.out.println(properties[i][0] + ": " + properties[i][1]);        }    }        public static void printActionMap(JComponent component) {        printActionMap(component.getActionMap(), component.getClass().getName());    }    public static void printInputMap(JComponent component) {        printInputMap(component.getInputMap(JComponent.WHEN_FOCUSED),                        "Input map used when focused");        printInputMap(component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT),                        "Input map used when ancestor of focused component");        printInputMap(component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW),                        "Input map used when in focused window");    }	public static void printActionMap(ActionMap actionMap, String who) {		System.out.println("Action map for " + who + ":");		Object[] keys = actionMap.allKeys();		if (keys != null) {			for (int i = 0; i < keys.length; i++) {				Object key = keys[i];				Action targetAction = actionMap.get(key);				System.out.println("\tName: <" + key + ">, action: "									+ targetAction.getClass().getName());			}		}	}    public static void printInputMap(InputMap inputMap, String heading) {        System.out.println("\n" + heading + ":");        KeyStroke[] keys = inputMap.allKeys();        if (keys != null) {            for (int i = 0; i < keys.length; i++) {                KeyStroke key = keys[i];                Object actionName = inputMap.get(key);                System.out.println("\tKey: <" + key + ">, action name: "                        + actionName);            }        }    }        public static String formatDuration(long value) {               if (twoDigitFormat == null || oneDigitFormat == null) {            oneDigitFormat = new DecimalFormat("0");            twoDigitFormat = new DecimalFormat("00");            //threeDigitFormat = new DecimalFormat("000");        }       // {"milliseconds","seconds","minutes","hours"}       long[] divisors = {1000,60,60,24};       double[] result = new double[divisors.length];       for(int i = 0; i < divisors.length;i++) {          result[i] = value % divisors[i];          value /= divisors[i];       }       /*       String[] labels = {"milliseconds","seconds","minutes","hours"};       for(int i = divisors.length-1;i >= 0;i--) {          System.out.print(" " + result[i] + " " + labels[i]);       }        System.out.println();       */        //build "hh:mm:ss.SSS"        StringBuffer buffer = new StringBuffer(" ");        buffer.append(oneDigitFormat.format(result[3]));        buffer.append(':');        buffer.append(twoDigitFormat.format(result[2]));        buffer.append(':');        buffer.append(twoDigitFormat.format(result[1]));        buffer.append('.');        buffer.append(twoDigitFormat.format(result[0]));        return buffer.toString();    }    public static boolean getBooleanValue(String value) {        return Boolean.valueOf(value).booleanValue();    }        public static String charsToString(char[] chars) {        StringBuffer sb = new StringBuffer(chars.length);        for (int i = 0; i < chars.length; i++) {            sb.append(chars[i]);        }        return sb.toString();    }     /**     * Returns whether the current version of the JVM is at least      * that specified for major and minor version numbers. For example,     * with a minium required of 1.4, the major version is 1 and minor is 4.     *     * @param major - the major version     * @param minor - the minor version     * @return whether the system version is at least major.minor     */    public static boolean isMinJavaVersion(int major, int minor) {        String version = System.getProperty("java.vm.version");        String installedVersion = version;        int index = version.indexOf("_");        if (index > 0) {            installedVersion = version.substring(0, index);        }        String[] installed = splitSeparatedValues(installedVersion, ".");                // expect to get something like x.x.x - need at least x.x        if (installed.length < 2) {            return false;        }                // major at position 0        int _version = Integer.parseInt(installed[0]);        if (_version < major) {            return false;        }                _version = Integer.parseInt(installed[1]);        if (_version < minor) {            return false;        }        return true;    }        public static byte[] inputStreamToBytes(InputStream is){        byte[] retVal =new byte[0];        ByteArrayOutputStream baos=new ByteArrayOutputStream ();        if(is!=null){            byte[] elementi = new byte[10000];            int size = 0;            try {                while((size = is.read(elementi))!=-1){                    //retVal = addBytes(retVal,elementi,(retVal.length),size);                    System.out.print(".");                    baos.write( elementi ,0,size);                }                retVal = baos.toByteArray() ;            } catch (IOException e) {                    e.printStackTrace();            } catch (Exception  e){                    e.printStackTrace() ;                    retVal = new byte[0];            }        }        return retVal;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -