Search in sources :

Example 1 with FilteringDirectoryNode

use of org.apache.poi.poifs.filesystem.FilteringDirectoryNode in project poi by apache.

the class HPSFPropertiesOnlyDocument method write.

private void write(NPOIFSFileSystem fs) throws IOException {
    // For tracking what we've written out, so far
    List<String> excepts = new ArrayList<String>(2);
    // Write out our HPFS properties, with any changes
    writeProperties(fs, excepts);
    // Copy over everything else unchanged
    FilteringDirectoryNode src = new FilteringDirectoryNode(getDirectory(), excepts);
    FilteringDirectoryNode dest = new FilteringDirectoryNode(fs.getRoot(), excepts);
    EntryUtils.copyNodes(src, dest);
// Caller will save the resultant POIFSFileSystem to the stream/file
}
Also used : ArrayList(java.util.ArrayList) FilteringDirectoryNode(org.apache.poi.poifs.filesystem.FilteringDirectoryNode)

Example 2 with FilteringDirectoryNode

use of org.apache.poi.poifs.filesystem.FilteringDirectoryNode in project poi by apache.

the class HSSFWorkbook method write.

/** Writes the workbook out to a brand new, empty POIFS */
private void write(NPOIFSFileSystem fs) throws IOException {
    // For tracking what we've written out, used if we're
    //  going to be preserving nodes
    List<String> excepts = new ArrayList<String>(1);
    // Write out the Workbook stream
    fs.createDocument(new ByteArrayInputStream(getBytes()), "Workbook");
    // Write out our HPFS properties, if we have them
    writeProperties(fs, excepts);
    if (preserveNodes) {
        // Don't write out the old Workbook, we'll be doing our new one
        // If the file had an "incorrect" name for the workbook stream,
        // don't write the old one as we'll use the correct name shortly
        excepts.addAll(Arrays.asList(WORKBOOK_DIR_ENTRY_NAMES));
        // Copy over all the other nodes to our new poifs
        EntryUtils.copyNodes(new FilteringDirectoryNode(getDirectory(), excepts), new FilteringDirectoryNode(fs.getRoot(), excepts));
        // YK: preserve StorageClsid, it is important for embedded workbooks,
        // see Bugzilla 47920
        fs.getRoot().setStorageClsid(getDirectory().getStorageClsid());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) LittleEndianByteArrayInputStream(org.apache.poi.util.LittleEndianByteArrayInputStream) ArrayList(java.util.ArrayList) UnicodeString(org.apache.poi.hssf.record.common.UnicodeString) FilteringDirectoryNode(org.apache.poi.poifs.filesystem.FilteringDirectoryNode)

Aggregations

ArrayList (java.util.ArrayList)2 FilteringDirectoryNode (org.apache.poi.poifs.filesystem.FilteringDirectoryNode)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 UnicodeString (org.apache.poi.hssf.record.common.UnicodeString)1 LittleEndianByteArrayInputStream (org.apache.poi.util.LittleEndianByteArrayInputStream)1