Java Code Examples for io.vov.vitamio.utils.FileUtils#getCanonical()

The following examples show how to use io.vov.vitamio.utils.FileUtils#getCanonical() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MediaScanner.java    From MyHearts with Apache License 2.0 4 votes vote down vote up
private void prescan(String filePath) throws RemoteException {
  mProvider = mContext.getContentResolver().acquireContentProviderClient(MediaStore.AUTHORITY);
  Cursor c = null;
  String where = null;
  String[] selectionArgs = null;

  if (mFileCache == null)
    mFileCache = new HashMap<String, FileCacheEntry>();
  else
    mFileCache.clear();

  try {
    if (filePath != null) {
      where = Video.Media.DATA + "=?";
      selectionArgs = new String[]{filePath};
    }

    c = mProvider.query(Video.Media.CONTENT_URI, VIDEO_PROJECTION, where, selectionArgs, null);
    if (c != null) {
      try {
        while (c.moveToNext()) {
          long rowId = c.getLong(ID_VIDEO_COLUMN_INDEX);
          String path = c.getString(PATH_VIDEO_COLUMN_INDEX);
          long lastModified = c.getLong(DATE_MODIFIED_VIDEO_COLUMN_INDEX);
          if (path.startsWith("/")) {
            File tempFile = new File(path);
            if (!TextUtils.isEmpty(filePath) && !tempFile.exists()) {
              mProvider.delete(Video.Media.CONTENT_URI, where, selectionArgs);
              return;
            }
            path = FileUtils.getCanonical(tempFile);
            String key = mCaseInsensitivePaths ? path.toLowerCase() : path;
            mFileCache.put(key, new FileCacheEntry(Video.Media.CONTENT_URI, rowId, path, lastModified));
          }
        }
      } finally {
        c.close();
        c = null;
      }
    }
  } finally {
    if (c != null) {
      c.close();
    }
  }
}
 
Example 2
Source File: MediaScanner.java    From HPlayer with Apache License 2.0 4 votes vote down vote up
private void prescan(String filePath) throws RemoteException {
  mProvider = mContext.getContentResolver().acquireContentProviderClient(MediaStore.AUTHORITY);
  Cursor c = null;
  String where = null;
  String[] selectionArgs = null;

  if (mFileCache == null)
    mFileCache = new HashMap<String, FileCacheEntry>();
  else
    mFileCache.clear();

  try {
    if (filePath != null) {
      where = Video.Media.DATA + "=?";
      selectionArgs = new String[]{filePath};
    }

    c = mProvider.query(Video.Media.CONTENT_URI, VIDEO_PROJECTION, where, selectionArgs, null);
    if (c != null) {
      try {
        while (c.moveToNext()) {
          long rowId = c.getLong(ID_VIDEO_COLUMN_INDEX);
          String path = c.getString(PATH_VIDEO_COLUMN_INDEX);
          long lastModified = c.getLong(DATE_MODIFIED_VIDEO_COLUMN_INDEX);
          if (path.startsWith("/")) {
            File tempFile = new File(path);
            if (!TextUtils.isEmpty(filePath) && !tempFile.exists()) {
              mProvider.delete(Video.Media.CONTENT_URI, where, selectionArgs);
              return;
            }
            path = FileUtils.getCanonical(tempFile);
            String key = mCaseInsensitivePaths ? path.toLowerCase() : path;
            mFileCache.put(key, new FileCacheEntry(Video.Media.CONTENT_URI, rowId, path, lastModified));
          }
        }
      } finally {
        c.close();
        c = null;
      }
    }
  } finally {
    if (c != null) {
      c.close();
    }
  }
}
 
