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

📄 eventrecordfactory.java

📁 java 读写word excel ppt
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    private boolean throwRecordEvent(Record record)    {        boolean result = true;        Iterator i = listeners.iterator();                while (i.hasNext()) {            result = ((ERFListener) i.next()).processRecord(record);              if (abortable == true && result == false) {                break;               }        }        return result;    }    /**     * Create an array of records from an input stream     *     * @param in the InputStream from which the records will be     *           obtained     *     * @exception RecordFormatException on error processing the     *            InputStream     */    public void processRecords(InputStream in)        throws RecordFormatException    {        Record    last_record = null;        RecordInputStream recStream = new RecordInputStream(in);        while (recStream.hasNextRecord()) {          recStream.nextRecord();          Record[] recs = createRecord(recStream);   // handle MulRK records                    if (recs.length > 1)                    {                        for (int k = 0; k < recs.length; k++)                        {                            if ( last_record != null ) {                                if (throwRecordEvent(last_record) == false && abortable == true) {                                 last_record = null;                                 break;                                   }                            }                            last_record =                                recs[ k ];                // do to keep the algorythm homogenous...you can't                        }                                 // actually continue a number record anyhow.                    }                    else                    {                        Record record = recs[ 0 ];                        if (record != null)                        {                                if (last_record != null) {                                    if (throwRecordEvent(last_record) == false && abortable == true) {                                        last_record = null;                                        break;                                       }                                }                                                                last_record = record;                            }                        }                    }                        if (last_record != null) {               throwRecordEvent(last_record);                           }        }    /**     * create a record, if there are MUL records than multiple records     * are returned digested into the non-mul form.     */    public static Record [] createRecord(RecordInputStream in)    {        Record   retval     = null;        Record[] realretval = null;        try        {            Constructor constructor =                ( Constructor ) recordsMap.get(new Short(in.getSid()));            if (constructor != null)            {                retval = ( Record ) constructor.newInstance(new Object[]                {                    in                });            }            else            {                retval = new UnknownRecord(in);            }        }        catch (Exception introspectionException)        {            throw new RecordFormatException("Unable to construct record instance" , introspectionException);        }        if (retval instanceof RKRecord)        {            RKRecord     rk  = ( RKRecord ) retval;            NumberRecord num = new NumberRecord();            num.setColumn(rk.getColumn());            num.setRow(rk.getRow());            num.setXFIndex(rk.getXFIndex());            num.setValue(rk.getRKNumber());            retval = num;        }        else if (retval instanceof DBCellRecord)        {            retval = null;        }        else if (retval instanceof MulRKRecord)        {            MulRKRecord mrk = ( MulRKRecord ) retval;            realretval = new Record[ mrk.getNumColumns() ];            for (int k = 0; k < mrk.getNumColumns(); k++)            {                NumberRecord nr = new NumberRecord();                nr.setColumn(( short ) (k + mrk.getFirstColumn()));                nr.setRow(mrk.getRow());                nr.setXFIndex(mrk.getXFAt(k));                nr.setValue(mrk.getRKNumberAt(k));                realretval[ k ] = nr;            }        }        else if (retval instanceof MulBlankRecord)        {            MulBlankRecord mb = ( MulBlankRecord ) retval;            realretval = new Record[ mb.getNumColumns() ];            for (int k = 0; k < mb.getNumColumns(); k++)            {                BlankRecord br = new BlankRecord();                br.setColumn(( short ) (k + mb.getFirstColumn()));                br.setRow(mb.getRow());                br.setXFIndex(mb.getXFAt(k));                realretval[ k ] = br;            }        }        if (realretval == null)        {            realretval      = new Record[ 1 ];            realretval[ 0 ] = retval;        }        return realretval;    }    /**     * @return an array of all the SIDS for all known records     */    public static short [] getAllKnownRecordSIDs()    {        short[] results = new short[ recordsMap.size() ];        int     i       = 0;        for (Iterator iterator = recordsMap.keySet().iterator();                iterator.hasNext(); )        {            Short sid = ( Short ) iterator.next();            results[ i++ ] = sid.shortValue();        }        return results;    }    /**     * gets the record constructors and sticks them in the map by SID     * @return map of SIDs to short,short,byte[] constructors for Record classes     * most of org.apache.poi.hssf.record.*     */    private static Map recordsToMap(Class [] records)    {        Map         result = new HashMap();        Constructor constructor;        for (int i = 0; i < records.length; i++)        {            Class record = null;            short sid    = 0;            record = records[ i ];            try            {                sid         = record.getField("sid").getShort(null);                constructor = record.getConstructor(new Class[]                {                    RecordInputStream.class                });            }            catch (Exception illegalArgumentException)            {                throw new RecordFormatException(                    "Unable to determine record types");            }            result.put(new Short(sid), constructor);        }        return result;    }}/** * ListenerWrapper just wraps an ERFListener and adds support for throwing * the event to multiple SIDs */class ListenerWrapper implements ERFListener {       private ERFListener listener;       private short[] sids;       private boolean abortable;    ListenerWrapper(ERFListener listener, short[] sids, boolean abortable) {        this.listener = listener;        this.sids = sids;           this.abortable = abortable;    }               public boolean processRecord(Record rec)    {        boolean result = true;        for (int k = 0; k < sids.length; k++) {            if (sids[k] == rec.getSid()) {                result = listener.processRecord(rec);                            if (abortable == true && result == false) {                    break;                   }            }        }        return result;    }   }

⌨️ 快捷键说明

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