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)"); } } }
/** * create a new DocumentEntry * * @param document the new document * * @return the new DocumentEntry * * @exception IOException if the document can't be created */ DocumentEntry createDocument(final POIFSDocument document) throws IOException { DocumentProperty property = document.getDocumentProperty(); DocumentNode rval = new DocumentNode(property, this); (( DirectoryProperty ) getProperty()).addChild(property); _nfilesystem.addDocument(document); _entries.add(rval); _byname.put(property.getName(), rval); return rval; }
/** * Constructor for an existing Document */ public POIFSDocument(DocumentNode document) { this((DocumentProperty)document.getProperty(), ((DirectoryNode)document.getParent()).getNFileSystem()); }
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);
/** * 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(); }
/** * Get an Iterator of objects, some of which may implement * POIFSViewable * * @return an Iterator; may not be null, but may have an empty * back end store */ public Iterator<Object> getViewableIterator() { List<Object> components = new ArrayList<>(); components.add(getProperty()); if (_document != null) { components.add(_document); } return components.iterator(); }
/** * Create an InputStream from the specified DocumentEntry * * @param document the DocumentEntry to be read * * @exception IOException if the DocumentEntry cannot be opened (like, maybe it has * been deleted?) */ public ODocumentInputStream(DocumentEntry document) throws IOException { if (!(document instanceof DocumentNode)) { throw new IOException("Cannot open internal document storage"); } DocumentNode documentNode = (DocumentNode)document; if(documentNode.getDocument() == null) { throw new IOException("Cannot open internal document storage"); } _current_offset = 0; _marked_offset = 0; _document_size = document.getSize(); _closed = false; _document = documentNode.getDocument(); _currentBlock = getDataInputBlock(0); }
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);
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 {
/** * get the zize of the document, in bytes * * @return size in bytes */ public int getSize() { return getProperty().getSize(); }
/** * Create an InputStream from the specified DocumentEntry * * @param document the DocumentEntry to be read * * @exception IOException if the DocumentEntry cannot be opened (like, maybe it has * been deleted?) */ public ODocumentInputStream(DocumentEntry document) throws IOException { if (!(document instanceof DocumentNode)) { throw new IOException("Cannot open internal document storage"); } DocumentNode documentNode = (DocumentNode)document; if(documentNode.getDocument() == null) { throw new IOException("Cannot open internal document storage"); } _current_offset = 0; _marked_offset = 0; _document_size = document.getSize(); _closed = false; _document = documentNode.getDocument(); _currentBlock = getDataInputBlock(0); }
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)"); } } }
/** * Create an InputStream from the specified DocumentEntry * * @param document the DocumentEntry to be read * * @exception IOException if the DocumentEntry cannot be opened (like, maybe it has * been deleted?) */ public DocumentInputStream(DocumentEntry document) throws IOException { if (!(document instanceof DocumentNode)) { throw new IOException("Cannot open internal document storage, " + document + " not a Document Node"); } _current_offset = 0; _current_block_count = 0; _marked_offset = 0; _marked_offset_count = 0; _document_size = document.getSize(); _closed = false; // can't be asserted ... see bug 61300 // assert (_document_size >= 0) : "Document size can't be < 0"; DocumentNode doc = (DocumentNode)document; DocumentProperty property = (DocumentProperty)doc.getProperty(); _document = new POIFSDocument( property, ((DirectoryNode)doc.getParent()).getNFileSystem() ); _data = _document.getBlockIterator(); }
childNode = new DocumentNode((DocumentProperty) child, this);
/** * 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(); }
/** * Get an Iterator of objects, some of which may implement * POIFSViewable * * @return an Iterator; may not be null, but may have an empty * back end store */ public Iterator getViewableIterator() { List components = new ArrayList(); components.add(getProperty()); components.add(_document); return components.iterator(); }
/** * remove an entry * * @param entry to be removed */ void remove(EntryNode entry) { _property_table.removeProperty(entry.getProperty()); if (entry.isDocumentEntry()) { _documents.remove((( DocumentNode ) entry).getDocument()); } }
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)"); } } }