/** * open a document in the directory's entry's list of entries * * @param document the document to be opened * * @return a newly opened DocumentInputStream or DocumentInputStream * * @exception IOException if the document does not exist or the * name is that of a DirectoryEntry */ public DocumentInputStream createDocumentInputStream( final Entry document) throws IOException { if (!document.isDocumentEntry()) { throw new IOException("Entry '" + document.getName() + "' is not a DocumentEntry"); } DocumentEntry entry = (DocumentEntry)document; return new DocumentInputStream(entry); }
protected void findProjectProperties(DirectoryNode node, Map<String, String> moduleNameMap, ModuleMap modules) throws IOException { for (Entry entry : node) { if ("project".equalsIgnoreCase(entry.getName())) { DocumentNode document = (DocumentNode)entry; try(DocumentInputStream dis = new DocumentInputStream(document)) { readProjectProperties(dis, moduleNameMap, modules); return; } } else if (entry instanceof DirectoryNode) { findProjectProperties((DirectoryNode)entry, moduleNameMap, modules); } } }
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 {
try { DocumentEntry entry = (DocumentEntry)dir.getEntry(name); inp = new DocumentInputStream(entry); try { return create(inp);
protected void findModuleNameMap(DirectoryNode node, Map<String, String> moduleNameMap, ModuleMap modules) throws IOException { for (Entry entry : node) { if ("projectwm".equalsIgnoreCase(entry.getName())) { DocumentNode document = (DocumentNode)entry; try(DocumentInputStream dis = new DocumentInputStream(document)) { readNameMapRecords(dis, moduleNameMap, modules.charset); return; } } else if (entry.isDirectoryEntry()) { findModuleNameMap((DirectoryNode)entry, moduleNameMap, modules); } } }
@Override public boolean equals(Object other) { if (!(other instanceof DocumentDelegate)) { return false; } DocumentDelegate dd = (DocumentDelegate)other; if (this == dd) { return true; } if (!Objects.equals(doc.getName(), dd.doc.getName())) { // Names don't match, not the same return false; } try (DocumentInputStream inpA = new DocumentInputStream(doc); DocumentInputStream inpB = new DocumentInputStream(dd.doc)) { if (PropertySet.isPropertySetStream(inpA) && PropertySet.isPropertySetStream(inpB)) { final PropertySet ps1 = PropertySetFactory.create(inpA); final PropertySet ps2 = PropertySetFactory.create(inpB); return ps1.equals(ps2); } else { return isEqual(inpA, inpB); } } catch (MarkUnsupportedException | NoPropertySetStreamException | IOException ex) { throw new RuntimeException(ex); } }
try (InputStream dis = new DocumentInputStream(documentNode)) { module.read(dis); InputStream compressed = new DocumentInputStream(documentNode); try { compressed = new DocumentInputStream(documentNode); byte[] decompressedBytes; try {
/** * 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 InputStream getStream() throws IOException { return new DocumentInputStream(_docEntry); }
document = new POIFSDocument((DocumentProperty)property, poifs); try (DocumentInputStream dis = new DocumentInputStream(document)) { POIFSReaderEvent pe = new POIFSReaderEvent(dis, path, name); rl.processPOIFSReaderEvent(pe);
private void processDirStream(Entry dir, ModuleMap modules) throws IOException { DocumentNode dirDocumentNode = (DocumentNode)dir; DIR_STATE dirState = DIR_STATE.INFORMATION_RECORD; try (DocumentInputStream dis = new DocumentInputStream(dirDocumentNode)) { String streamName = null; int recordId = 0;
private void parseSummaryEntryIfExists( DirectoryNode root, String entryName) throws IOException, TikaException { try { DocumentEntry entry = (DocumentEntry) root.getEntry(entryName); PropertySet properties = new PropertySet(new DocumentInputStream(entry)); if (properties.isSummaryInformation()) { parse(new SummaryInformation(properties)); } if (properties.isDocumentSummaryInformation()) { parse(new DocumentSummaryInformation(properties)); } } catch (FileNotFoundException e) { // entry does not exist, just skip it } catch (NoPropertySetStreamException e) { // no property stream, just skip it } catch (UnexpectedPropertySetTypeException e) { throw new TikaException("Unexpected HPSF document", e); } catch (Exception e) { LOG.warn("Ignoring unexpected exception while parsing summary entry {}", entryName, 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); } } } } }
if (e != null && e.isDocumentEntry()) { DocumentNode dn = (DocumentNode) e; DocumentInputStream stream = new DocumentInputStream(dn); byte[] bytes = IOUtils.toByteArray(stream);
TikaInputStream stream = TikaInputStream.get(new DocumentInputStream((DocumentEntry) ooxml)); try (DocumentInputStream inp = new DocumentInputStream(contentsEntry)) { ret = new byte[contentsEntry.getSize()]; inp.readFully(ret);
/** * {@inheritDoc} */ @Override protected VarMeta getCalendarVarMeta(DirectoryEntry directory) throws IOException { return new VarMeta9(new DocumentInputStream(((DocumentEntry) directory.getEntry("VarMeta")))); }
/** * {@inheritDoc} */ @Override protected VarMeta getCalendarVarMeta(DirectoryEntry directory) throws IOException { return new VarMeta12(new DocumentInputStream(((DocumentEntry) directory.getEntry("VarMeta")))); }
/** * {@inheritDoc} */ @Override protected VarMeta getCalendarVarMeta(DirectoryEntry directory) throws IOException { return new VarMeta12(new DocumentInputStream(((DocumentEntry) directory.getEntry("VarMeta")))); }
new DocumentInputStream((DocumentEntry) ooxml))) { ZipContainerDetector detector = new ZipContainerDetector(); MediaType type = null; contentsEntry = (DocumentEntry) dir.getEntry("Contents"); DocumentInputStream inp = new DocumentInputStream(contentsEntry); byte[] contents = new byte[contentsEntry.getSize()]; inp.readFully(contents);