/** * Writes out a given PropertySet * * @param name the (POIFS Level) name of the property to write * @param set the PropertySet to write out * @param outFS the NPOIFSFileSystem to write the property into * * @throws IOException if an error when writing to the * {@link POIFSFileSystem} occurs */ private void writePropertySet(String name, PropertySet set, POIFSFileSystem outFS) throws IOException { try { PropertySet mSet = new PropertySet(set); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); mSet.write(bOut); byte[] data = bOut.toByteArray(); ByteArrayInputStream bIn = new ByteArrayInputStream(data); // Create or Update the Property Set stream in the POIFS outFS.createOrUpdateDocument(bIn, name); logger.log(POILogger.INFO, "Wrote property set " + name + " of size " + data.length); } catch(WritingNotSupportedException ignored) { logger.log( POILogger.ERROR, "Couldn't write property set with name " + name + " as not supported by HPSF yet"); } }
int byteOrder1 = ps.getByteOrder(); int byteOrder2 = getByteOrder(); ClassID classID1 = ps.getClassID(); ClassID classID2 = getClassID(); int format1 = ps.getFormat(); int format2 = getFormat(); int osVersion1 = ps.getOSVersion(); int osVersion2 = getOSVersion(); int sectionCount1 = ps.getSectionCount(); int sectionCount2 = getSectionCount(); if (byteOrder1 != byteOrder2 || !classID1.equals(classID2) || return getSections().containsAll(ps.getSections());
/** * Creates a {@link PropertySet} instance from a byte array that * represents a stream in the Horrible Property Set Format. * * @param stream The byte array holding the stream data. * @param offset The offset in {@code stream} where the stream * data begin. If the stream data begin with the first byte in the * array, the {@code offset} is 0. * @param length The length of the stream data. * @throws NoPropertySetStreamException if the byte array is not a * property set stream. * * @exception UnsupportedEncodingException if the codepage is not supported. */ public PropertySet(final byte[] stream, final int offset, final int length) throws NoPropertySetStreamException, UnsupportedEncodingException { if (!isPropertySetStream(stream, offset, length)) { throw new NoPropertySetStreamException(); } init(stream, offset, length); }
/** * Constructs a {@code PropertySet} by doing a deep copy of * an existing {@code PropertySet}. All nested elements, i.e. * {@code Section}s and {@code Property} instances, will be their * counterparts in the new {@code PropertySet}. * * @param ps The property set to copy */ public PropertySet(PropertySet ps) { setByteOrder(ps.getByteOrder()); setFormat(ps.getFormat()); setOSVersion(ps.getOSVersion()); setClassID(ps.getClassID()); for (final Section section : ps.getSections()) { sections.add(new Section(section)); } }
/** * Checks whether this {@link PropertySet} is a Document Summary Information. * * @return {@code true} if this {@link PropertySet} * represents a Document Summary Information, else {@code false}. */ public boolean isDocumentSummaryInformation() { return !sections.isEmpty() && matchesSummary(getFirstSection().getFormatID(), DocumentSummaryInformation.FORMAT_ID); }
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); } }
PropertySet ps = new PropertySet(is); if( ps.getSectionCount() != 0 ) { for( Property p : ps.getProperties() ) { System.out.println("Prop: "+p.getID()+" "+p.getValue());
final PropertySet mps = new PropertySet(si); final Section s = mps.getSections().get(0); final InputStream pss = mps.toInputStream();
ExtendedPropertyDefinition PR_TRANSPORT_MESSAGE_HEADERS = new ExtendedPropertyDefinition(0x007D, MapiPropertyType.String); PropertySet psPropSet = new PropertySet(BasePropertySet.FirstClassProperties) { PR_TRANSPORT_MESSAGE_HEADERS}; EmailMessage message = EmailMessage.bind(args.getSubscription().getService(), item.getItemId(),psPropSet);
@SuppressWarnings("SameParameterValue") void set1stProperty(long id, byte[] value) { getFirstSection().setProperty((int)id, value); }
/** * <p>Writes a {@link PropertySet} to a POI filesystem. This method is * simpler than {@link #editSI} because the origin property set has just * to be copied.</p> * * @param poiFs The POI filesystem to write to. * @param path The file's path in the POI filesystem. * @param name The file's name in the POI filesystem. * @param ps The property set to write. */ public void copy(final POIFSFileSystem poiFs, final POIFSDocumentPath path, final String name, final PropertySet ps) throws WritingNotSupportedException, IOException { final DirectoryEntry de = getPath(poiFs, path); final PropertySet mps = new PropertySet(ps); de.createDocument(name, mps.toInputStream()); }
if (sectionCount > 0 && PropertySet.matchesSummary(clsId, SummaryInformation.FORMAT_ID)) { return new SummaryInformation(stream); } else if (sectionCount > 0 && PropertySet.matchesSummary(clsId, DocumentSummaryInformation.FORMAT_ID)) { return new DocumentSummaryInformation(stream); } else { return new PropertySet(stream);
final long sectionCount = ps.getSectionCount(); out(" No. of sections: " + sectionCount); List<Section> sections = ps.getSections(); int nr = 0; for (Section sec : sections) {
/** * If the {@link PropertySet} has only a single section this method returns it. * * @return The singleSection value * * @deprecated superfluous convenience method */ @Deprecated @Removal(version="5.0.0") public Section getSingleSection() { final int sectionCount = getSectionCount(); if (sectionCount != 1) { throw new NoSingleSectionException("Property set contains " + sectionCount + " sections."); } return sections.get(0); }
if (PropertySet.isPropertySetStream(stream)) { try { if (ps.isSummaryInformation()) {
/** * Checks whether an {@link InputStream} is in the Horrible * Property Set Format. * * @param stream The {@link InputStream} to check. In order to * perform the check, the method reads the first bytes from the * stream. After reading, the stream is reset to the position it * had before reading. The {@link InputStream} must support the * {@link InputStream#mark} method. * @return {@code true} if the stream is a property set * stream, else {@code false}. * @exception IOException if an I/O error occurs */ public static boolean isPropertySetStream(final InputStream stream) throws IOException { /* * Read at most this many bytes. */ final int BUFFER_SIZE = 50; /* * Read a couple of bytes from the stream. */ try { final byte[] buffer = IOUtils.peekFirstNBytes(stream, BUFFER_SIZE); return isPropertySetStream(buffer, 0, buffer.length); } catch (EmptyFileException e) { return false; } }
@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); } }
/** * Constructs a {@code PropertySet} by doing a deep copy of * an existing {@code PropertySet}. All nested elements, i.e. * {@code Section}s and {@code Property} instances, will be their * counterparts in the new {@code PropertySet}. * * @param ps The property set to copy */ public PropertySet(PropertySet ps) { setByteOrder(ps.getByteOrder()); setFormat(ps.getFormat()); setOSVersion(ps.getOSVersion()); setClassID(ps.getClassID()); for (final Section section : ps.getSections()) { sections.add(new Section(section)); } }
UnsupportedEncodingException, IOException final PropertySet ps = new PropertySet(stream); try if (ps.isSummaryInformation()) return new SummaryInformation(ps); else if (ps.isDocumentSummaryInformation()) return new DocumentSummaryInformation(ps); else
PropertySet ps = new PropertySet(is); if( ps.getSectionCount() != 0 ) { for( Property p : ps.getProperties() ) { System.out.println("Prop: "+p.getID()+" "+p.getValue());