private static POIDelegate toDelegate(Entry entry) { return (entry.isDirectoryEntry()) ? new DirectoryDelegate((DirectoryEntry)entry) : new DocumentDelegate((DocumentEntry)entry); }
/** * Copies all nodes from one POIFS to the other * * @param source * is the source POIFS to copy from * @param target * is the target POIFS to copy to */ public static void copyNodes(POIFSFileSystem source, POIFSFileSystem target ) throws IOException { copyNodes( source.getRoot(), target.getRoot() ); }
/** * Constructor for an existing Document */ public POIFSDocument(DocumentNode document) { this((DocumentProperty)document.getProperty(), ((DirectoryNode)document.getParent()).getNFileSystem()); }
/** * 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 { return getRoot().createDocumentInputStream(documentName); }
/** * Creates an instance of this class from an embedded OLE Object. The OLE Object is expected * to include a stream "{01}Ole10Native" which contains the actual * data relevant for this class. * * @param poifs POI Filesystem object * @return Returns an instance of this class * @throws IOException on IO error * @throws Ole10NativeException on invalid or unexcepted data format */ public static Ole10Native createFromEmbeddedOleObject(POIFSFileSystem poifs) throws IOException, Ole10NativeException { return createFromEmbeddedOleObject(poifs.getRoot()); }
/** * 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 getRoot().getViewableArray(); } return new Object[ 0 ]; }
/** * Add the \1OLE marker entry, which is not the Ole10Native entry. * Beside this "\u0001Ole" record there were several other records, e.g. CompObj, * OlePresXXX, but it seems, that they aren't necessary */ public static void createOleMarkerEntry(final POIFSFileSystem poifs) throws IOException { createOleMarkerEntry(poifs.getRoot()); }
/** * 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 getRoot().preferArray(); }
/** * Opens for decryption */ public EncryptionInfo(POIFSFileSystem fs) throws IOException { this(fs.getRoot()); }
private FilteringIterator() { parent = directory.getEntries(); locateNext(); } private void locateNext() {
private void free(ChainLoopDetector loopDetector) { int nextBlock = startBlock; while(nextBlock != POIFSConstants.END_OF_CHAIN) { int thisBlock = nextBlock; loopDetector.claim(thisBlock); nextBlock = blockStore.getNextBlock(thisBlock); blockStore.setNextBlock(thisBlock, POIFSConstants.UNUSED_BLOCK); } this.startBlock = POIFSConstants.END_OF_CHAIN; }
/** * Frees all blocks in the stream */ public void free() throws IOException { ChainLoopDetector loopDetector = blockStore.getChainLoopDetector(); free(loopDetector); } private void free(ChainLoopDetector loopDetector) {
public void close() throws IOException { // If we're overwriting, free any remaining blocks POIFSStream toFree = new POIFSStream(blockStore, nextBlock); toFree.free(loopDetector); // Mark the end of the stream, if we have any data if (prevBlock != POIFSConstants.END_OF_CHAIN) { blockStore.setNextBlock(prevBlock, POIFSConstants.END_OF_CHAIN); } } }
DocumentOutputStream(POIFSDocument document, long limit) throws IOException { _document = document; _document.free(); _property = document.getDocumentProperty(); _limit = limit; }
/** * 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 getName(); }
public Entry next() { Entry e = next; locateNext(); return e; }
protected ChainLoopDetector(long rawSize) { int blkSize = getBlockStoreBlockSize(); int numBlocks = (int)(rawSize / blkSize); if ((rawSize % blkSize) != 0) { numBlocks++; } used_blocks = new boolean[numBlocks]; } protected void claim(int offset) {
/** * Checks to see if the two Directories hold the same contents. * For this to be true, they must have entries with the same names, * no entries in one but not the other, and the size+contents * of each entry must match, and they must share names. * To exclude certain parts of the Directory from being checked, * use a {@link FilteringDirectoryNode} */ public static boolean areDirectoriesIdentical(DirectoryEntry dirA, DirectoryEntry dirB) { return new DirectoryDelegate(dirA).equals(new DirectoryDelegate(dirB)); }
@Override public void write(int b) throws IOException { oneByte[0] = (byte)(b & 0xFF); write(oneByte); }
/** * Returns an iterator that'll supply one {@link ByteBuffer} * per block in the stream. */ public Iterator<ByteBuffer> iterator() { return getBlockIterator(); }