/** * Opens for decryption */ public EncryptionInfo(DirectoryNode dir) throws IOException { this(dir.createDocumentInputStream("EncryptionInfo"), null); }
/** * open a document in the root entry's list of entries * * @param documentName the name of the document to be opened * * @return a newly opened DocumentInputStream * * @exception IOException if the document does not exist or the * name is that of a DirectoryEntry */ public DocumentInputStream createDocumentInputStream( final String documentName) throws IOException { return getRoot().createDocumentInputStream(documentName); }
/** * open a document in the directory's entry's list of entries * * @param documentName the name of the document to be opened * * @return a newly opened DocumentInputStream * * @exception IOException if the document does not exist or the * name is that of a DirectoryEntry */ public DocumentInputStream createDocumentInputStream( final String documentName) throws IOException { return createDocumentInputStream(getEntry(documentName)); }
/** * Processes a file into essentially record events. * * @param req an Instance of HSSFRequest which has your registered listeners * @param dir a DirectoryNode containing your workbook * @return numeric user-specified result code. * * @throws HSSFUserException if the processing should be aborted * @throws IOException if the workbook contained errors */ public short abortableProcessWorkbookEvents(HSSFRequest req, DirectoryNode dir) throws IOException, HSSFUserException { InputStream in = dir.createDocumentInputStream("Workbook"); try { return abortableProcessEvents(req, in); } finally { in.close(); } }
@Override public EmbeddedData extract(DirectoryNode dn) throws IOException { try(ByteArrayOutputStream bos = new ByteArrayOutputStream(); InputStream is = dn.createDocumentInputStream("CONTENTS")) { IOUtils.copy(is, bos); return new EmbeddedData(dn.getName() + ".pdf", bos.toByteArray(), CONTENT_TYPE_PDF); } }
@Override @SuppressWarnings("resource") public ChunkedCipherInputStream getDataStream(DirectoryNode dir) throws IOException, GeneralSecurityException { DocumentInputStream dis = dir.createDocumentInputStream(DEFAULT_POIFS_ENTRY); length = dis.readLong(); return new BinaryRC4CipherInputStream(dis, length); }
@Override public InputStream getDataStream(DirectoryNode dir) throws IOException, GeneralSecurityException { DocumentInputStream dis = dir.createDocumentInputStream(DEFAULT_POIFS_ENTRY); _length = dis.readLong(); return new AgileCipherInputStream(dis, _length); }
/** * Processes a file into essentially record events. * * @param req an Instance of HSSFRequest which has your registered listeners * @param dir a DirectoryNode containing your workbook * * @throws IOException if the workbook contained errors */ public void processWorkbookEvents(HSSFRequest req, DirectoryNode dir) throws IOException { // some old documents have "WORKBOOK" or "BOOK" String name = null; Set<String> entryNames = dir.getEntryNames(); for (String potentialName : WORKBOOK_DIR_ENTRY_NAMES) { if (entryNames.contains(potentialName)) { name = potentialName; break; } } // If in doubt, go for the default if (name == null) { name = WORKBOOK_DIR_ENTRY_NAMES[0]; } InputStream in = dir.createDocumentInputStream(name); try { processEvents(req, in); } finally { in.close(); } }
@SuppressWarnings("unchecked") public static <T extends POITextExtractor> T createExtractor(DirectoryNode poifsDir) throws IOException, OpenXML4JException, XmlException { // First, check for OOXML for (String entryName : poifsDir.getEntryNames()) { if (entryName.equals("Package")) { OPCPackage pkg = OPCPackage.open(poifsDir.createDocumentInputStream("Package")); return (T)createExtractor(pkg); } } // If not, ask the OLE2 code to check, with Scratchpad if possible return (T)OLE2ExtractorFactory.createExtractor(poifsDir); }
private void open(DirectoryNode directory) throws IOException { DocumentNode book; try { book = (DocumentNode)directory.getEntry(OLD_WORKBOOK_DIR_ENTRY_NAME); } catch (FileNotFoundException e) { // some files have "Workbook" instead book = (DocumentNode)directory.getEntry(WORKBOOK_DIR_ENTRY_NAMES[0]); } if (book == null) { throw new IOException("No Excel 5/95 Book stream found"); } ris = new RecordInputStream(directory.createDocumentInputStream(book)); prepare(); }
/** * Creates an instance of this class from an embedded OLE Object. The OLE Object is expected * to include a stream "{01}Ole10Native" which contains the actual * data relevant for this class. * * @param directory POI Filesystem object * @return Returns an instance of this class * @throws IOException on IO error * @throws Ole10NativeException on invalid or unexcepted data format */ public static Ole10Native createFromEmbeddedOleObject(DirectoryNode directory) throws IOException, Ole10NativeException { DocumentEntry nativeEntry = (DocumentEntry)directory.getEntry(OLE10_NATIVE); byte[] data = IOUtils.safelyAllocate(nativeEntry.getSize(), MAX_RECORD_LENGTH); int readBytes = directory.createDocumentInputStream(nativeEntry).read(data); assert(readBytes == data.length); return new Ole10Native(data, 0); }
@Override @SuppressWarnings("resource") public InputStream getDataStream(DirectoryNode dir) throws IOException { DocumentInputStream dis = dir.createDocumentInputStream(DEFAULT_POIFS_ENTRY); _length = dis.readLong(); if(getSecretKey() == null) { verifyPassword(null); } // limit wrong calculated ole entries - (bug #57080) // standard encryption always uses aes encoding, so blockSize is always 16 // http://stackoverflow.com/questions/3283787/size-of-data-after-aes-encryption int blockSize = getEncryptionInfo().getHeader().getCipherAlgorithm().blockSize; long cipherLen = (_length/blockSize + 1) * blockSize; Cipher cipher = getCipher(getSecretKey()); InputStream boundedDis = new BoundedInputStream(dis, cipherLen); return new BoundedInputStream(new CipherInputStream(boundedDis, cipher), _length); }
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); } } } }
@Override public EmbeddedData extract(DirectoryNode dn) throws IOException { ClassIDPredefined clsId = ClassIDPredefined.lookup(dn.getStorageClsid()); String contentType = null; String ext = null; if (clsId != null) { contentType = clsId.getContentType(); ext = clsId.getFileExtension(); } if (contentType == null || ext == null) { contentType = "application/zip"; ext = ".zip"; } DocumentInputStream dis = dn.createDocumentInputStream("package"); byte data[] = IOUtils.toByteArray(dis); dis.close(); return new EmbeddedData(dn.getName()+ext, data, contentType); } }
InputStream stream = directory.createDocumentInputStream(workbookName);
try (DocumentInputStream dis = dirNode.createDocumentInputStream(dirNode.getEntry(setName))) {
throws IOException, GeneralSecurityException { DocumentNode es = (DocumentNode) root.getEntry(encryptedStream); DocumentInputStream dis = root.createDocumentInputStream(es); ByteArrayOutputStream bos = new ByteArrayOutputStream(); IOUtils.copy(dis, bos);
DocumentInputStream dis = dir.createDocumentInputStream(entry); IOUtils.copy(dis, bos); dis.close();
private static byte[] getData(DirectoryNode dir, String name) throws IOException { // Grab the document stream InputStream is = dir.createDocumentInputStream(name); byte[] d = IOUtils.toByteArray(is); is.close(); // All done return d; }
DocumentInputStream documentInputStream = root.createDocumentInputStream(WORKBOOK_ENTRY); HSSFEventFactory eventFactory = new HSSFEventFactory(); try {