Example 3
Source File: MediaScanner.java    From video-player with MIT License 4 votes vote down vote up
private void prescan(String filePath) throws RemoteException {
  mProvider = mContext.getContentResolver().acquireContentProviderClient(MediaStore.AUTHORITY);
  Cursor c = null;
  String where = null;
  String[] selectionArgs = null;

  if (mFileCache == null)
    mFileCache = new HashMap<String, FileCacheEntry>();
  else
    mFileCache.clear();

  try {
    if (filePath != null) {
      where = Video.Media.DATA + "=?";
      selectionArgs = new String[]{filePath};
    }

    c = mProvider.query(Video.Media.CONTENT_URI, VIDEO_PROJECTION, where, selectionArgs, null);
    if (c != null) {
      try {
        while (c.moveToNext()) {
          long rowId = c.getLong(ID_VIDEO_COLUMN_INDEX);
          String path = c.getString(PATH_VIDEO_COLUMN_INDEX);
          long lastModified = c.getLong(DATE_MODIFIED_VIDEO_COLUMN_INDEX);
          if (path.startsWith("/")) {
            File tempFile = new File(path);
            if (!TextUtils.isEmpty(filePath) && !tempFile.exists()) {
              mProvider.delete(Video.Media.CONTENT_URI, where, selectionArgs);
              return;
            }
            path = FileUtils.getCanonical(tempFile);
            String key = mCaseInsensitivePaths ? path.toLowerCase() : path;
            mFileCache.put(key, new FileCacheEntry(Video.Media.CONTENT_URI, rowId, path, lastModified));
          }
        }
      } finally {
        c.close();
        c = null;
      }
    }
  } finally {
    if (c != null) {
      c.close();
    }
  }
}
 
Example 4
Source File: MediaScanner.java    From NetEasyNews with GNU General Public License v3.0 4 votes vote down vote up
private void prescan(String filePath) throws RemoteException {
  mProvider = mContext.getContentResolver().acquireContentProviderClient(MediaStore.AUTHORITY);
  Cursor c = null;
  String where = null;
  String[] selectionArgs = null;

  if (mFileCache == null)
    mFileCache = new HashMap<String, FileCacheEntry>();
  else
    mFileCache.clear();

  try {
    if (filePath != null) {
      where = Video.Media.DATA + "=?";
      selectionArgs = new String[]{filePath};
    }

    c = mProvider.query(Video.Media.CONTENT_URI, VIDEO_PROJECTION, where, selectionArgs, null);
    if (c != null) {
      try {
        while (c.moveToNext()) {
          long rowId = c.getLong(ID_VIDEO_COLUMN_INDEX);
          String path = c.getString(PATH_VIDEO_COLUMN_INDEX);
          long lastModified = c.getLong(DATE_MODIFIED_VIDEO_COLUMN_INDEX);
          if (path.startsWith("/")) {
            File tempFile = new File(path);
            if (!TextUtils.isEmpty(filePath) && !tempFile.exists()) {
              mProvider.delete(Video.Media.CONTENT_URI, where, selectionArgs);
              return;
            }
            path = FileUtils.getCanonical(tempFile);
            String key = mCaseInsensitivePaths ? path.toLowerCase() : path;
            mFileCache.put(key, new FileCacheEntry(Video.Media.CONTENT_URI, rowId, path, lastModified));
          }
        }
      } finally {
        c.close();
        c = null;
      }
    }
  } finally {
    if (c != null) {
      c.close();
    }
  }
}
 
Example 5
Source File: MediaScanner.java    From react-native-android-vitamio with MIT License 4 votes vote down vote up
private void prescan(String filePath) throws RemoteException {
  mProvider = mContext.getContentResolver().acquireContentProviderClient(MediaStore.AUTHORITY);
  Cursor c = null;
  String where = null;
  String[] selectionArgs = null;

  if (mFileCache == null)
    mFileCache = new HashMap<String, FileCacheEntry>();
  else
    mFileCache.clear();

  try {
    if (filePath != null) {
      where = Video.Media.DATA + "=?";
      selectionArgs = new String[]{filePath};
    }

    c = mProvider.query(Video.Media.CONTENT_URI, VIDEO_PROJECTION, where, selectionArgs, null);
    if (c != null) {
      try {
        while (c.moveToNext()) {
          long rowId = c.getLong(ID_VIDEO_COLUMN_INDEX);
          String path = c.getString(PATH_VIDEO_COLUMN_INDEX);
          long lastModified = c.getLong(DATE_MODIFIED_VIDEO_COLUMN_INDEX);
          if (path.startsWith("/")) {
            File tempFile = new File(path);
            if (!TextUtils.isEmpty(filePath) && !tempFile.exists()) {
              mProvider.delete(Video.Media.CONTENT_URI, where, selectionArgs);
              return;
            }
            path = FileUtils.getCanonical(tempFile);
            String key = mCaseInsensitivePaths ? path.toLowerCase() : path;
            mFileCache.put(key, new FileCacheEntry(Video.Media.CONTENT_URI, rowId, path, lastModified));
          }
        }
      } finally {
        c.close();
        c = null;
      }
    }
  } finally {
    if (c != null) {
      c.close();
    }
  }
}
 
