diff --git a/G-Earth.iml b/G-Earth.iml
new file mode 100644
index 0000000..c90834f
--- /dev/null
+++ b/G-Earth.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/protocol/hostreplacer/UnixHostReplacer.java b/src/main/protocol/hostreplacer/UnixHostReplacer.java
index 6436e92..f4fb5dd 100644
--- a/src/main/protocol/hostreplacer/UnixHostReplacer.java
+++ b/src/main/protocol/hostreplacer/UnixHostReplacer.java
@@ -16,14 +16,19 @@ class UnixHostReplacer implements HostReplacer {
@Override
public void addRedirect(String original, String redirect) {
- String text = redirect + " " + original;
+ String text = redirect + " " + original + "\t# G-Earth replacement";
+
+ FileReader fr = null;
+ BufferedReader br = null;
+ FileWriter fw = null;
+ BufferedWriter out = null;
try
{
ArrayList lines = new ArrayList();
File f1 = new File(hostsFileLocation);
- FileReader fr = new FileReader(f1);
- BufferedReader br = new BufferedReader(fr);
+ fr = new FileReader(f1);
+ br = new BufferedReader(fr);
String line = null;
boolean containmmm = false;
while ((line = br.readLine()) != null)
@@ -36,59 +41,77 @@ class UnixHostReplacer implements HostReplacer {
fr.close();
br.close();
- FileWriter fw = new FileWriter(f1);
- BufferedWriter out = new BufferedWriter(fw);
+ fw = new FileWriter(f1);
+ out = new BufferedWriter(fw);
if (!containmmm) {
out.write(text);
}
for (int i = 0; i < lines.size(); i++) {
- out.write("\n"+ lines.get(i));
+ out.write(System.getProperty("line.separator")+ lines.get(i));
}
-
- out.flush();
- out.close();
}
catch (Exception ex)
{
ex.printStackTrace();
}
+ finally {
+ try {
+ if (fr != null) fr.close();
+ if (br != null) br.close();
+ if (fw != null) fw.close();
+ if (out != null) out.close();
+ }
+ catch (Exception e) {}
+ }
}
@Override
public void removeRedirect(String original, String redirect) {
- String text = redirect + " " + original;
+ String text = redirect + " " + original + "\t# G-Earth replacement";
+
+ FileReader fr = null;
+ BufferedReader br = null;
+ FileWriter fw = null;
+ BufferedWriter out = null;
try
{
ArrayList lines = new ArrayList();
File f1 = new File(hostsFileLocation);
- FileReader fr = new FileReader(f1);
- BufferedReader br = new BufferedReader(fr);
+ fr = new FileReader(f1);
+ br = new BufferedReader(fr);
String line = null;
while ((line = br.readLine()) != null)
{
- if (!line.contains(text))
+ if (!line.equals(text))
lines.add(line);
}
fr.close();
br.close();
- FileWriter fw = new FileWriter(f1);
- BufferedWriter out = new BufferedWriter(fw);
+ fw = new FileWriter(f1);
+ out = new BufferedWriter(fw);
for (int i = 0; i < lines.size(); i++) {
out.write(lines.get(i));
- if (i != lines.size() - 1) out.write("\n");
+ if (i != lines.size() - 1) out.write(System.getProperty("line.separator"));
}
- out.flush();
- out.close();
}
catch (Exception ex)
{
ex.printStackTrace();
}
+ finally {
+ try {
+ if (fr != null) fr.close();
+ if (br != null) br.close();
+ if (fw != null) fw.close();
+ if (out != null) out.close();
+ }
+ catch (Exception e) {}
+ }
}
}