mirror of https://github.com/apache/poi.git
refactor CopyCompare again
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896543 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e35347157d
commit
4823d0cbd4
|
@ -22,7 +22,6 @@ import java.io.FileOutputStream;
|
||||||
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;
|
||||||
|
@ -63,7 +62,7 @@ import org.apache.poi.util.TempFile;
|
||||||
@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:
|
||||||
|
@ -82,10 +81,6 @@ public final class CopyCompare {
|
||||||
* 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;
|
||||||
|
|
||||||
|
@ -103,7 +98,11 @@ public final class CopyCompare {
|
||||||
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();
|
||||||
|
@ -123,14 +122,10 @@ public final class CopyCompare {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
import static org.junit.jupiter.api.Assumptions.assumeFalse;
|
import static org.junit.jupiter.api.Assumptions.assumeFalse;
|
||||||
|
|
||||||
|
@ -27,11 +28,8 @@ import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
|
||||||
import org.apache.poi.examples.hpsf.CopyCompare;
|
import org.apache.poi.examples.hpsf.CopyCompare;
|
||||||
import org.apache.poi.hpsf.DocumentSummaryInformation;
|
import org.apache.poi.hpsf.DocumentSummaryInformation;
|
||||||
import org.apache.poi.hpsf.HPSFPropertiesOnlyDocument;
|
import org.apache.poi.hpsf.HPSFPropertiesOnlyDocument;
|
||||||
|
@ -128,14 +126,8 @@ public class HPSFFileHandler extends POIFSFileHandler {
|
||||||
public void handleAdditional(File file) throws Exception {
|
public void handleAdditional(File file) throws Exception {
|
||||||
assumeFalse(EXCLUDES_HANDLE_ADD.contains(file.getParentFile().getName()+"/"+file.getName()));
|
assumeFalse(EXCLUDES_HANDLE_ADD.contains(file.getParentFile().getName()+"/"+file.getName()));
|
||||||
|
|
||||||
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
boolean result = CopyCompare.compare(file.getAbsolutePath(), copyOutput.get().getAbsolutePath());
|
||||||
try (PrintStream psNew = new PrintStream(bos, true, "ISO-8859-1")) {
|
assertTrue(result);
|
||||||
CopyCompare copyCompare = new CopyCompare();
|
|
||||||
copyCompare.setOut(psNew);
|
|
||||||
copyCompare.run(new String[]{file.getAbsolutePath(), copyOutput.get().getAbsolutePath()});
|
|
||||||
assertEquals("Equal" + NL, bos.toString(StandardCharsets.UTF_8));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue