1 package com.introlab.rtabmap;
3 import java.io.BufferedInputStream;
4 import java.io.BufferedOutputStream;
6 import java.io.FileInputStream;
7 import java.io.FileOutputStream;
8 import java.io.FilenameFilter;
9 import java.io.IOException;
10 import java.util.ArrayList;
11 import java.util.Arrays;
12 import java.util.Collections;
13 import java.util.Comparator;
14 import java.util.List;
15 import java.util.zip.ZipEntry;
16 import java.util.zip.ZipOutputStream;
18 import android.content.Context;
19 import android.net.ConnectivityManager;
20 import android.net.NetworkInfo;
21 import android.util.Log;
27 public static void zip(String file, String zipFile)
throws IOException {
29 String[] files =
new String[1];
34 public static void zip(String[] files, String zipFile)
throws IOException {
35 Log.i(
RTABMapActivity.
TAG,
"Zipping " + String.valueOf(files.length) +
" files to " + zipFile);
36 BufferedInputStream
origin =
null;
37 ZipOutputStream
out =
new ZipOutputStream(
new BufferedOutputStream(
new FileOutputStream(zipFile)));
41 for (
int i = 0;
i < files.length;
i++) {
42 FileInputStream fi =
new FileInputStream(files[
i]);
45 ZipEntry entry =
new ZipEntry(files[
i].substring(files[
i].lastIndexOf(
"/") + 1));
46 out.putNextEntry(entry);
62 public static String[]
loadFileList(
final String directory,
final boolean databasesOnly) {
63 File
path =
new File(directory);
68 catch(SecurityException
e) {
72 FilenameFilter filter =
new FilenameFilter() {
75 public boolean accept(File dir, String
filename) {
88 fileList =
path.list(filter);
89 Arrays.sort(fileList);
90 List<String> fileListt =
new ArrayList<String>(Arrays.asList(fileList));
91 Collections.sort(fileListt,
new Comparator<String>() {
94 public int compare(String filename1, String filename2) {
95 File file1 =
new File(directory+
"/"+filename1);
96 File file2 =
new File(directory+
"/"+filename2);
97 long k = file1.lastModified() - file2.lastModified();
107 fileListt.toArray(fileList);
111 fileList =
new String[0];
132 String[] vals1 = str1.split(
"\\.");
133 String[] vals2 = str2.split(
"\\.");
136 while (
i < vals1.length &&
i < vals2.length && vals1[
i].equals(vals2[
i])) {
140 if (
i < vals1.length &&
i < vals2.length) {
141 int diff = Integer.valueOf(vals1[
i]).compareTo(Integer.valueOf(vals2[
i]));
142 return Integer.signum(
diff);
146 return Integer.signum(vals1.length - vals2.length);