void writeToPOIFS() throws IOException { int oleStreamSize = (int)(fileOut.length()+LittleEndianConsts.LONG_SIZE); dir.createDocument(DEFAULT_POIFS_ENTRY, oleStreamSize, this); // TODO: any properties??? }
protected static void copyNodes(DirectoryNode src, DirectoryNode dest) throws IOException { for (Entry e : src) { if (e instanceof DirectoryNode) { DirectoryNode srcDir = (DirectoryNode)e; DirectoryNode destDir = (DirectoryNode)dest.createDirectory(srcDir.getName()); destDir.setStorageClsid(srcDir.getStorageClsid()); copyNodes(srcDir, destDir); } else { try (InputStream is = src.createDocumentInputStream(e)) { dest.createDocument(e.getName(), is); } } } }
bos.setSize(savedSize); dir.createDocument(encryptedStream, new ByteArrayInputStream(bos.getBuf(), 0, savedSize));
/** * create a new DocumentEntry in the root entry; the data will be * provided later * * @param name the name of the new DocumentEntry * @param size the size of the new DocumentEntry * @param writer the writer of the new DocumentEntry * * @return the new DocumentEntry * * @exception IOException if the writer exceeds the given size */ public DocumentEntry createDocument(final String name, final int size, final POIFSWriterListener writer) throws IOException { return getRoot().createDocument(name, size, writer); }
protected static void copyNodes(DirectoryNode src, DirectoryNode dest) throws IOException { for (Entry e : src) { if (e instanceof DirectoryNode) { DirectoryNode srcDir = (DirectoryNode)e; DirectoryNode destDir = (DirectoryNode)dest.createDirectory(srcDir.getName()); destDir.setStorageClsid(srcDir.getStorageClsid()); copyNodes(srcDir, destDir); } else { try (InputStream is = src.createDocumentInputStream(e)) { dest.createDocument(e.getName(), is); } } } }
/** * create a new DocumentEntry * * @param name the name of the new DocumentEntry * @param stream the InputStream from which to create the new * DocumentEntry * * @return the new DocumentEntry * * @exception IOException if the document can't be created */ public DocumentEntry createDocument(final String name, final InputStream stream) throws IOException { return createDocument(new POIFSDocument(name, _nfilesystem, stream)); }
/** * Create a new document to be added to the root directory * * @param stream the InputStream from which the document's data * will be obtained * @param name the name of the new POIFSDocument * * @return the new DocumentEntry * * @exception IOException on error creating the new POIFSDocument */ public DocumentEntry createDocument(final InputStream stream, final String name) throws IOException { return getRoot().createDocument(name, stream); }
/** * create a new DocumentEntry; the data will be provided later * * @param name the name of the new DocumentEntry * @param size the size of the new DocumentEntry * @param writer the writer of the new DocumentEntry * * @return the new DocumentEntry * * @exception IOException if the document can't be created */ public DocumentEntry createDocument(final String name, final int size, final POIFSWriterListener writer) throws IOException { return createDocument(new POIFSDocument(name, size, _nfilesystem, writer)); }
@Override public void close() throws IOException { if (isClosed) { LOG.log(POILogger.DEBUG, "ChunkedCipherOutputStream was already closed - ignoring"); return; } isClosed = true; try { writeChunk(false); super.close(); if (fileOut != null) { int oleStreamSize = (int)(fileOut.length()+LittleEndianConsts.LONG_SIZE); calculateChecksum(fileOut, (int)pos); dir.createDocument(DEFAULT_POIFS_ENTRY, oleStreamSize, new EncryptedPackageWriter()); createEncryptionInfoEntry(dir, fileOut); } } catch (GeneralSecurityException e) { throw new IOException(e); } }
/** * Set the contents of a document, creating if needed, * otherwise updating. Returns the created / updated DocumentEntry * * @param name the name of the new or existing DocumentEntry * @param stream the InputStream from which to populate the DocumentEntry * * @return the new or updated DocumentEntry * * @exception IOException if the document can't be created or its content be replaced */ @SuppressWarnings("WeakerAccess") public DocumentEntry createOrUpdateDocument(final String name, final InputStream stream) throws IOException { if (! hasEntry(name)) { return createDocument(name, stream); } else { DocumentNode existing = (DocumentNode)getEntry(name); POIFSDocument nDoc = new POIFSDocument(existing); nDoc.replaceContents(stream); return existing; } }
@Override public int addOlePackage(byte[] oleData, String label, String fileName, String command) throws IOException { // find an unused part name OPCPackage opc = getPackage(); PackagePartName pnOLE; int oleId=0; do { try { pnOLE = PackagingURIHelper.createPartName( "/xl/embeddings/oleObject"+(++oleId)+".bin" ); } catch (InvalidFormatException e) { throw new IOException("ole object name not recognized", e); } } while (opc.containPart(pnOLE)); PackagePart pp = opc.createPart( pnOLE, "application/vnd.openxmlformats-officedocument.oleObject" ); Ole10Native ole10 = new Ole10Native(label, fileName, command, oleData); try (ByteArrayOutputStream bos = new ByteArrayOutputStream(oleData.length+500)) { ole10.writeOut(bos); try (POIFSFileSystem poifs = new POIFSFileSystem()) { DirectoryNode root = poifs.getRoot(); root.createDocument(Ole10Native.OLE10_NATIVE, new ByteArrayInputStream(bos.toByteArray())); root.setStorageClsid(ClassIDPredefined.OLE_V1_PACKAGE.getClassID()); // TODO: generate CombObj stream try (OutputStream os = pp.getOutputStream()) { poifs.writeFilesystem(os); } } } return oleId; }
void writeToPOIFS() throws IOException { int oleStreamSize = (int)(fileOut.length()+LittleEndianConsts.LONG_SIZE); dir.createDocument(DEFAULT_POIFS_ENTRY, oleStreamSize, this); // TODO: any properties??? }
/** * create a new DocumentEntry in the root entry; the data will be * provided later * * @param name the name of the new DocumentEntry * @param size the size of the new DocumentEntry * @param writer the writer of the new DocumentEntry * * @return the new DocumentEntry * * @exception IOException if the writer exceeds the given size */ public DocumentEntry createDocument(final String name, final int size, final POIFSWriterListener writer) throws IOException { return getRoot().createDocument(name, size, writer); }
/** * Create a new document to be added to the root directory * * @param stream the InputStream from which the document's data * will be obtained * @param name the name of the new POIFSDocument * * @return the new DocumentEntry * * @exception IOException on error creating the new POIFSDocument */ public DocumentEntry createDocument(final InputStream stream, final String name) throws IOException { return getRoot().createDocument(name, stream); }
/** * Create a new document to be added to the root directory * * @param stream the InputStream from which the document's data * will be obtained * @param name the name of the new POIFSDocument * * @return the new DocumentEntry * * @exception IOException on error creating the new POIFSDocument */ public DocumentEntry createDocument(final InputStream stream, final String name) throws IOException { return getRoot().createDocument(name, stream); }
/** * create a new DocumentEntry; the data will be provided later * * @param name the name of the new DocumentEntry * @param size the size of the new DocumentEntry * @param writer the writer of the new DocumentEntry * * @return the new DocumentEntry * * @exception IOException */ public DocumentEntry createDocument(final String name, final int size, final POIFSWriterListener writer) throws IOException { return createDocument(new POIFSDocument(name, size, _path, writer)); }
/** * Create a new document to be added to the root directory * * @param stream the InputStream from which the document's data * will be obtained * @param name the name of the new POIFSDocument * * @return the new DocumentEntry * * @exception IOException on error creating the new POIFSDocument */ public DocumentEntry createDocument(final InputStream stream, final String name) throws IOException { return getRoot().createDocument(name, stream); }
/** * Create a new document to be added to the root directory * * @param stream the InputStream from which the document's data * will be obtained * @param name the name of the new POIFSDocument * * @return the new DocumentEntry * * @exception IOException on error creating the new POIFSDocument */ public DocumentEntry createDocument(final InputStream stream, final String name) throws IOException { return getRoot().createDocument(name, stream); }
/** * create a new DocumentEntry in the root entry; the data will be * provided later * * @param name the name of the new DocumentEntry * @param size the size of the new DocumentEntry * @param writer the writer of the new DocumentEntry * * @return the new DocumentEntry * * @exception IOException */ public DocumentEntry createDocument(final String name, final int size, final POIFSWriterListener writer) throws IOException { return getRoot().createDocument(name, size, writer); }
/** * create a new DocumentEntry in the root entry; the data will be * provided later * * @param name the name of the new DocumentEntry * @param size the size of the new DocumentEntry * @param writer the writer of the new DocumentEntry * * @return the new DocumentEntry * * @exception IOException */ public DocumentEntry createDocument(final String name, final int size, final POIFSWriterListener writer) throws IOException { return getRoot().createDocument(name, size, writer); }