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

📄 groupingfilter.java

📁 java编写的OCR软件
💻 JAVA
字号:
/*    Jacson    Copyright (C) 2005 Patrick Carl, pcs_org at users.sf.net     This library is free software; you can redistribute it and/or    modify it under the terms of the GNU Lesser General Public    License as published by the Free Software Foundation; either    version 2.1 of the License, or (at your option) any later version.     This library is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    Lesser General Public License for more details.     You should have received a copy of the GNU Lesser General Public    License along with this library; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  */package de.spieleck.app.jacson.filter;import de.spieleck.app.jacson.JacsonConfigException;import de.spieleck.app.jacson.JacsonRegistry;import de.spieleck.config.ConfigNode;import org.apache.log4j.Logger;/** * <h2>GroupingFilter</h2> * <h3>Description</h3> * <p>Filter class which concatenates the received chunks and * delivers them as one chunk as soon as a configurable split token * shows up</p> * <h3>Parameters</h3> * <table border="1" cellpadding="2" cellspacing="0"> *  <tr> *   <td valign="top"><b>Attribute</b></td> *   <td valign="top"><b>Description</b></td> *   <td align="center" valign="top"><b>Required</b></td> *  </tr> *  <tr> *   <td valign="top">delim</td> *   <td valign="top">The string separating the different tokens</td> *   <td valign="top" align="center">No, default is ;</td> *  </tr> * </table> *  * @author pcs * @version $Id: GroupingFilter.java 35 2005-10-03 22:08:55Z pcs $ * @since 0.90 */public class GroupingFilter extends ConstFilter {        private  static final Logger logger = Logger.getLogger(GroupingFilter.class);        /**     * name of config node containing the delimiter token     */    public static final String DELIM_NODE = "delim";    /**     * default value for delimiter if none is given     */    public static final String DELIM_DEFAULT = ";";        private String delim;    private StringBuffer buffer = new StringBuffer(1024);        GroupingFilter(String delim){        this.delim = delim;    }            /**     * initializes this object     * @param config a ConfigNode containing the configuration     * @param registry the JacsonRegistry     */        public void init(ConfigNode config, JacsonRegistry registry)    throws JacsonConfigException {        delim = config.getString(DELIM_NODE, DELIM_DEFAULT);        super.init(config, registry);    }        /**     * returns true if the given node is accepted by this object     * @param node the config node to check     * @return true if the node is accepted     */    public boolean accept(ConfigNode node) {        if(logger.isDebugEnabled())            logger.debug("GroupingFilter.init");        return DELIM_NODE.equals(node.getName()) || super.accept(node);    }        public void putChunk(String chunk) throws de.spieleck.app.jacson.JacsonException {        if(logger.isDebugEnabled())            logger.debug("GroupingFilter received " + chunk);        if(chunk == null) {            drain.putChunk(buffer.toString());            drain.putChunk(null);            return;        }        String[] tokens = chunk.split(delim);        if(logger.isDebugEnabled())            logger.debug("Split chunk in " + tokens.length + " tokens");        if(tokens.length == 1 && !chunk.endsWith(delim))            buffer.append(chunk + "\n");        else {            drain.putChunk(buffer.toString() + tokens[0]);            for(int i = 1, l = tokens.length - 1; i < l; i++){                drain.putChunk(tokens[i]);            }            if(logger.isDebugEnabled())                logger.debug("Creating new buffer");            buffer = new StringBuffer(1024);            if(tokens.length > 1)                buffer.append(tokens[tokens.length - 1]);      }    }}

⌨️ 快捷键说明

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