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

📄 filter.java

📁 本程序用于对页面信息进行提取并分析
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        Object ret;        bis = new ByteArrayInputStream (data);        ois = new ObjectInputStream (bis);        ret = ois.readObject ();        ois.close ();        return (ret);    }    /**     * Serialize a byte array to a String.     * Convert each byte from the serialized object into a couple of hexadecimal     * characters.     * @param data The serialized object as a byte array.     * @return The string representing the serialized object.     */    public static String serialize (byte[] data)    {        String string;        StringBuffer ret;                ret = new StringBuffer (data.length * 2);        for (int i = 0; i < data.length; i++)        {            string = Integer.toString (0xff & data[i], 16);            if (string.length () < 2)                ret.append ("0");            ret.append (string);        }                return (ret.toString ());    }    /**     * Convert a sequence of hexadecimal characters back into a byte array.     * @param string The string to convert (must be correct hex characters).     * @return The bytes as an array.     */    public static byte[] deserialize (String string)    {        byte[] ret;                ret = new byte[string.length () / 2];                for (int i = 0; i < string.length (); i += 2)            ret[i/2] = (byte)Integer.parseInt (string.substring (i, i + 2), 16); // todo: hopelessly inefficient                return (ret);    }    /**     * Returns a string serialization of the filters.     * @param filters The list of filters to serialize.     * @return A string representation of the filters.     * @exception IOException If serialization fails.     */    public static String deconstitute (Filter[] filters) throws IOException    {        StringBuffer ret;        ret = new StringBuffer (1024);        for (int i = 0; i < filters.length; i++)        {            ret.append ("[");            ret.append (serialize (pickle (filters[i].getNodeFilter ())));            ret.append ("]");        }        return (ret.toString ());    }    /**     * Returns the filters represented by the string.     * @param string The string with serialized node filters.     * @param context The context from which to extract meaningful values     * for GUI choices (which aren't serialized).     * @return The filters gleaned from the string.     * @see #wrap     */    public static Filter[] reconstitute (String string, Parser context)    {        Filter[] ret;        Vector vector;        int index;        String code;        Object object;        Filter filter;                vector = new Vector ();        try        {            while (string.startsWith ("["))            {                index = string.indexOf (']');                if (-1 != index)                {                    code = string.substring (1, index);                    string = string.substring (index + 1);                    object = unpickle (deserialize (code));                    if (object instanceof NodeFilter)                    {                        filter = wrap ((NodeFilter)object, context);                        if (null != filter)                            vector.addElement (filter);                    }                    else                        break;                }                else                    break;            }        }        catch (Exception e)        {            e.printStackTrace ();        }        ret = new Filter[vector.size ()];        vector.copyInto (ret);        return (ret);    }    /**     * Get the enclosed sub filter list if any.     * Todo: rationalize with FilterBuilder's method(s) of the same name.     * @param component The component that's supposedly enclosing the list.     * @return The enclosed component or <code>null</code> otherwise.     */    protected static SubFilterList getEnclosed (Component component)    {        Component[] list;        if (component instanceof Container)        {            list = ((Container)component).getComponents  ();            for (int i = 0; i < list.length; i++)                if (list[i] instanceof SubFilterList)                    return ((SubFilterList)list[i]);        }        return (null);    }    /**     * Returns a wrapped filter.     * @param filter A filter to be wrapped by GUI components.     * @param context The context within which to wrap the object.     * Some wrappers need context to set up useful choices for the user.     * @return The filter to wrap.     */    public static Filter wrap (NodeFilter filter, Parser context)    {        String class_name;        NodeFilter[] filters;        SubFilterList list;        Filter ret;        ret = null;                class_name = filter.getClass ().getName ();        class_name = (String)mWrappers.get (class_name);        if (null != class_name)        {            try            {                ret = Filter.instantiate (class_name);                ret.setNodeFilter (filter, context);                // recurse into subfilters                filters = ret.getSubNodeFilters ();                if (0 != filters.length)                {                    list = getEnclosed (ret);                    if (null != list)                    {                        ret.setSubNodeFilters (new NodeFilter[0]); // clean out the unwrapped filters                        for (int i = 0; i < filters.length; i++)                            list.addFilter (wrap (filters[i], context));                    }                    else                        throw new IllegalStateException ("filter can't have subnodes without a SubFilterList on the wrapper");                }            }            catch (Exception e)            {                e.printStackTrace ();            }        }        else            System.out.println (class_name + " is not registered for wrapping.");                return (ret);    }    /**     * Set the 'selected look' for the component.     * @param selected If <code>true</code>, 'select' this component,     * otherwise 'deselect' it.     */    public void setSelected (boolean selected)    {        if (selected)            setBorder (                new CompoundBorder (                    new EtchedBorder (),                    new CompoundBorder (                        new LineBorder(Color.blue, 2),                        new EmptyBorder (1, 1, 1, 1))));        else            setBorder (                new CompoundBorder (                    new EtchedBorder (),                    new EmptyBorder (3,3,3,3)));    }        /**     * Set the expanded state for the component.     * This sets invisible all but the JLabel component in the     * comand component.     * @param expanded If <code>true</code>, 'expand' this component,     * otherwise 'collapse' it.     */    public void setExpanded (boolean expanded)    {        Component[] components;                components = getComponents ();        for (int i = 0; i < components.length; i++)            if (!(components[i] instanceof JLabel))                components[i].setVisible (expanded);    }        /**     * Append count spaces to the buffer.     * @param out The buffer to append to.     * @param count The number of spaces to append.     */    public static void spaces (StringBuffer out, int count)    {        for (int i = 0; i < count; i++)            out.append (' ');    }        /**     * Append a newline to the buffer.     * @param out The buffer to append to.     */    public static void newline (StringBuffer out)    {        out.append ('\n');    }}

⌨️ 快捷键说明

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