Example 6
Source File: MediaScanner.java    From Vitamio with Apache License 2.0 4 votes vote down vote up
private void prescan(String filePath) throws RemoteException {
  mProvider = mContext.getContentResolver().acquireContentProviderClient(MediaStore.AUTHORITY);
  Cursor c = null;
  String where = null;
  String[] selectionArgs = null;

  if (mFileCache == null)
    mFileCache = new HashMap<String, FileCacheEntry>();
  else
    mFileCache.clear();

  try {
    if (filePath != null) {
      where = Video.Media.DATA + "=?";
      selectionArgs = new String[]{filePath};
    }

    c = mProvider.query(Video.Media.CONTENT_URI, VIDEO_PROJECTION, where, selectionArgs, null);
    if (c != null) {
      try {
        while (c.moveToNext()) {
          long rowId = c.getLong(ID_VIDEO_COLUMN_INDEX);
          String path = c.getString(PATH_VIDEO_COLUMN_INDEX);
          long lastModified = c.getLong(DATE_MODIFIED_VIDEO_COLUMN_INDEX);
          if (path.startsWith("/")) {
            File tempFile = new File(path);
            if (!TextUtils.isEmpty(filePath) && !tempFile.exists()) {
              mProvider.delete(Video.Media.CONTENT_URI, where, selectionArgs);
              return;
            }
            path = FileUtils.getCanonical(tempFile);
            String key = mCaseInsensitivePaths ? path.toLowerCase() : path;
            mFileCache.put(key, new FileCacheEntry(Video.Media.CONTENT_URI, rowId, path, lastModified));
          }
        }
      } finally {
        c.close();
        c = null;
      }
    }
  } finally {
    if (c != null) {
      c.close();
    }
  }
}
 
Example 7
Source File: MediaScanner.java    From BambooPlayer with Apache License 2.0 4 votes vote down vote up
private void prescan(String filePath) throws RemoteException {
  mProvider = mContext.getContentResolver().acquireContentProviderClient(MediaStore.AUTHORITY);
  Cursor c = null;
  String where = null;
  String[] selectionArgs = null;

  if (mFileCache == null)
    mFileCache = new HashMap<String, FileCacheEntry>();
  else
    mFileCache.clear();

  try {
    if (filePath != null) {
      where = Video.Media.DATA + "=?";
      selectionArgs = new String[]{filePath};
    }

    c = mProvider.query(Video.Media.CONTENT_URI, VIDEO_PROJECTION, where, selectionArgs, null);
    if (c != null) {
      try {
        while (c.moveToNext()) {
          long rowId = c.getLong(ID_VIDEO_COLUMN_INDEX);
          String path = c.getString(PATH_VIDEO_COLUMN_INDEX);
          long lastModified = c.getLong(DATE_MODIFIED_VIDEO_COLUMN_INDEX);
          if (path.startsWith("/")) {
            File tempFile = new File(path);
            if (!TextUtils.isEmpty(filePath) && !tempFile.exists()) {
              mProvider.delete(Video.Media.CONTENT_URI, where, selectionArgs);
              return;
            }
            path = FileUtils.getCanonical(tempFile);
            String key = mCaseInsensitivePaths ? path.toLowerCase() : path;
            mFileCache.put(key, new FileCacheEntry(Video.Media.CONTENT_URI, rowId, path, lastModified));
          }
        }
      } finally {
        c.close();
        c = null;
      }
    }
  } finally {
    if (c != null) {
      c.close();
    }
  }
}