|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
import java.io.InputStream; |
|
|
import java.io.InputStream; |
|
|
import java.io.OutputStream; |
|
|
import java.io.OutputStream; |
|
|
import java.io.PrintStream; |
|
|
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
|
|
|
|
|
import org.apache.poi.hpsf.DocumentSummaryInformation; |
|
|
import org.apache.poi.hpsf.DocumentSummaryInformation; |
|
|
|
|
|
|
|
|
@SuppressWarnings({"java:S106","java:S4823"}) |
|
|
@SuppressWarnings({"java:S106","java:S4823"}) |
|
|
public final class CopyCompare { |
|
|
public final class CopyCompare { |
|
|
|
|
|
|
|
|
private PrintStream out = System.out; |
|
|
|
|
|
|
|
|
private CopyCompare() {} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Runs the example program. The application expects one or two arguments: |
|
|
* Runs the example program. The application expects one or two arguments: |
|
|
|
|
|
|
|
|
* supported. |
|
|
* supported. |
|
|
*/ |
|
|
*/ |
|
|
public static void main(final String[] args) throws IOException { |
|
|
public static void main(final String[] args) throws IOException { |
|
|
new CopyCompare().run(args); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void run(String[] args) throws IOException { |
|
|
|
|
|
String originalFileName = null; |
|
|
String originalFileName = null; |
|
|
String copyFileName = null; |
|
|
String copyFileName = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.exit(1); |
|
|
System.exit(1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
boolean result = compare(originalFileName, copyFileName); |
|
|
|
|
|
System.out.println(result ? "Equal" : "Not equal"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static boolean compare(String originalFileName, String copyFileName) throws IOException { |
|
|
// Read the origin POIFS using the eventing API. |
|
|
// Read the origin POIFS using the eventing API. |
|
|
final POIFSReader r = new POIFSReader(); |
|
|
final POIFSReader r = new POIFSReader(); |
|
|
try (final POIFSFileSystem poiFs = new POIFSFileSystem(); |
|
|
try (final POIFSFileSystem poiFs = new POIFSFileSystem(); |
|
|
|
|
|
|
|
|
POIFSFileSystem cpfs = new POIFSFileSystem(new File(copyFileName))) { |
|
|
POIFSFileSystem cpfs = new POIFSFileSystem(new File(copyFileName))) { |
|
|
final DirectoryEntry oRoot = opfs.getRoot(); |
|
|
final DirectoryEntry oRoot = opfs.getRoot(); |
|
|
final DirectoryEntry cRoot = cpfs.getRoot(); |
|
|
final DirectoryEntry cRoot = cpfs.getRoot(); |
|
|
out.println(EntryUtils.areDirectoriesIdentical(oRoot, cRoot) ? "Equal" : "Not equal"); |
|
|
|
|
|
|
|
|
return EntryUtils.areDirectoriesIdentical(oRoot, cRoot); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void setOut(PrintStream ps) { |
|
|
|
|
|
out = ps; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private interface InputStreamSupplier { |
|
|
private interface InputStreamSupplier { |
|
|
InputStream get() throws IOException, WritingNotSupportedException; |
|
|
InputStream get() throws IOException, WritingNotSupportedException; |
|
|
} |
|
|
} |