List of usage examples for android.os StatFs StatFs
public StatFs(String path)
From source file:com.androidpi.bricks.gallery.lru.cache.ImageCache.java
/** * Check how much usable space is available at a given path. * * @param path The path to check/*from w w w . j a v a 2s .c o m*/ * @return The space available in bytes */ @TargetApi(VERSION_CODES.GINGERBREAD) public static long getUsableSpace(File path) { if (AppUtil.hasGingerbread()) { return path.getUsableSpace(); } final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }
From source file:it.feio.android.omninotes.utils.StorageManager.java
/** * Returns a directory size in bytes//from ww w.ja v a 2 s.c om * @param directory * @return */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") public static long getSize(File directory) { StatFs statFs = new StatFs(directory.getAbsolutePath()); long blockSize = 0; try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { blockSize = statFs.getBlockSizeLong(); } else { blockSize = statFs.getBlockSize(); } // Can't understand why on some devices this fails } catch (NoSuchMethodError e) { } return getSize(directory, blockSize); }
From source file:eu.geopaparazzi.library.util.Utilities.java
/** * Get the megabytes available in the filesystem at 'file'. * * @param file the filesystem's path./* w w w . j a v a 2s . c o m*/ * @return the available space in mb. */ public static float getAvailableMegabytes(File file) { StatFs stat = new StatFs(file.getPath()); long bytesAvailable = (long) stat.getBlockSize() * (long) stat.getAvailableBlocks(); return bytesAvailable / (1024.f * 1024.f); }
From source file:fr.sedona.volley.manager.HttpImageLoader.java
@SuppressLint("NewApi") private long getDiskCacheSpace(Context context) { String cachePath = context.getCacheDir().getPath(); File diskCacheDir = new File(cachePath); if (Build.VERSION.SDK_INT >= 9) { return Math.min(diskCacheDir.getFreeSpace() - (1024 * 1024 * 30), (long) 1024 * 1024 * 20); }/*from w w w . j a v a 2 s . c o m*/ StatFs statFs = new StatFs(diskCacheDir.getAbsolutePath()); return (long) Math.min(statFs.getAvailableBlocks() * (long) statFs.getBlockSize() - (1024 * 1024 * 30), (long) 1024 * 1024 * 20); }
From source file:org.mozilla.gecko.GeckoAppShell.java
public static long getFreeSpace() { try {//from w w w . j a v a2s . co m if (sFreeSpace == -1) { File cacheDir = getCacheDir(); if (cacheDir != null) { StatFs cacheStats = new StatFs(cacheDir.getPath()); sFreeSpace = cacheStats.getFreeBlocks() * cacheStats.getBlockSize(); } else { Log.i(LOGTAG, "Unable to get cache dir"); } } } catch (Exception e) { Log.e(LOGTAG, "exception while stating cache dir: ", e); } return sFreeSpace; }
From source file:eu.geopaparazzi.library.util.Utilities.java
/** * Get the size in megabytes of the filesystem at 'file'. * * @param file the filesystem's path./*w w w . jav a 2s .co m*/ * @return the size in mb. */ public static float getFilesystemMegabytes(File file) { StatFs stat = new StatFs(file.getPath()); long bytes = (long) stat.getBlockSize() * (long) stat.getBlockCount(); return bytes / (1024.f * 1024.f); }
From source file:com.cyberocw.habittodosecretary.file.StorageHelper.java
/** * Returns a directory size in bytes/*from w ww .j a v a 2 s .co m*/ */ @SuppressWarnings("deprecation") public static long getSize(File directory) { StatFs statFs = new StatFs(directory.getAbsolutePath()); long blockSize = 0; try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { blockSize = statFs.getBlockSizeLong(); } else { blockSize = statFs.getBlockSize(); } // Can't understand why on some devices this fails } catch (NoSuchMethodError e) { Log.e(Const.ERROR_TAG, "Mysterious error", e); } return getSize(directory, blockSize); }
From source file:com.intelerad.android.portal.ImageCache.java
/** * Check how much usable space is available at a given path. * //w w w . java 2s . c o m * @param path The path to check * @return The space available in bytes */ @TargetApi(Build.VERSION_CODES.GINGERBREAD) public static long getUsableSpace(File path) { if (UiUtils.hasGingerbread()) { return path.getUsableSpace(); } final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }
From source file:com.colorchen.qbase.utils.FileUtil.java
/** * ???.//from w ww . j a v a2 s .c o m */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") public static long getSDCardAvailaleSize() { File path = getRootPath(); StatFs stat = new StatFs(path.getPath()); long blockSize, availableBlocks; if (Build.VERSION.SDK_INT >= 18) { blockSize = stat.getBlockSizeLong(); availableBlocks = stat.getAvailableBlocksLong(); } else { blockSize = stat.getBlockSize(); availableBlocks = stat.getAvailableBlocks(); } return availableBlocks * blockSize; }
From source file:gr.unfold.android.tsibato.images.ImageCache.java
@TargetApi(9) public static long getUsableSpace(File path) { if (Utils.hasGingerbread()) { return path.getUsableSpace(); }//from ww w.j a va2s .c o m final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }