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.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;
17 
18 import android.content.Context;
19 import android.net.ConnectivityManager;
20 import android.net.NetworkInfo;
21 import android.util.Log;
22 
23 public class Util {
24 
25  public static final int ZIP_BUFFER_SIZE = 1<<20; // 1MB
26 
27  public static void zip(String file, String zipFile) throws IOException {
28  Log.i(RTABMapActivity.TAG, "Zipping " + file +" to " + zipFile);
29  String[] files = new String[1];
30  files[0] = file;
31  zip(files, zipFile);
32  }
33 
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)));
38  try {
39  byte data[] = new byte[ZIP_BUFFER_SIZE];
40 
41  for (int i = 0; i < files.length; i++) {
42  FileInputStream fi = new FileInputStream(files[i]);
43  origin = new BufferedInputStream(fi, ZIP_BUFFER_SIZE);
44  try {
45  ZipEntry entry = new ZipEntry(files[i].substring(files[i].lastIndexOf("/") + 1));
46  out.putNextEntry(entry);
47  int count;
48  while ((count = origin.read(data, 0, ZIP_BUFFER_SIZE)) != -1) {
49  out.write(data, 0, count);
50  }
51  }
52  finally {
53  origin.close();
54  }
55  }
56  }
57  finally {
58  out.close();
59  }
60  }
61 
62  public static String[] loadFileList(final String directory, final boolean databasesOnly) {
63  File path = new File(directory);
64  String fileList[];
65  try {
66  path.mkdirs();
67  }
68  catch(SecurityException e) {
69  Log.e(RTABMapActivity.TAG, "unable to write on the sd card " + e.toString());
70  }
71  if(path.exists()) {
72  FilenameFilter filter = new FilenameFilter() {
73 
74  @Override
75  public boolean accept(File dir, String filename) {
76  File sel = new File(dir, filename);
77  if(databasesOnly)
78  {
79  return filename.compareTo(RTABMapActivity.RTABMAP_TMP_DB) != 0 && filename.endsWith(".db");
80  }
81  else
82  {
83  return sel.isFile();
84  }
85  }
86 
87  };
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>() {
92 
93  @Override
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();
98  if(k > 0){
99  return -1;
100  }else if(k == 0){
101  return 0;
102  }else{
103  return 1;
104  }
105  }
106  });
107  fileListt.toArray(fileList);
108 
109  }
110  else {
111  fileList = new String[0];
112  }
113  return fileList;
114  }
115 
131  public static int versionCompare(String str1, String str2) {
132  String[] vals1 = str1.split("\\.");
133  String[] vals2 = str2.split("\\.");
134  int i = 0;
135  // set index to first non-equal ordinal or length of shortest version string
136  while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i])) {
137  i++;
138  }
139  // compare first non-equal ordinal number
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);
143  }
144  // the strings are equal or one string is a substring of the other
145  // e.g. "1.2.3" = "1.2.3" or "1.2.3" < "1.2.3.4"
146  return Integer.signum(vals1.length - vals2.length);
147  }
148 
149 }
com.introlab.rtabmap.RTABMapActivity.TAG
static final String TAG
Definition: RTABMapActivity.java:113
compare
bool compare
com.introlab.rtabmap.Util.versionCompare
static int versionCompare(String str1, String str2)
Definition: Util.java:131
com.introlab.rtabmap.Util.ZIP_BUFFER_SIZE
static final int ZIP_BUFFER_SIZE
Definition: Util.java:25
com.introlab.rtabmap.Util.loadFileList
static String[] loadFileList(final String directory, final boolean databasesOnly)
Definition: Util.java:62
count
Index count
com.introlab.rtabmap.Util.zip
static void zip(String file, String zipFile)
Definition: Util.java:27
data
int data[]
filename
filename
com.introlab.rtabmap.Util
Definition: Util.java:23
com.introlab.rtabmap.Util.zip
static void zip(String[] files, String zipFile)
Definition: Util.java:34
out
std::ofstream out("Result.txt")
path
path
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
origin
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set origin
diff
diff
com.introlab.rtabmap.RTABMapActivity.RTABMAP_TMP_DB
static final String RTABMAP_TMP_DB
Definition: RTABMapActivity.java:125
file
file
i
int i
com.introlab.rtabmap.RTABMapActivity
Definition: RTABMapActivity.java:107


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:23