FileUtilities.java
Go to the documentation of this file.
1 package com.intel.realsense.camera;
2 
3 import android.content.Context;
4 import android.os.Handler;
5 import android.util.Log;
6 
7 import java.io.File;
8 import java.io.FileOutputStream;
9 
10 public class FileUtilities {
11 
12  private static final String TAG = "file_utilities";
13 
14  private final static Handler mHandler = new Handler();
15  private static Thread mUiThread;
16 
17  public static final void runOnUiThread(Runnable action) {
18  if (Thread.currentThread() != mUiThread) {
19  mHandler.post(action);
20  } else {
21  action.run();
22  }
23  }
24 
25  public static String getExternalStorageDir(Context context) {
26  return context.getExternalFilesDir(null).getAbsolutePath();
27  }
28 
29  public static void saveFileToExternalDir(Context context, final String fileName, byte[] data) {
30  try {
31  File file = new File(context.getExternalFilesDir(null) + File.separator + fileName);
32  FileOutputStream fos = new FileOutputStream(file);
33  fos.write(data);
34  Log.i(TAG, "saveFileToExternalDir: file " + fileName + " saved successfully");
35  } catch (Exception e) {
36  Log.e(TAG, "saveFileToExternalDir: failed to create a file " + fileName, e);
37  }
38  }
39 
40  public static boolean isPathEmpty(String path) {
41  try {
42  File folder = new File(path);
43  if (!folder.exists()) {
44  return true;
45  }
46  final File[] files = folder.listFiles();
47  if (files.length == 0)
48  return true;
49  } catch (Exception e) {
50  return true;
51  }
52  return false;
53  }
54 }
::rosgraph_msgs::Log_< std::allocator< void > > Log
Definition: Log.h:88
GLsizei const GLchar *const * path
Definition: glext.h:4276
e
Definition: rmse.py:177
::std_msgs::String_< std::allocator< void > > String
Definition: String.h:47
static void saveFileToExternalDir(Context context, final String fileName, byte[] data)
files_container files
static String getExternalStorageDir(Context context)
action
Definition: enums.py:62
static final void runOnUiThread(Runnable action)
unsigned char byte
Definition: src/types.h:52
static boolean isPathEmpty(String path)
Definition: threads.c:40
Definition: parser.hpp:150


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:14