2017-03-05 13:05:26 -05:00
|
|
|
package com.introlab.rtabmap;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedInputStream;
|
|
|
|
|
import java.io.BufferedOutputStream;
|
2017-06-16 16:24:38 -04:00
|
|
|
import java.io.File;
|
2017-03-05 13:05:26 -05:00
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.FileOutputStream;
|
2017-06-16 16:24:38 -04:00
|
|
|
import java.io.FilenameFilter;
|
2017-03-05 13:05:26 -05:00
|
|
|
import java.io.IOException;
|
2017-06-16 16:24:38 -04:00
|
|
|
import java.util.Arrays;
|
2017-03-05 13:05:26 -05:00
|
|
|
import java.util.zip.ZipEntry;
|
|
|
|
|
import java.util.zip.ZipOutputStream;
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.net.ConnectivityManager;
|
|
|
|
|
import android.net.NetworkInfo;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
public class Util {
|
|
|
|
|
|
|
|
|
|
public static final int ZIP_BUFFER_SIZE = 1<<20; // 1MB
|
|
|
|
|
|
|
|
|
|
public static void zip(String file, String zipFile) throws IOException {
|
|
|
|
|
Log.i(RTABMapActivity.TAG, "Zipping " + file +" to " + zipFile);
|
|
|
|
|
String[] files = new String[1];
|
|
|
|
|
files[0] = file;
|
|
|
|
|
zip(files, zipFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void zip(String[] files, String zipFile) throws IOException {
|
|
|
|
|
Log.i(RTABMapActivity.TAG, "Zipping " + String.valueOf(files.length) +" files to " + zipFile);
|
|
|
|
|
BufferedInputStream origin = null;
|
|
|
|
|
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
|
|
|
|
|
try {
|
|
|
|
|
byte data[] = new byte[ZIP_BUFFER_SIZE];
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < files.length; i++) {
|
|
|
|
|
FileInputStream fi = new FileInputStream(files[i]);
|
|
|
|
|
origin = new BufferedInputStream(fi, ZIP_BUFFER_SIZE);
|
|
|
|
|
try {
|
|
|
|
|
ZipEntry entry = new ZipEntry(files[i].substring(files[i].lastIndexOf("/") + 1));
|
|
|
|
|
out.putNextEntry(entry);
|
|
|
|
|
int count;
|
|
|
|
|
while ((count = origin.read(data, 0, ZIP_BUFFER_SIZE)) != -1) {
|
|
|
|
|
out.write(data, 0, count);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
origin.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
out.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-16 16:24:38 -04:00
|
|
|
public static String[] loadFileList(String directory, final boolean databasesOnly) {
|
|
|
|
|
File path = new File(directory);
|
|
|
|
|
String fileList[];
|
|
|
|
|
try {
|
|
|
|
|
path.mkdirs();
|
|
|
|
|
}
|
|
|
|
|
catch(SecurityException e) {
|
|
|
|
|
Log.e(RTABMapActivity.TAG, "unable to write on the sd card " + e.toString());
|
|
|
|
|
}
|
|
|
|
|
if(path.exists()) {
|
|
|
|
|
FilenameFilter filter = new FilenameFilter() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean accept(File dir, String filename) {
|
|
|
|
|
File sel = new File(dir, filename);
|
|
|
|
|
if(databasesOnly)
|
|
|
|
|
{
|
|
|
|
|
return filename.compareTo(RTABMapActivity.RTABMAP_TMP_DB) != 0 && filename.endsWith(".db");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return sel.isFile();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
fileList = path.list(filter);
|
|
|
|
|
Arrays.sort(fileList);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fileList = new String[0];
|
|
|
|
|
}
|
|
|
|
|
return fileList;
|
|
|
|
|
}
|
2017-03-05 13:05:26 -05:00
|
|
|
|
|
|
|
|
}
|