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

📄 tailpadfilter.java

📁 java编写的OCR软件
💻 JAVA
字号:
/*
    Jacson
    Copyright (C) 2004 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.JacsonException;
import de.spieleck.app.jacson.JacsonRegistry;
import de.spieleck.config.ConfigNode;
import de.spieleck.config.ConfigVerify.Acceptor;



/**
 * <h2>TailPadFilter</h2>
 * <h3>Description</h3>
 * <p>Filter class which either adds a configurable token as last chunk
 *    or appends the token to the last chunk. This allows something like
 *    awk's end.</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">post</td>
 *   <td valign="top">The token to add at the end</td>
 *   <td valign="top" align="center">Yes</td>
 *  </tr>
 *  <tr>
 *   <td valign="top">separatechunk</td>
 *   <td valign="top">Determines if the token is added as separated chunk or
 *       if the token is prepended to the first chunk</td>
 *   <td valign="top" align="center">No, default is false</td>
 *  </tr>
 * </table>
 * @version $Id: TailPadFilter.java 35 2005-10-03 22:08:55Z pcs $
 * @author pcs
 * @since 0.90
 */

public class TailPadFilter   extends FilterBase
implements FilterNames, Acceptor{
    
    public static final String POST_NODE = "post";
    private String postText;
    
    public static final String SEPARATE_CHUNK_NODE = "separatechunk";
    private boolean ownChunk;
    
    private String buffer;
    
    /** Creates a new instance of TailPadFilter */
    public TailPadFilter() {
    }
    
    public void init(ConfigNode snr, JacsonRegistry registry) throws JacsonConfigException {
        postText = snr.getString(POST_NODE, postText);
        if(postText == null)
            throw new JacsonConfigException("TailPadFilter needs a text to append");
        ownChunk = snr.getBoolean(SEPARATE_CHUNK_NODE, false);
        buffer = null;
    }
    
    public void putChunk(String ch) throws JacsonException {
        if(ch != null){
            if(ownChunk)
                drain.putChunk(ch);
            else{
                if(buffer != null)
                    drain.putChunk(buffer);
                buffer = ch;
            }
        } else {
            if(ownChunk || buffer == null){
                drain.putChunk(postText);
            } else {
                drain.putChunk(buffer + postText);
            }
            drain.putChunk(null);
        }
    }
    
    public boolean accept(ConfigNode node) {
        String name = node.getName();
        return name.equals(POST_NODE) || name.equals(SEPARATE_CHUNK_NODE);
    }
    
}

⌨️ 快捷键说明

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