/** * Display the contents of multiple POIFS files * * @param args the names of the files to be displayed */ public static void main(final String args[]) { if (args.length == 0) { System.err.println("Must specify at least one file to view"); System.exit(1); } boolean printNames = (args.length > 1); for (String arg : args) { viewFile(arg, printNames); } }
objects.add(indent(indentLevel, indentString, inspected.getShortDescription())); if (drilldown) if (inspected.preferArray()) Object[] data = inspected.getViewableArray(); objects.addAll(inspectViewable(data[ j ], drilldown, indentLevel + 1, indentString)); Iterator<Object> iter = inspected.getViewableIterator(); objects.addAll(inspectViewable(iter.next(), drilldown, indentLevel + 1, objects.add(indent(indentLevel, indentString, viewable.toString()));
/** * Display the entries of multiple POIFS files * * @param args the names of the files to be displayed */ public static void main(final String args[]) throws IOException { if (args.length == 0) { System.err.println("Must specify at least one file to view"); System.exit(1); } boolean withSizes = false; boolean newPOIFS = true; for (String arg : args) { if (arg.equalsIgnoreCase("-size") || arg.equalsIgnoreCase("-sizes")) { withSizes = true; } else if (arg.equalsIgnoreCase("-old") || arg.equalsIgnoreCase("-old-poifs")) { newPOIFS = false; } else { if (newPOIFS) { viewFile(arg, withSizes); } else { viewFileOld(arg, withSizes); } } } }
public static void viewFileOld(final String filename, boolean withSizes) throws IOException { POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename)); displayDirectory(fs.getRoot(), "", withSizes); fs.close(); }
/** * 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(); }
/** * 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(); } return new Object[ 0 ]; }
private static void viewFile(String filename, boolean printName) { if (printName) { StringBuffer flowerbox = new StringBuffer(); flowerbox.append("."); for (int j = 0; j < filename.length(); j++) { flowerbox.append("-"); } flowerbox.append("."); System.out.println(flowerbox); System.out.println("|" + filename + "|"); System.out.println(flowerbox); } try { POIFSFileSystem fs = new POIFSFileSystem(new File(filename)); List<String> strings = POIFSViewEngine.inspectViewable(fs, true, 0, " "); for (String s : strings) { System.out.print(s); } fs.close(); } catch (IOException e) { System.out.println(e.getMessage()); } } }
public static void viewFile(final String filename, boolean withSizes) throws IOException { POIFSFileSystem fs = new POIFSFileSystem(new File(filename)); displayDirectory(fs.getRoot(), "", withSizes); fs.close(); }
/** * 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(); }
/** * 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(); } return new Object[ 0 ]; }
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 displayDirectory(DirectoryNode dir, String indent, boolean withSizes) { System.out.println(indent + dir.getName() + " -"); String newIndent = indent + " "; boolean hadChildren = false; for(Iterator<Entry> it = dir.getEntries(); it.hasNext();) { hadChildren = true; Entry entry = it.next(); if (entry instanceof DirectoryNode) { displayDirectory((DirectoryNode) entry, newIndent, withSizes); } else { DocumentNode doc = (DocumentNode) entry; String name = doc.getName(); String size = ""; if (name.charAt(0) < 10) { String altname = "(0x0" + (int) name.charAt(0) + ")" + name.substring(1); name = name.substring(1) + " <" + altname + ">"; } if (withSizes) { size = " [" + doc.getSize() + " / 0x" + Integer.toHexString(doc.getSize()) + "]"; } System.out.println(newIndent + name + size); } } if (!hadChildren) { System.out.println(newIndent + "(no children)"); } } }
/** * 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(); }
/** * 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(); } return new Object[ 0 ]; }
public static void viewFileOld(final String filename, boolean withSizes) throws IOException { POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename)); displayDirectory(fs.getRoot(), "", withSizes); }
/** * 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(); }
/** * 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(); } return new Object[ 0 ]; }
public static void viewFile(final String filename, boolean withSizes) throws IOException { POIFSFileSystem fs = new POIFSFileSystem(new File(filename)); displayDirectory(fs.getRoot(), "", withSizes); fs.close(); }
public static void viewFileOld(final String filename, boolean withSizes) throws IOException { POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename)); displayDirectory(fs.getRoot(), "", withSizes); fs.close(); }