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

📄 jacsongeneric.java

📁 java编写的OCR软件
💻 JAVA
字号:
/*    Jacson    Copyright (C) 2004 Patrick Carl, patrick.carl@web.de     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;import de.spieleck.app.jacson.source.GenericJacsonChunkSource;import de.spieleck.config.ConfigNode;import de.spieleck.util.FastClassForName;import java.io.IOException;import java.util.Iterator;/** * This class extends Jacson and offers the possibility to configure * JacsonSources instead of creating them programmatically<br> * The JacsonSources used by GenericJacson have to implement * GenericJacsonChunkSources. * $Id: JacsonGeneric.java 13 2005-09-28 06:02:56Z pcs $ * @author Patrick Carl * @see GenericJacsonChunkSource */public class JacsonGeneric extends Jacson{        /**     * Creates a new JacsonGeneric     * @param config     * @param params     * @throws JacsonConfigException     */        public JacsonGeneric(ConfigNode config, JacsonState params) throws JacsonConfigException {        super(config, params);    }        /**     * creates a JacsonSource from configuration     * @return an iterator of GenericJacsonChunkSources     */    protected Iterator createSources(ConfigNode config)    throws JacsonConfigException{        JacsonRegistry r = new JacsonRegistry(config);        Iterator it = r.find(config, JS_OBJ_SOURCE);        return new GenericSourceIterator(it);    }        /**     * main class for JacsonGeneric using configured sources. The code is based     * on Jacson     * @see Jacson     */    public static void main(String[] args) {        JacsonState rootState = new JacsonState();                try {            ConfigNode config = obtainConfig(args[0], rootState);            JacsonGeneric stat = new JacsonGeneric(config, rootState);            JacsonReport jr = stat.getReport();                        jr.begin(JS_REP_PROC);            long t1 = System.currentTimeMillis();            try {                // This line contains the difference to Jacson.                // There is no hard-coded Source but the Source will be created                // from configuration                Iterator sources = stat.createSources(config);                Object src = null;                while(sources.hasNext()){                    src = sources.next();                    if(src!= null)                        stat.run((JacsonChunkSource) src);                    else                        System.err.println("Ignoring source" );                }            }            catch ( IOException e ) {                e.printStackTrace(System.out);            }            long dt = System.currentTimeMillis() - t1;            jr.report(JS_REP_TIME, ""+dt);            jr.end();            stat.summary();            jr.finish();        }        catch (JacsonConfigException e ) {            exit(JacsonGeneric.class, e);        }        catch (JacsonException e) {            e.printStackTrace();        }        catch (Exception e) {            e.printStackTrace();        }    }        /**     *     * @param node the ConfigNode to check     * @return true if given ConfigNode is accepted     */        public boolean accept(ConfigNode node) {        if(super.accept(node))            return true;        String name = node.getName();        return name.equals(JS_OBJ_SOURCE);    }        /**     * Lazy iterator over configured GenericJacsonChunkSources     */    private class GenericSourceIterator implements Iterator {                private Iterator it;        public GenericSourceIterator(Iterator it){         this.it = it;        }              public boolean hasNext() {            return it.hasNext();        }                /**         * returns the next GenericJacsonChunkSource or<br>         * If an exception is raised during configuaration of the Source         * null is returned         */        public Object next() {            ConfigNode cn = (ConfigNode) it.next();            GenericJacsonChunkSource source = (GenericJacsonChunkSource)            FastClassForName.newInstance(cn.getString(), JS_PCK_SOURCE,            GenericJacsonChunkSource.class);            try{                source.init(cn);                return source;            } catch (JacsonConfigException e){                System.err.println("Could not configure source " + source                 + "\n" + e);                return null;            }        }                /**         * not implemented         * @throws UnsupportedOperationException         */        public void remove() {            throw new UnsupportedOperationException("remove is not supported");        }            }}

⌨️ 快捷键说明

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