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

📄 eventrecordfactory.java

📁 Office格式转换代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        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;        try        {            short rectype = 0;            do            {                rectype = LittleEndian.readShort(in);                if (rectype != 0)                {                    short  recsize = LittleEndian.readShort(in);                    byte[] data    = new byte[ ( int ) recsize ];                    in.read(data);                    Record[] recs = createRecord(rectype, recsize,                                                 data);   // 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;                                   }                            }                         //   records.add(                         //       recs[ k ]);               // these will be number records                            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 (rectype == ContinueRecord.sid &&                                ! (last_record instanceof ContinueRecord) && // include continuation records after                                ! (last_record instanceof UnknownRecord) )   // unknown records or previous continuation records                            {                                if (last_record == null)                                {                                    throw new RecordFormatException(                                        "First record is a ContinueRecord??");                                }                                last_record.processContinueRecord(data);                            }                            else                            {                                if (last_record != null) {                                    if (throwRecordEvent(last_record) == false && abortable == true) {                                        last_record = null;                                        break;                                       }                                }                                                                last_record = record;                                                                //records.add(record);                            }                        }                    }                }            }            while (rectype != 0);                        if (last_record != null) {               throwRecordEvent(last_record);                           }        }        catch (IOException e)        {            throw new RecordFormatException("Error reading bytes");        }        // Record[] retval = new Record[ records.size() ];        // retval = ( Record [] ) records.toArray(retval);         }    /**     * create a record, if there are MUL records than multiple records     * are returned digested into the non-mul form.     */    public static Record [] createRecord(short rectype, short size,                                         byte [] data)    {        Record   retval     = null;        Record[] realretval = null;        try        {            Constructor constructor =                ( Constructor ) recordsMap.get(new Short(rectype));            if (constructor != null)            {                retval = ( Record ) constructor.newInstance(new Object[]                {                    new Short(rectype), new Short(size), data                });            }            else            {                retval = new UnknownRecord(rectype, size, data);            }        }        catch (Exception introspectionException)        {            introspectionException.printStackTrace();            throw new RecordFormatException(                "Unable to construct record instance, the following exception occured: " + introspectionException.getMessage());        }        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[]                {                    short.class, short.class, byte [].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 + -