[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [orbot/master] refactor



commit d1884c3349601c27c9cd95492b94b62e3b37b981
Author: arrase <arrase@xxxxxxxxx>
Date:   Mon Nov 21 00:04:48 2016 +0100

    refactor
---
 .../org/torproject/android/OrbotMainActivity.java  |  2 +-
 .../android/hsutils/ExternalStorage.java           | 42 ----------
 .../android/hsutils/GrantedPermissionsAction.java  |  7 --
 .../android/hsutils/HiddenServiceUtils.java        |  2 +
 .../java/org/torproject/android/hsutils/ZipIt.java | 98 ----------------------
 .../android/storage/ExternalStorage.java           | 42 ++++++++++
 .../android/storage/GrantedPermissionsAction.java  |  7 ++
 .../java/org/torproject/android/zip/ZipIt.java     | 98 ++++++++++++++++++++++
 8 files changed, 150 insertions(+), 148 deletions(-)

diff --git a/app/src/main/java/org/torproject/android/OrbotMainActivity.java b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
index b28c3c4..a544de5 100644
--- a/app/src/main/java/org/torproject/android/OrbotMainActivity.java
+++ b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
@@ -16,7 +16,7 @@ import java.util.Random;
 import java.util.StringTokenizer;
 
 import org.json.JSONArray;
-import org.torproject.android.hsutils.GrantedPermissionsAction;
+import org.torproject.android.storage.GrantedPermissionsAction;
 import org.torproject.android.service.OrbotConstants;
 import org.torproject.android.service.util.Prefs;
 import org.torproject.android.service.TorService;
diff --git a/app/src/main/java/org/torproject/android/hsutils/ExternalStorage.java b/app/src/main/java/org/torproject/android/hsutils/ExternalStorage.java
deleted file mode 100644
index 400f39a..0000000
--- a/app/src/main/java/org/torproject/android/hsutils/ExternalStorage.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package org.torproject.android.hsutils;
-
-import android.os.Environment;
-
-import java.io.File;
-
-public class ExternalStorage {
-    private final String BACKUPS_DIR = "Orbot-HiddenServices";
-
-    public String createBackupDir() {
-        if (!isExternalStorageWritable()) {
-            return null;
-        }
-
-        File path = Environment.getExternalStoragePublicDirectory(BACKUPS_DIR);
-
-        if (!path.mkdirs()) {
-            return null;
-        }
-
-        return path.getAbsolutePath();
-    }
-
-    /* Checks if external storage is available for read and write */
-    public boolean isExternalStorageWritable() {
-        String state = Environment.getExternalStorageState();
-        if (Environment.MEDIA_MOUNTED.equals(state)) {
-            return true;
-        }
-        return false;
-    }
-
-    /* Checks if external storage is available to at least read */
-    public boolean isExternalStorageReadable() {
-        String state = Environment.getExternalStorageState();
-        if (Environment.MEDIA_MOUNTED.equals(state) ||
-                Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
-            return true;
-        }
-        return false;
-    }
-}
diff --git a/app/src/main/java/org/torproject/android/hsutils/GrantedPermissionsAction.java b/app/src/main/java/org/torproject/android/hsutils/GrantedPermissionsAction.java
deleted file mode 100644
index 31731fa..0000000
--- a/app/src/main/java/org/torproject/android/hsutils/GrantedPermissionsAction.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.torproject.android.hsutils;
-
-import android.content.Context;
-
-public abstract class GrantedPermissionsAction {
-    public abstract void run(Context context, boolean granted);
-}
diff --git a/app/src/main/java/org/torproject/android/hsutils/HiddenServiceUtils.java b/app/src/main/java/org/torproject/android/hsutils/HiddenServiceUtils.java
index 0e96756..0cf359b 100644
--- a/app/src/main/java/org/torproject/android/hsutils/HiddenServiceUtils.java
+++ b/app/src/main/java/org/torproject/android/hsutils/HiddenServiceUtils.java
@@ -4,6 +4,8 @@ import android.app.Application;
 import android.content.Context;
 
 import org.torproject.android.service.TorServiceConstants;
+import org.torproject.android.storage.ExternalStorage;
+import org.torproject.android.zip.ZipIt;
 
 import java.io.File;
 
diff --git a/app/src/main/java/org/torproject/android/hsutils/ZipIt.java b/app/src/main/java/org/torproject/android/hsutils/ZipIt.java
deleted file mode 100644
index 25d74a5..0000000
--- a/app/src/main/java/org/torproject/android/hsutils/ZipIt.java
+++ /dev/null
@@ -1,98 +0,0 @@
-package org.torproject.android.hsutils;
-
-
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-import java.util.zip.ZipOutputStream;
-
-public class ZipIt {
-    private static final int BUFFER = 2048;
-
-    private String[] _files;
-    private String _zipFile;
-
-    public ZipIt(String[] files, String zipFile) {
-        _files = files;
-        _zipFile = zipFile;
-    }
-
-    public boolean zip() {
-        try {
-            BufferedInputStream origin = null;
-            FileOutputStream dest = new FileOutputStream(_zipFile);
-
-            ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest));
-
-            byte data[] = new byte[BUFFER];
-
-            for (String _file : _files) {
-                FileInputStream fi = new FileInputStream(_file);
-                origin = new BufferedInputStream(fi, BUFFER);
-                ZipEntry entry = new ZipEntry(_file.substring(_file.lastIndexOf("/") + 1));
-                out.putNextEntry(entry);
-                int count;
-                while ((count = origin.read(data, 0, BUFFER)) != -1) {
-                    out.write(data, 0, count);
-                }
-                origin.close();
-            }
-
-            out.close();
-        } catch (Exception e) {
-            return false;
-        }
-
-        return true;
-    }
-
-    public boolean unzip(String output_path) {
-        InputStream is;
-        ZipInputStream zis;
-
-        try {
-            String filename;
-            is = new FileInputStream(_zipFile);
-            zis = new ZipInputStream(new BufferedInputStream(is));
-            ZipEntry ze;
-            byte[] buffer = new byte[1024];
-            int count;
-
-            while ((ze = zis.getNextEntry()) != null) {
-                // zapis do souboru
-                filename = ze.getName();
-
-                // Need to create directories if not exists, or
-                // it will generate an Exception...
-                if (ze.isDirectory()) {
-                    File fmd = new File(output_path + filename);
-                    fmd.mkdirs();
-                    continue;
-                }
-
-                FileOutputStream fout = new FileOutputStream(output_path + filename);
-
-                // cteni zipu a zapis
-                while ((count = zis.read(buffer)) != -1) {
-                    fout.write(buffer, 0, count);
-                }
-
-                fout.close();
-                zis.closeEntry();
-            }
-
-            zis.close();
-        } catch (IOException e) {
-            e.printStackTrace();
-            return false;
-        }
-
-        return true;
-    }
-}
\ No newline at end of file
diff --git a/app/src/main/java/org/torproject/android/storage/ExternalStorage.java b/app/src/main/java/org/torproject/android/storage/ExternalStorage.java
new file mode 100644
index 0000000..6da650d
--- /dev/null
+++ b/app/src/main/java/org/torproject/android/storage/ExternalStorage.java
@@ -0,0 +1,42 @@
+package org.torproject.android.storage;
+
+import android.os.Environment;
+
+import java.io.File;
+
+public class ExternalStorage {
+    private final String BACKUPS_DIR = "Orbot-HiddenServices";
+
+    public String createBackupDir() {
+        if (!isExternalStorageWritable()) {
+            return null;
+        }
+
+        File path = Environment.getExternalStoragePublicDirectory(BACKUPS_DIR);
+
+        if (!path.mkdirs()) {
+            return null;
+        }
+
+        return path.getAbsolutePath();
+    }
+
+    /* Checks if external storage is available for read and write */
+    public boolean isExternalStorageWritable() {
+        String state = Environment.getExternalStorageState();
+        if (Environment.MEDIA_MOUNTED.equals(state)) {
+            return true;
+        }
+        return false;
+    }
+
+    /* Checks if external storage is available to at least read */
+    public boolean isExternalStorageReadable() {
+        String state = Environment.getExternalStorageState();
+        if (Environment.MEDIA_MOUNTED.equals(state) ||
+                Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
+            return true;
+        }
+        return false;
+    }
+}
diff --git a/app/src/main/java/org/torproject/android/storage/GrantedPermissionsAction.java b/app/src/main/java/org/torproject/android/storage/GrantedPermissionsAction.java
new file mode 100644
index 0000000..9a62a74
--- /dev/null
+++ b/app/src/main/java/org/torproject/android/storage/GrantedPermissionsAction.java
@@ -0,0 +1,7 @@
+package org.torproject.android.storage;
+
+import android.content.Context;
+
+public abstract class GrantedPermissionsAction {
+    public abstract void run(Context context, boolean granted);
+}
diff --git a/app/src/main/java/org/torproject/android/zip/ZipIt.java b/app/src/main/java/org/torproject/android/zip/ZipIt.java
new file mode 100644
index 0000000..84a0b7a
--- /dev/null
+++ b/app/src/main/java/org/torproject/android/zip/ZipIt.java
@@ -0,0 +1,98 @@
+package org.torproject.android.zip;
+
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
+
+public class ZipIt {
+    private static final int BUFFER = 2048;
+
+    private String[] _files;
+    private String _zipFile;
+
+    public ZipIt(String[] files, String zipFile) {
+        _files = files;
+        _zipFile = zipFile;
+    }
+
+    public boolean zip() {
+        try {
+            BufferedInputStream origin = null;
+            FileOutputStream dest = new FileOutputStream(_zipFile);
+
+            ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest));
+
+            byte data[] = new byte[BUFFER];
+
+            for (String _file : _files) {
+                FileInputStream fi = new FileInputStream(_file);
+                origin = new BufferedInputStream(fi, BUFFER);
+                ZipEntry entry = new ZipEntry(_file.substring(_file.lastIndexOf("/") + 1));
+                out.putNextEntry(entry);
+                int count;
+                while ((count = origin.read(data, 0, BUFFER)) != -1) {
+                    out.write(data, 0, count);
+                }
+                origin.close();
+            }
+
+            out.close();
+        } catch (Exception e) {
+            return false;
+        }
+
+        return true;
+    }
+
+    public boolean unzip(String output_path) {
+        InputStream is;
+        ZipInputStream zis;
+
+        try {
+            String filename;
+            is = new FileInputStream(_zipFile);
+            zis = new ZipInputStream(new BufferedInputStream(is));
+            ZipEntry ze;
+            byte[] buffer = new byte[1024];
+            int count;
+
+            while ((ze = zis.getNextEntry()) != null) {
+                // zapis do souboru
+                filename = ze.getName();
+
+                // Need to create directories if not exists, or
+                // it will generate an Exception...
+                if (ze.isDirectory()) {
+                    File fmd = new File(output_path + filename);
+                    fmd.mkdirs();
+                    continue;
+                }
+
+                FileOutputStream fout = new FileOutputStream(output_path + filename);
+
+                // cteni zipu a zapis
+                while ((count = zis.read(buffer)) != -1) {
+                    fout.write(buffer, 0, count);
+                }
+
+                fout.close();
+                zis.closeEntry();
+            }
+
+            zis.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+            return false;
+        }
+
+        return true;
+    }
+}
\ No newline at end of file



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits