*/
@SuppressWarnings({"java:S106","java:S4823"})
public final class CopyCompare {
- private CopyCompare() {}
- private static final ThreadLocal<PrintStream> out = ThreadLocal.withInitial(() -> System.out);
+ private PrintStream out = System.out;
/**
* Runs the example program. The application expects one or two arguments:
* supported.
*/
public static void main(final String[] args) throws IOException {
+ new CopyCompare().run(args);
+ }
+
+ public void run(String[] args) throws IOException {
String originalFileName = null;
String copyFileName = null;
POIFSFileSystem cpfs = new POIFSFileSystem(new File(copyFileName))) {
final DirectoryEntry oRoot = opfs.getRoot();
final DirectoryEntry cRoot = cpfs.getRoot();
- out.get().println(EntryUtils.areDirectoriesIdentical(oRoot, cRoot) ? "Equal" : "Not equal");
+ out.println(EntryUtils.areDirectoriesIdentical(oRoot, cRoot) ? "Equal" : "Not equal");
}
}
- public static void setOut(PrintStream ps) {
- out.set(ps);
+ public void setOut(PrintStream ps) {
+ out = ps;
}
private interface InputStreamSupplier {
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.examples.hpsf.CopyCompare;
-import org.apache.poi.extractor.POITextExtractor;
import org.apache.poi.hpsf.DocumentSummaryInformation;
import org.apache.poi.hpsf.HPSFPropertiesOnlyDocument;
import org.apache.poi.hpsf.PropertySet;
public void handleAdditional(File file) throws Exception {
assumeFalse(EXCLUDES_HANDLE_ADD.contains(file.getParentFile().getName()+"/"+file.getName()));
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
- PrintStream psNew = new PrintStream(bos, true, "ISO-8859-1");
- CopyCompare.setOut(psNew);
- CopyCompare.main(new String[]{file.getAbsolutePath(), copyOutput.get().getAbsolutePath()});
- assertEquals("Equal" + NL, bos.toString(StandardCharsets.UTF_8));
+ try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ PrintStream psNew = new PrintStream(bos, true, "ISO-8859-1");
+ CopyCompare copyCompare = new CopyCompare();
+ copyCompare.setOut(psNew);
+ CopyCompare.main(new String[]{file.getAbsolutePath(), copyOutput.get().getAbsolutePath()});
+ assertEquals("Equal" + NL, bos.toString(StandardCharsets.UTF_8));
+ }
}