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

📄 poifsdocument.java

📁 Office格式转换代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    {        _property.setStartBlock(index);    }    /* **********  END  implementation of BATManaged ********** */    /* ********** START begin implementation of POIFSViewable ********** */    /**     * Get an array of objects, some of which may implement     * POIFSViewable     *     * @return an array of Object; may not be null, but may be empty     */    public Object [] getViewableArray()    {        Object[] results = new Object[ 1 ];        String   result;        try        {            ByteArrayOutputStream output = new ByteArrayOutputStream();            BlockWritable[]       blocks = null;            if (_big_store.isValid())            {                blocks = _big_store.getBlocks();            }            else if (_small_store.isValid())            {                blocks = _small_store.getBlocks();            }            if (blocks != null)            {                for (int k = 0; k < blocks.length; k++)                {                    blocks[ k ].writeBlocks(output);                }                byte[] data = output.toByteArray();                if (data.length > _property.getSize())                {                    byte[] tmp = new byte[ _property.getSize() ];                    System.arraycopy(data, 0, tmp, 0, tmp.length);                    data = tmp;                }                output = new ByteArrayOutputStream();                HexDump.dump(data, 0, output, 0);                result = output.toString();            }            else            {                result = "<NO DATA>";            }        }        catch (IOException e)        {            result = e.getMessage();        }        results[ 0 ] = result;        return results;    }    /**     * Get an Iterator of objects, some of which may implement     * POIFSViewable     *     * @return an Iterator; may not be null, but may have an empty     * back end store     */    public Iterator getViewableIterator()    {        return Collections.EMPTY_LIST.iterator();    }    /**     * Give viewers a hint as to whether to call getViewableArray or     * getViewableIterator     *     * @return true if a viewer should call getViewableArray, false if     *         a viewer should call getViewableIterator     */    public boolean preferArray()    {        return true;    }    /**     * Provides a short description of the object, to be used when a     * POIFSViewable object has not provided its contents.     *     * @return short description     */    public String getShortDescription()    {        StringBuffer buffer = new StringBuffer();        buffer.append("Document: \"").append(_property.getName())            .append("\"");        buffer.append(" size = ").append(getSize());        return buffer.toString();    }    /* **********  END  begin implementation of POIFSViewable ********** */    private class SmallBlockStore    {        private SmallDocumentBlock[] smallBlocks;        private POIFSDocumentPath    path;        private String               name;        private int                  size;        private POIFSWriterListener  writer;        /**         * Constructor         *         * @param blocks blocks to construct the store from         */        SmallBlockStore(final Object [] blocks)        {            smallBlocks = new SmallDocumentBlock[ blocks.length ];            for (int j = 0; j < blocks.length; j++)            {                smallBlocks[ j ] = ( SmallDocumentBlock ) blocks[ j ];            }            this.path   = null;            this.name   = null;            this.size   = -1;            this.writer = null;        }        /**         * Constructor for a small block store that will be written         * later         *         * @param path path of the document         * @param name name of the document         * @param size length of the document         * @param writer the object that will eventually write the document         */        SmallBlockStore(final POIFSDocumentPath path, final String name,                        final int size, final POIFSWriterListener writer)        {            smallBlocks = new SmallDocumentBlock[ 0 ];            this.path   = path;            this.name   = name;            this.size   = size;            this.writer = writer;        }        /**         * @return true if this store is a valid source of data         */        boolean isValid()        {            return ((smallBlocks.length > 0) || (writer != null));        }        /**         * @return the SmallDocumentBlocks         */        BlockWritable [] getBlocks()        {            if (isValid() && (writer != null))            {                ByteArrayOutputStream stream  =                    new ByteArrayOutputStream(size);                DocumentOutputStream  dstream =                    new DocumentOutputStream(stream, size);                writer.processPOIFSWriterEvent(new POIFSWriterEvent(dstream,                        path, name, size));                smallBlocks = SmallDocumentBlock.convert(stream.toByteArray(),                                                         size);            }            return smallBlocks;        }    }   // end private class SmallBlockStore    private class BigBlockStore    {        private DocumentBlock[]     bigBlocks;        private POIFSDocumentPath   path;        private String              name;        private int                 size;        private POIFSWriterListener writer;        /**         * Constructor         *         * @param blocks the blocks making up the store         *         * @exception IOException on I/O error         */        BigBlockStore(final Object [] blocks)            throws IOException        {            bigBlocks = new DocumentBlock[ blocks.length ];            for (int j = 0; j < blocks.length; j++)            {                if (blocks[ j ] instanceof DocumentBlock)                {                    bigBlocks[ j ] = ( DocumentBlock ) blocks[ j ];                }                else                {                    bigBlocks[ j ] =                        new DocumentBlock(( RawDataBlock ) blocks[ j ]);                }            }            this.path   = null;            this.name   = null;            this.size   = -1;            this.writer = null;        }        /**         * Constructor for a big block store that will be written         * later         *         * @param path path of the document         * @param name name of the document         * @param size length of the document         * @param writer the object that will eventually write the         *               document         */        BigBlockStore(final POIFSDocumentPath path, final String name,                      final int size, final POIFSWriterListener writer)        {            bigBlocks   = new DocumentBlock[ 0 ];            this.path   = path;            this.name   = name;            this.size   = size;            this.writer = writer;        }        /**         * @return true if this store is a valid source of data         */        boolean isValid()        {            return ((bigBlocks.length > 0) || (writer != null));        }        /**         * @return the DocumentBlocks         */        DocumentBlock [] getBlocks()        {            if (isValid() && (writer != null))            {                ByteArrayOutputStream stream  =                    new ByteArrayOutputStream(size);                DocumentOutputStream  dstream =                    new DocumentOutputStream(stream, size);                writer.processPOIFSWriterEvent(new POIFSWriterEvent(dstream,                        path, name, size));                bigBlocks = DocumentBlock.convert(stream.toByteArray(), size);            }            return bigBlocks;        }        /**         * write the blocks to a stream         *         * @param stream the stream to which the data is to be written         *         * @exception IOException on error         */        void writeBlocks(OutputStream stream)            throws IOException        {            if (isValid())            {                if (writer != null)                {                    DocumentOutputStream dstream =                        new DocumentOutputStream(stream, size);                    writer.processPOIFSWriterEvent(                        new POIFSWriterEvent(dstream, path, name, size));                    dstream.writeFiller(countBlocks()                                        * POIFSConstants                                            .BIG_BLOCK_SIZE, DocumentBlock                                            .getFillByte());                }                else                {                    for (int k = 0; k < bigBlocks.length; k++)                    {                        bigBlocks[ k ].writeBlocks(stream);                    }                }            }        }        /**         * @return number of big blocks making up this document         */        int countBlocks()        {            int rval = 0;            if (isValid())            {                if (writer != null)                {                    rval = (size + POIFSConstants.BIG_BLOCK_SIZE - 1)                           / POIFSConstants.BIG_BLOCK_SIZE;                }                else                {                    rval = bigBlocks.length;                }            }            return rval;        }    }   // end private class BigBlockStore}       // end class POIFSDocument

⌨️ 快捷键说明

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