public DocumentEntry createDocument(String name, InputStream stream) throws IOException { return directory.createDocument(name, stream); }
public DocumentEntry createDocument(String name, int size, POIFSWriterListener writer) throws IOException { return directory.createDocument(name, size, writer); }
private static DocumentEntry createDocument(DirectoryEntry parent, String name) throws IOException { if (!(parent instanceof DirectoryNode)) { throw new IOException("Cannot open internal directory storage, " + parent + " not a Directory Node"); } // Have an empty one created for now return parent.createDocument(name, new ByteArrayInputStream(new byte[0])); }
/** * Add the \1OLE marker entry, which is not the Ole10Native entry. * Beside this "\u0001Ole" record there were several other records, e.g. CompObj, * OlePresXXX, but it seems, that they aren't necessary */ public static void createOleMarkerEntry(final DirectoryEntry parent) throws IOException { if (!parent.hasEntry(OLE_MARKER_NAME)) { parent.createDocument(OLE_MARKER_NAME, new ByteArrayInputStream(OLE_MARKER_BYTES)); } }
/** * Writes a property set to a document in a POI filesystem directory. * * @param dir The directory in the POI filesystem to write the document to. * @param name The document's name. If there is already a document with the * same name in the directory the latter will be overwritten. * * @throws WritingNotSupportedException if the filesystem doesn't support writing * @throws IOException if the old entry can't be deleted or the new entry be written */ public void write(final DirectoryEntry dir, final String name) throws WritingNotSupportedException, IOException { /* If there is already an entry with the same name, remove it. */ if (dir.hasEntry(name)) { final Entry e = dir.getEntry(name); e.delete(); } /* Create the new entry. */ dir.createDocument(name, toInputStream()); }
@Override public int addOlePackage(byte[] oleData, String label, String fileName, String command) throws IOException { // check if we were created by POIFS otherwise create a new dummy POIFS for storing the package data if (initDirectory()) { preserveNodes = true; } // get free MBD-Node int storageId = 0; DirectoryEntry oleDir = null; do { String storageStr = "MBD"+ HexDump.toHex(++storageId); if (!getDirectory().hasEntry(storageStr)) { oleDir = getDirectory().createDirectory(storageStr); oleDir.setStorageClsid(ClassIDPredefined.OLE_V1_PACKAGE.getClassID()); } } while (oleDir == null); Ole10Native.createOleMarkerEntry(oleDir); Ole10Native oleNative = new Ole10Native(label, fileName, command, oleData); ByteArrayOutputStream bos = new ByteArrayOutputStream(); oleNative.writeOut(bos); oleDir.createDocument(Ole10Native.OLE10_NATIVE, new ByteArrayInputStream(bos.toByteArray())); return storageId; }
/** * 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(); } }
public static DocumentEntry createEncryptionEntry(DirectoryEntry dir, String path, EncryptionRecord out) throws IOException { String parts[] = path.split("/"); for (int i=0; i<parts.length-1; i++) { dir = dir.hasEntry(parts[i]) ? (DirectoryEntry)dir.getEntry(parts[i]) : dir.createDirectory(parts[i]); } final byte buf[] = new byte[5000]; LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(buf, 0); out.write(bos); String fileName = parts[parts.length-1]; if (dir.hasEntry(fileName)) { dir.getEntry(fileName).delete(); } return dir.createDocument(fileName, bos.getWriteIndex(), new POIFSWriterListener(){ public void processPOIFSWriterEvent(POIFSWriterEvent event) { try { event.getStream().write(buf, 0, event.getLimit()); } catch (IOException e) { throw new EncryptedDocumentException(e); } } }); }
protected void copy(DirectoryEntry sourceDir, DirectoryEntry destDir) throws IOException { for (Entry entry : sourceDir) { if (entry instanceof DirectoryEntry) { // Need to recurse DirectoryEntry newDir = destDir.createDirectory(entry.getName()); copy((DirectoryEntry) entry, newDir); } else { // Copy entry try (InputStream contents = new DocumentInputStream((DocumentEntry) entry)) { destDir.createDocument(entry.getName(), contents); } } } } }
protected void copy(DirectoryEntry sourceDir, DirectoryEntry destDir) throws IOException { for (org.apache.poi.poifs.filesystem.Entry entry : sourceDir) { if (entry instanceof DirectoryEntry) { // Need to recurse DirectoryEntry newDir = destDir.createDirectory(entry.getName()); copy((DirectoryEntry) entry, newDir); } else { // Copy entry try (InputStream contents = new DocumentInputStream((DocumentEntry) entry)) { destDir.createDocument(entry.getName(), contents); } } } } }
public DocumentEntry createDocument(String name, int size, POIFSWriterListener writer) throws IOException { return directory.createDocument(name, size, writer); }
public DocumentEntry createDocument(String name, int size, POIFSWriterListener writer) throws IOException { return directory.createDocument(name, size, writer); }
public DocumentEntry createDocument(String name, InputStream stream) throws IOException { return directory.createDocument(name, stream); }
public DocumentEntry createDocument(String name, InputStream stream) throws IOException { return directory.createDocument(name, stream); }
public DocumentEntry createDocument(String name, InputStream stream) throws IOException { return directory.createDocument(name, stream); }
public DocumentEntry createDocument(String name, int size, POIFSWriterListener writer) throws IOException { return directory.createDocument(name, size, writer); }
private static DocumentEntry createDocument(DirectoryEntry parent, String name) throws IOException { if (!(parent instanceof DirectoryNode)) { throw new IOException("Cannot open internal directory storage, " + parent + " not a Directory Node"); } // Have an empty one created for now return parent.createDocument(name, new ByteArrayInputStream(new byte[0])); }
/** * Add the \1OLE marker entry, which is not the Ole10Native entry. * Beside this "\u0001Ole" record there were several other records, e.g. CompObj, * OlePresXXX, but it seems, that they aren't necessary */ public static void createOleMarkerEntry(final DirectoryEntry parent) throws IOException { if (!parent.hasEntry(OLE_MARKER_NAME)) { parent.createDocument(OLE_MARKER_NAME, new ByteArrayInputStream(OLE_MARKER_BYTES)); } }
private void saveEntries(final DirectoryEntry source, final DirectoryEntry destination) throws IOException { for (Entry entry : source) { // Recursively save sub-entries. if (entry instanceof DirectoryEntry) { saveEntries((DirectoryEntry) entry, destination.createDirectory(entry.getName())); continue; } // Copy the entry. try (final InputStream contents = new DocumentInputStream((DocumentEntry) entry)) { destination.createDocument(entry.getName(), contents); } catch (IOException e) { logger.error("Unable to save embedded document \"{}\" in document: \"{}\".", entry.getName(), parent, e); } } } }
private void saveEntries(final DirectoryEntry source, final DirectoryEntry destination) throws IOException { for (Entry entry : source) { // Recursively save sub-entries or copy the entry. if (entry instanceof DirectoryEntry) { saveEntries((DirectoryEntry) entry, destination.createDirectory(entry.getName())); } else { try (final InputStream contents = new DocumentInputStream((DocumentEntry) entry)) { destination.createDocument(entry.getName(), contents); } } } } }