private FilteringIterator() { parent = directory.getEntries(); locateNext(); } private void locateNext() {
public static void dump(DirectoryEntry root, File parent) throws IOException { for(Iterator<Entry> it = root.getEntries(); it.hasNext();){ Entry entry = it.next(); if(entry instanceof DocumentNode){ DocumentNode node = (DocumentNode)entry; DocumentInputStream is = new DocumentInputStream(node); byte[] bytes = IOUtils.toByteArray(is); is.close(); try (OutputStream out = new FileOutputStream(new File(parent, node.getName().trim()))) { out.write(bytes); } } else if (entry instanceof DirectoryEntry){ DirectoryEntry dir = (DirectoryEntry)entry; File file = new File(parent, entry.getName()); if(!file.exists() && !file.mkdirs()) { throw new IOException("Could not create directory " + file); } dump(dir, file); } else { System.err.println("Skipping unsupported POIFS entry: " + entry); } } } public static void dump(POIFSFileSystem fs, int startBlock, String name, File parent) throws IOException {
Iterator<Entry> it = root.getEntries(); while(it.hasNext()) { Entry entry = it.next();
Iterator<Entry> it = root.getEntries(); while (it.hasNext()) { Entry entry = it.next();
/** * Copies an Entry into a target POIFS directory, recursively */ @Internal public static void copyNodeRecursively( Entry entry, DirectoryEntry target ) throws IOException { if ( entry.isDirectoryEntry() ) { DirectoryEntry dirEntry = (DirectoryEntry)entry; DirectoryEntry newTarget = target.createDirectory( entry.getName() ); newTarget.setStorageClsid( dirEntry.getStorageClsid() ); Iterator<Entry> entries = dirEntry.getEntries(); while ( entries.hasNext() ) { copyNodeRecursively( entries.next(), newTarget ); } } else { DocumentEntry dentry = (DocumentEntry) entry; DocumentInputStream dstream = new DocumentInputStream( dentry ); target.createDocument( dentry.getName(), dstream ); dstream.close(); } }
/** * Retrieves child nodes from a directory entry. * * @param parent parent directory entry * @return list of child nodes */ private List<Entry> getChildNodes(DirectoryEntry parent) { List<Entry> result = new ArrayList<Entry>(); Iterator<Entry> entries = parent.getEntries(); while (entries.hasNext()) { result.add(entries.next()); } return result; }
private FilteringIterator() { parent = directory.getEntries(); locateNext(); } private void locateNext() {
/** * Retrieves child nodes from a directory entry. * * @param parent parent directory entry * @return list of child nodes */ private List<Entry> getChildNodes(DirectoryEntry parent) { List<Entry> result = new ArrayList<Entry>(); Iterator<Entry> entries = parent.getEntries(); while (entries.hasNext()) { result.add(entries.next()); } return result; }
private FilteringIterator() { parent = directory.getEntries(); locateNext(); } private void locateNext() {
private FilteringIterator() { parent = directory.getEntries(); locateNext(); } private void locateNext() {
private String dumpFileSystem( DirectoryEntry directory ) { StringBuilder result = new StringBuilder(); result.append( "+ " ); result.append( directory.getName() ); for ( Iterator<Entry> iterator = directory.getEntries(); iterator .hasNext(); ) { Entry entry = iterator.next(); String entryToString = "\n" + dumpFileSystem( entry ); entryToString = entryToString.replaceAll( "\n", "\n+---" ); result.append( entryToString ); } result.append( "\n" ); return result.toString(); }
private String dumpFileSystem( DirectoryEntry directory ) { StringBuilder result = new StringBuilder(); result.append( "+ " ); result.append( directory.getName() ); for ( Iterator<Entry> iterator = directory.getEntries(); iterator .hasNext(); ) { Entry entry = iterator.next(); String entryToString = "\n" + dumpFileSystem( entry ); entryToString = entryToString.replaceAll( "\n", "\n+---" ); result.append( entryToString ); } result.append( "\n" ); return result.toString(); }
/** * Copies nodes from one Directory to the other minus the excepts * * @param sourceRoot * is the source Directory to copy from * @param targetRoot * is the target Directory to copy to * @param excepts * is a list of Strings specifying what nodes NOT to copy * @deprecated use {@link FilteringDirectoryNode} instead */ public static void copyNodes( DirectoryEntry sourceRoot, DirectoryEntry targetRoot, List<String> excepts ) throws IOException { Iterator<Entry> entries = sourceRoot.getEntries(); while ( entries.hasNext() ) { Entry entry = entries.next(); if ( !excepts.contains( entry.getName() ) ) { copyNodeRecursively( entry, targetRoot ); } } }
/** * Copies nodes from one Directory to the other minus the excepts * * @param sourceRoot * is the source Directory to copy from * @param targetRoot * is the target Directory to copy to * @param excepts * is a list of Strings specifying what nodes NOT to copy * @deprecated use {@link FilteringDirectoryNode} instead */ public static void copyNodes( DirectoryEntry sourceRoot, DirectoryEntry targetRoot, List<String> excepts ) throws IOException { Iterator<Entry> entries = sourceRoot.getEntries(); while ( entries.hasNext() ) { Entry entry = entries.next(); if ( !excepts.contains( entry.getName() ) ) { copyNodeRecursively( entry, targetRoot ); } } }
public static void dump(DirectoryEntry root, File parent) throws IOException { for(Iterator<Entry> it = root.getEntries(); it.hasNext();){ Entry entry = it.next(); if(entry instanceof DocumentNode){ DocumentNode node = (DocumentNode)entry; DocumentInputStream is = new DocumentInputStream(node); byte[] bytes = IOUtils.toByteArray(is); is.close(); try (OutputStream out = new FileOutputStream(new File(parent, node.getName().trim()))) { out.write(bytes); } } else if (entry instanceof DirectoryEntry){ DirectoryEntry dir = (DirectoryEntry)entry; File file = new File(parent, entry.getName()); if(!file.exists() && !file.mkdirs()) { throw new IOException("Could not create directory " + file); } dump(dir, file); } else { System.err.println("Skipping unsupported POIFS entry: " + entry); } } } public static void dump(POIFSFileSystem fs, int startBlock, String name, File parent) throws IOException {
public static void dump(DirectoryEntry root, File parent) throws IOException { for(Iterator it = root.getEntries(); it.hasNext();){ Entry entry = (Entry)it.next(); if(entry instanceof DocumentNode){ DocumentNode node = (DocumentNode)entry; DocumentInputStream is = new DocumentInputStream(node); byte[] bytes = new byte[node.getSize()]; is.read(bytes); is.close(); FileOutputStream out = new FileOutputStream(new File(parent, node.getName().trim())); out.write(bytes); out.close(); } else if (entry instanceof DirectoryEntry){ DirectoryEntry dir = (DirectoryEntry)entry; File file = new File(parent, entry.getName()); file.mkdir(); dump(dir, file); } else { System.err.println("Skipping unsupported POIFS entry: " + entry); } } } }
public static void dump(DirectoryEntry root, File parent) throws IOException { for(Iterator it = root.getEntries(); it.hasNext();){ Entry entry = (Entry)it.next(); if(entry instanceof DocumentNode){ DocumentNode node = (DocumentNode)entry; DocumentInputStream is = new DocumentInputStream(node); byte[] bytes = new byte[node.getSize()]; is.read(bytes); is.close(); FileOutputStream out = new FileOutputStream(new File(parent, node.getName().trim())); out.write(bytes); out.close(); } else if (entry instanceof DirectoryEntry){ DirectoryEntry dir = (DirectoryEntry)entry; File file = new File(parent, entry.getName()); file.mkdir(); dump(dir, file); } else { System.err.println("Skipping unsupported POIFS entry: " + entry); } } } }
protected void sanitize(BleachSession session, DirectoryEntry rootIn, DirectoryEntry rootOut) { LOGGER.debug("Entries before: {}", rootIn.getEntryNames()); // Save the changes to a new file // Returns false if the entry should be removed Predicate<Entry> visitor = ((Predicate<Entry>) (e -> true)) .and(new MacroRemover(session)) .and(new ObjectRemover(session)) .and(new SummaryInformationSanitiser(session)); LOGGER.debug("Root ClassID: {}", rootIn.getStorageClsid()); // https://blogs.msdn.microsoft.com/heaths/2006/02/27/identifying-windows-installer-file-types/ rootOut.setStorageClsid(rootIn.getStorageClsid()); rootIn .getEntries() .forEachRemaining( entry -> { if (!visitor.test(entry)) { return; } copyNodesRecursively(session, entry, rootOut); }); LOGGER.debug("Entries after: {}", rootOut.getEntryNames()); // Save the changes to a new file }
/** * Copies an Entry into a target POIFS directory, recursively */ @Internal public static void copyNodeRecursively( Entry entry, DirectoryEntry target ) throws IOException { // logger.log( POILogger.ERROR, "copyNodeRecursively called with "+entry.getName()+ // ","+target.getName()); DirectoryEntry newTarget = null; if ( entry.isDirectoryEntry() ) { newTarget = target.createDirectory( entry.getName() ); Iterator<Entry> entries = ( (DirectoryEntry) entry ).getEntries(); while ( entries.hasNext() ) { copyNodeRecursively( entries.next(), newTarget ); } } else { DocumentEntry dentry = (DocumentEntry) entry; DocumentInputStream dstream = new DocumentInputStream( dentry ); target.createDocument( dentry.getName(), dstream ); dstream.close(); } }
/** * Copies an Entry into a target POIFS directory, recursively */ @Internal public static void copyNodeRecursively( Entry entry, DirectoryEntry target ) throws IOException { if ( entry.isDirectoryEntry() ) { DirectoryEntry dirEntry = (DirectoryEntry)entry; DirectoryEntry newTarget = target.createDirectory( entry.getName() ); newTarget.setStorageClsid( dirEntry.getStorageClsid() ); Iterator<Entry> entries = dirEntry.getEntries(); while ( entries.hasNext() ) { copyNodeRecursively( entries.next(), newTarget ); } } else { DocumentEntry dentry = (DocumentEntry) entry; DocumentInputStream dstream = new DocumentInputStream( dentry ); target.createDocument( dentry.getName(), dstream ); dstream.close(); } }