/** * Compares two {@link DocumentEntry} instances of a POI file system. * Documents that are not property set streams must be bitwise identical. * Property set streams must be logically equal.<p> * * (Their parent directories are not checked) */ @SuppressWarnings("WeakerAccess") public static boolean areDocumentsIdentical(DocumentEntry docA, DocumentEntry docB) throws IOException { try { return new DocumentDelegate(docA).equals(new DocumentDelegate(docB)); } catch (RuntimeException e) { if (e.getCause() instanceof IOException) { throw (IOException)e.getCause(); } else { throw e; } } }
@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); } }
@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); } }
/** * Compares two {@link DocumentEntry} instances of a POI file system. * Documents that are not property set streams must be bitwise identical. * Property set streams must be logically equal.<p> * * (Their parent directories are not checked) */ @SuppressWarnings("WeakerAccess") public static boolean areDocumentsIdentical(DocumentEntry docA, DocumentEntry docB) throws IOException { try { return new DocumentDelegate(docA).equals(new DocumentDelegate(docB)); } catch (RuntimeException e) { if (e.getCause() instanceof IOException) { throw (IOException)e.getCause(); } else { throw e; } } }
private static POIDelegate toDelegate(Entry entry) { return (entry.isDirectoryEntry()) ? new DirectoryDelegate((DirectoryEntry)entry) : new DocumentDelegate((DocumentEntry)entry); }
private static POIDelegate toDelegate(Entry entry) { return (entry.isDirectoryEntry()) ? new DirectoryDelegate((DirectoryEntry)entry) : new DocumentDelegate((DocumentEntry)entry); }