+
+ /**
+ * renewMainPrintWriter() renews the mapHostToMainFile object that lists all main PrintWriters
+ *
+ * @return void
+ */
+ public void renewMainPrintWriter() {
+
+ mapHostToMainFile = new HashMap<String, PrintWriter>();
+ }
+
+ /**
+ * initMainPolicy() initializes the main PrintWriter object to print the entire policies
+ *
+ * @param strConfigHost String hostname to be configured
+ * @return void
+ */
+ public void initMainPolicy(String strConfigHost) {
+
+ PrintWriter pwConfig = getMainPrintWriter(strConfigHost);
+ pwConfig.println("*filter"); // Print header for iptables-restore
+ }
+
+ /**
+ * getMainPrintWriter() gets the main PrintWriter object to print the entire policies
+ *
+ * @param strHost String hostname to be configured
+ * @return PrintWriter
+ */
+ private PrintWriter getMainPrintWriter(String strHost) {
+
+ String strConfigHost = strHost + STR_POLICY_FILE_ALL;
+ // Return object if existing
+ if (mapHostToMainFile.containsKey(strConfigHost)) {
+ return mapHostToMainFile.get(strConfigHost);
+ } else {
+ // Simply create a new one if it doesn't exist
+ FileWriter fw = null;
+ try {
+ fw = new FileWriter(strConfigHost + STR_POLICY_FILE_EXT);
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ PrintWriter pwConfig = new PrintWriter(new BufferedWriter(fw));
+ mapHostToMainFile.put(strConfigHost, pwConfig);
+ return pwConfig;
+ }
+ }