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 main(String[] args) throws Exception { for (int i = 0; i < args.length; i++) { System.out.println("Dumping " + args[i]); FileInputStream is = new FileInputStream(args[i]); POIFSFileSystem fs = new POIFSFileSystem(is); is.close(); DirectoryEntry root = fs.getRoot(); File file = new File(root.getName()); file.mkdir(); dump(root, file); } }
public static void main(String[] args) throws Exception { for (int i = 0; i < args.length; i++) { System.out.println("Dumping " + args[i]); FileInputStream is = new FileInputStream(args[i]); POIFSFileSystem fs = new POIFSFileSystem(is); is.close(); DirectoryEntry root = fs.getRoot(); File file = new File(root.getName()); file.mkdir(); dump(root, file); } }
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); } } } }