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

📄 poifsfilesystem.java

📁 Office格式转换代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                                             batStartBlock);        // set the property table start block        header_block_writer.setPropertyStart(_property_table.getStartBlock());        // set the small block allocation table start block        header_block_writer.setSBATStart(sbtw.getSBAT().getStartBlock());        // set the small block allocation table block count        header_block_writer.setSBATBlockCount(sbtw.getSBATBlockCount());        // the header is now properly initialized. Make a list of        // writers (the header block, followed by the documents, the        // property table, the small block store, the small block        // allocation table, the block allocation table, and the        // extended block allocation table blocks)        List writers = new ArrayList();        writers.add(header_block_writer);        writers.addAll(_documents);        writers.add(_property_table);        writers.add(sbtw);        writers.add(sbtw.getSBAT());        writers.add(bat);        for (int j = 0; j < xbat_blocks.length; j++)        {            writers.add(xbat_blocks[ j ]);        }        // now, write everything out        iter = writers.iterator();        while (iter.hasNext())        {            BlockWritable writer = ( BlockWritable ) iter.next();            writer.writeBlocks(stream);        }    }    /**     * read in a file and write it back out again     *     * @param args names of the files; arg[ 0 ] is the input file,     *             arg[ 1 ] is the output file     *     * @exception IOException     */    public static void main(String args[])        throws IOException    {        if (args.length != 2)        {            System.err.println(                "two arguments required: input filename and output filename");            System.exit(1);        }        FileInputStream  istream = new FileInputStream(args[ 0 ]);        FileOutputStream ostream = new FileOutputStream(args[ 1 ]);        new POIFSFileSystem(istream).writeFilesystem(ostream);        istream.close();        ostream.close();    }    /**     * get the root entry     *     * @return the root entry     */    public DirectoryEntry getRoot()    {        if (_root == null)        {            _root = new DirectoryNode(_property_table.getRoot(), this, null);        }        return _root;    }    /**     * open a document in the root entry's list of entries     *     * @param documentName the name of the document to be opened     *     * @return a newly opened DocumentInputStream     *     * @exception IOException if the document does not exist or the     *            name is that of a DirectoryEntry     */    public DocumentInputStream createDocumentInputStream(            final String documentName)        throws IOException    {        Entry document = getRoot().getEntry(documentName);        if (!document.isDocumentEntry())        {            throw new IOException("Entry '" + documentName                                  + "' is not a DocumentEntry");        }        return new DocumentInputStream(( DocumentEntry ) document);    }    /**     * add a new POIFSDocument     *     * @param document the POIFSDocument being added     */    void addDocument(final POIFSDocument document)    {        _documents.add(document);        _property_table.addProperty(document.getDocumentProperty());    }    /**     * add a new DirectoryProperty     *     * @param directory the DirectoryProperty being added     */    void addDirectory(final DirectoryProperty directory)    {        _property_table.addProperty(directory);    }    /**     * remove an entry     *     * @param entry to be removed     */    void remove(EntryNode entry)    {        _property_table.removeProperty(entry.getProperty());        if (entry.isDocumentEntry())        {            _documents.remove((( DocumentNode ) entry).getDocument());        }    }    private void processProperties(final BlockList small_blocks,                                   final BlockList big_blocks,                                   final Iterator properties,                                   final DirectoryNode dir)        throws IOException    {        while (properties.hasNext())        {            Property      property = ( Property ) properties.next();            String        name     = property.getName();            DirectoryNode parent   = (dir == null)                                     ? (( DirectoryNode ) getRoot())                                     : dir;            if (property.isDirectory())            {                DirectoryNode new_dir =                    ( DirectoryNode ) parent.createDirectory(name);                new_dir.setStorageClsid( property.getStorageClsid() );                processProperties(                    small_blocks, big_blocks,                    (( DirectoryProperty ) property).getChildren(), new_dir);            }            else            {                int           startBlock = property.getStartBlock();                int           size       = property.getSize();                POIFSDocument document   = null;                if (property.shouldUseSmallBlocks())                {                    document =                        new POIFSDocument(name, small_blocks                            .fetchBlocks(startBlock), size);                }                else                {                    document =                        new POIFSDocument(name,                                          big_blocks.fetchBlocks(startBlock),                                          size);                }                parent.createDocument(document);            }        }    }    /* ********** 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()    {        if (preferArray())        {            return (( POIFSViewable ) getRoot()).getViewableArray();        }        else        {            return new Object[ 0 ];        }    }    /**     * 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()    {        if (!preferArray())        {            return (( POIFSViewable ) getRoot()).getViewableIterator();        }        else        {            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 (( POIFSViewable ) getRoot()).preferArray();    }    /**     * 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()    {        return "POIFS FileSystem";    }    /* **********  END  begin implementation of POIFSViewable ********** */}   // end public class POIFSFileSystem

⌨️ 快捷键说明

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