summaryrefslogtreecommitdiff
path: root/navit/android/src/org/navitproject/navit/NavitUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'navit/android/src/org/navitproject/navit/NavitUtils.java')
-rw-r--r--navit/android/src/org/navitproject/navit/NavitUtils.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/navit/android/src/org/navitproject/navit/NavitUtils.java b/navit/android/src/org/navitproject/navit/NavitUtils.java
new file mode 100644
index 000000000..bbdf6539e
--- /dev/null
+++ b/navit/android/src/org/navitproject/navit/NavitUtils.java
@@ -0,0 +1,53 @@
+package org.navitproject.navit;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+class NavitUtils {
+
+
+ static void removeFileIfExists(String source) {
+ File file = new File(source);
+
+ if (!file.exists()) {
+ return;
+ }
+
+ file.delete();
+ }
+
+ static void copyFileIfExists(String source, String destination) throws IOException {
+ File file = new File(source);
+
+ if (!file.exists()) {
+ return;
+ }
+
+ FileInputStream is = null;
+ FileOutputStream os = null;
+
+ try {
+ is = new FileInputStream(source);
+ os = new FileOutputStream(destination);
+
+ int len;
+ byte[] buffer = new byte[1024];
+
+ while ((len = is.read(buffer)) != -1) {
+ os.write(buffer, 0, len);
+ }
+ } finally {
+ /* Close the FileStreams to prevent Resource leaks */
+ if (is != null) {
+ is.close();
+ }
+
+ if (os != null) {
+ os.close();
+ }
+ }
+ }
+
+}