Util.java
Go to the documentation of this file.
1 package com.introlab.rtabmap;
2 
3 import java.io.BufferedInputStream;
4 import java.io.BufferedOutputStream;
5 import java.io.File;
6 import java.io.FileInputStream;
7 import java.io.FileOutputStream;
8 import java.io.FilenameFilter;
9 import java.io.IOException;
10 import java.util.Arrays;
11 import java.util.zip.ZipEntry;
12 import java.util.zip.ZipOutputStream;
13 
14 import android.content.Context;
15 import android.net.ConnectivityManager;
16 import android.net.NetworkInfo;
17 import android.util.Log;
18 
19 public class Util {
20 
21  public static final int ZIP_BUFFER_SIZE = 1<<20; // 1MB
22 
23  public static void zip(String file, String zipFile) throws IOException {
24  Log.i(RTABMapActivity.TAG, "Zipping " + file +" to " + zipFile);
25  String[] files = new String[1];
26  files[0] = file;
27  zip(files, zipFile);
28  }
29 
30  public static void zip(String[] files, String zipFile) throws IOException {
31  Log.i(RTABMapActivity.TAG, "Zipping " + String.valueOf(files.length) +" files to " + zipFile);
32  BufferedInputStream origin = null;
33  ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
34  try {
35  byte data[] = new byte[ZIP_BUFFER_SIZE];
36 
37  for (int i = 0; i < files.length; i++) {
38  FileInputStream fi = new FileInputStream(files[i]);
39  origin = new BufferedInputStream(fi, ZIP_BUFFER_SIZE);
40  try {
41  ZipEntry entry = new ZipEntry(files[i].substring(files[i].lastIndexOf("/") + 1));
42  out.putNextEntry(entry);
43  int count;
44  while ((count = origin.read(data, 0, ZIP_BUFFER_SIZE)) != -1) {
45  out.write(data, 0, count);
46  }
47  }
48  finally {
49  origin.close();
50  }
51  }
52  }
53  finally {
54  out.close();
55  }
56  }
57 
58  public static String[] loadFileList(String directory, final boolean databasesOnly) {
59  File path = new File(directory);
60  String fileList[];
61  try {
62  path.mkdirs();
63  }
64  catch(SecurityException e) {
65  Log.e(RTABMapActivity.TAG, "unable to write on the sd card " + e.toString());
66  }
67  if(path.exists()) {
68  FilenameFilter filter = new FilenameFilter() {
69 
70  @Override
71  public boolean accept(File dir, String filename) {
72  File sel = new File(dir, filename);
73  if(databasesOnly)
74  {
75  return filename.compareTo(RTABMapActivity.RTABMAP_TMP_DB) != 0 && filename.endsWith(".db");
76  }
77  else
78  {
79  return sel.isFile();
80  }
81  }
82 
83  };
84  fileList = path.list(filter);
85  Arrays.sort(fileList);
86  }
87  else {
88  fileList = new String[0];
89  }
90  return fileList;
91  }
92 
108  public static int versionCompare(String str1, String str2) {
109  String[] vals1 = str1.split("\\.");
110  String[] vals2 = str2.split("\\.");
111  int i = 0;
112  // set index to first non-equal ordinal or length of shortest version string
113  while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i])) {
114  i++;
115  }
116  // compare first non-equal ordinal number
117  if (i < vals1.length && i < vals2.length) {
118  int diff = Integer.valueOf(vals1[i]).compareTo(Integer.valueOf(vals2[i]));
119  return Integer.signum(diff);
120  }
121  // the strings are equal or one string is a substring of the other
122  // e.g. "1.2.3" = "1.2.3" or "1.2.3" < "1.2.3.4"
123  return Integer.signum(vals1.length - vals2.length);
124  }
125 
126 }
GLM_FUNC_DECL genType e()
static void zip(String file, String zipFile)
Definition: Util.java:23
static void zip(String[] files, String zipFile)
Definition: Util.java:30
static String[] loadFileList(String directory, final boolean databasesOnly)
Definition: Util.java:58
unsigned char byte
static final int ZIP_BUFFER_SIZE
Definition: Util.java:21
static int versionCompare(String str1, String str2)
Definition: Util.java:108


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Dec 14 2020 03:37:06