--- /dev/null
+package net.jaekl.qd.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+// Dispatch File Input/Output operations from a singleton
+// This makes it possible to intercept file reads and writes
+// during unit testing, and replace them with mock operations.
+
+public class FileIO {
+ // Note: need volatile to implement double-checked locking in getInst()
+ static volatile FileIO m_inst = null;
+
+ FileIO() { ; }
+
+ public static FileIO getInst() {
+ FileIO result = m_inst;
+ if (null == result) {
+ synchronized(FileIO.class) {
+ if (null == m_inst) {
+ m_inst = new FileIO();
+ }
+ result = m_inst;
+ }
+ }
+ return result;
+ }
+
+ public InputStream openInput(File file) throws FileNotFoundException
+ {
+ return new FileInputStream(file);
+ }
+
+ public OutputStream openOutput(File file) throws FileNotFoundException
+ {
+ return new FileOutputStream(file);
+ }
+}