List of usage examples for org.apache.poi.poifs.filesystem DocumentNode getSize
public int getSize()
From source file:org.docx4j.openpackaging.parts.WordprocessingML.OleObjectBinaryPart.java
License:Apache License
/** * Adapted from org.apache.poi.poifs.dev.POIFSLister * @param dir//from w w w. ja v a 2 s.co m * @param indent * @param withSizes * @throws IOException * */ private void displayDirectory(DirectoryNode dir, OutputStream os, String indent, boolean withSizes) throws IOException { 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, os, 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()) + "]"; } os.write((newIndent + name + size + "\n").getBytes()); } } if (!hadChildren) { os.write((newIndent + "(no children)").getBytes()); } }
From source file:org.opf_labs.aqua.OfficeAnalyser.java
License:Apache License
public static void dump(DirectoryEntry root) throws IOException { System.out.println(root.getName() + " : storage CLSID " + root.getStorageClsid()); for (Iterator it = root.getEntries(); it.hasNext();) { Entry entry = (Entry) it.next(); if (entry instanceof DocumentNode) { DocumentNode node = (DocumentNode) entry; System.out.println("Node name: " + node.getName()); System.out.println("Node desc: " + node.getShortDescription()); System.out.println("Node size: " + node.getSize()); DocumentInputStream is = new DocumentInputStream(node); try { PropertySet ps = new PropertySet(is); if (ps.getSectionCount() != 0) { for (Property p : ps.getProperties()) { System.out.println("Prop: " + p.getID() + " " + p.getValue()); }/*ww w . ja v a2 s . co m*/ } } catch (NoPropertySetStreamException e) { // TODO Auto-generated catch block //e.printStackTrace(); } catch (MarkUnsupportedException e) { // TODO Auto-generated catch block //e.printStackTrace(); } //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(); //System.out.println("Node: "+new String(bytes).substring(0, 10)); } else if (entry instanceof DirectoryEntry) { DirectoryEntry dir = (DirectoryEntry) entry; dump(dir); } else { System.err.println("Skipping unsupported POIFS entry: " + entry); } } }
From source file:uk.bl.wa.tika.parser.ole2.OLE2Parser.java
License:Open Source License
public static void dump(DirectoryEntry root) throws IOException { System.out.println(root.getName() + " : storage CLSID " + root.getStorageClsid()); for (Iterator it = root.getEntries(); it.hasNext();) { Entry entry = (Entry) it.next(); if (entry instanceof DocumentNode) { DocumentNode node = (DocumentNode) entry; System.out.println("Node name: " + node.getName()); System.out.println("Node desc: " + node.getShortDescription()); System.out.println("Node size: " + node.getSize()); DocumentInputStream is = new DocumentInputStream(node); try { PropertySet ps = new PropertySet(is); if (ps.getSectionCount() != 0) { for (Property p : ps.getProperties()) { System.out.println("Prop: " + p.getID() + " " + p.getValue()); }/* w ww . j a v a 2 s .c o m*/ } } catch (NoPropertySetStreamException e) { // TODO Auto-generated catch block //e.printStackTrace(); } //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(); //System.out.println("Node: "+new String(bytes).substring(0, 10)); } else if (entry instanceof DirectoryEntry) { DirectoryEntry dir = (DirectoryEntry) entry; dump(dir); } else { System.err.println("Skipping unsupported POIFS entry: " + entry); } } }