List of usage examples for android.os StatFs getBlockCountLong
public long getBlockCountLong()
From source file:Main.java
/** * Helper method to calculate the proper size limit of a cache instance. *///from w w w . j a v a 2 s . com public static long getCacheSizeInBytes(File dir, float cacheSizePercent, long maxSizeInBytes) { if (dir == null || (!dir.exists() && !dir.mkdir())) { return 0; } try { StatFs stat = new StatFs(dir.getPath()); long totalBytes = stat.getBlockCountLong() * stat.getBlockSizeLong(); long freeBytes = stat.getAvailableBlocksLong() * stat.getBlockSizeLong(); long desiredBytes = Math.min((long) (totalBytes * cacheSizePercent), maxSizeInBytes); // If free space is less than desired, use half of the free disk space instead. desiredBytes = (desiredBytes > freeBytes) ? freeBytes / 2 : desiredBytes; return desiredBytes; } catch (IllegalArgumentException e) { return 0; } }
From source file:Main.java
/** * Returns the amount of storage currently available in the cache. * * @param dir The cache directory path name. * @return The amount of storage available in bytes. */// w w w. jav a 2s .c o m public static long calculateDiskCacheSize(File dir) { long size = MIN_DISK_CACHE_SIZE; try { StatFs statFs = new StatFs(dir.getAbsolutePath()); long available = statFs.getBlockCountLong() * statFs.getBlockSizeLong(); // Target 2% of the total space. size = available * MAX_DISK_CACHE_AS_PERCENT / 100; } catch (IllegalArgumentException ignored) { } // Bound inside min/max size for disk cache. return Math.max(Math.min(size, MAX_DISK_CACHE_SIZE), MIN_DISK_CACHE_SIZE); }
From source file:Main.java
/** * ********************************************************************************************** * Returns size in MegaBytes./*from w w w .j av a2 s . c o m*/ * * @author Dan * <p/> * If you need calculate external memory, change this: StatFs statFs * = new StatFs(Environment.getRootDirectory().getAbsolutePath()); * to this: StatFs statFs = new * StatFs(Environment.getExternalStorageDirectory * ().getAbsolutePath()); * ************************************************************************************************ */ public static long TotalMemory() { StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath()); long Total = (statFs.getBlockCountLong() * statFs.getBlockSize()) / 1048576; return Total; }
From source file:Main.java
/** * Gets the free disk space at the specified location. * * @param dir/*w w w . j a v a2 s .com*/ * the directory linking to the filesystem to query * @return the free disk space at {@code dir} in bytes */ private static long getFreeDiskSpace(File dir) { StatFs statFs = new StatFs(dir.getAbsolutePath()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { return statFs.getBlockCountLong() * statFs.getBlockSizeLong(); } else { //noinspection deprecation return statFs.getBlockCount() * statFs.getBlockSize(); } }
From source file:Main.java
@SuppressWarnings("deprecation") @SuppressLint("NewApi") public static boolean getSDCardRemainCanWrite(Context context, long remainSize) { String path = getSDCardDataPath(context); StatFs statFS = new StatFs(path); long blockSize = 0L; if (getSDKInt() >= 18) { blockSize = statFS.getBlockCountLong(); } else {/* w w w . j a va2 s. c om*/ blockSize = statFS.getBlockSize(); } long availableBlock = 0L; if (getSDKInt() >= 18) { availableBlock = statFS.getAvailableBlocksLong(); } else { availableBlock = statFS.getAvailableBlocks(); } long size = blockSize * availableBlock; if (size > remainSize) { return true; } return false; }
From source file:Main.java
static long calculateApiDiskCacheSize(File dir) { long size = MIN_DISK_API_CACHE_SIZE; try {//from w ww . j ava2 s.co m StatFs statFs = new StatFs(dir.getAbsolutePath()); long available; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { available = statFs.getBlockCountLong() * statFs.getBlockSizeLong(); } else { available = ((long) statFs.getBlockCount()) * statFs.getBlockSize(); } // Target 2% of the total space. size = available / 50; } catch (IllegalArgumentException ignored) { } // Bound inside min/max size for disk cache. return Math.max(Math.min(size, MAX_DISK_API_CACHE_SIZE), MIN_DISK_API_CACHE_SIZE); }
From source file:Main.java
/** * Calculates the total memory of the device. This is based on an inspection of the filesystem, which in android * devices is stored in RAM.// w ww.java 2 s. co m * * @return Total number of bytes. */ public static long getTotalInternalMemorySize() { final File path = Environment.getDataDirectory(); final StatFs stat = new StatFs(path.getPath()); final long blockSize; final long totalBlocks; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { blockSize = stat.getBlockSizeLong(); totalBlocks = stat.getBlockCountLong(); } else { //noinspection deprecation blockSize = stat.getBlockSize(); //noinspection deprecation totalBlocks = stat.getBlockCount(); } return totalBlocks * blockSize; }
From source file:Main.java
@SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) private static long getAvailable(final File dir) { final StatFs statFs = new StatFs(dir.getAbsolutePath()); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { return ((long) statFs.getBlockCount()) * statFs.getBlockSize(); }// w w w .j a v a 2 s . c o m return statFs.getBlockCountLong() * statFs.getBlockSizeLong(); }
From source file:com.squareup.picasso3.Utils.java
static long calculateDiskCacheSize(File dir) { long size = MIN_DISK_CACHE_SIZE; try {/* ww w . j a v a2 s . c o m*/ StatFs statFs = new StatFs(dir.getAbsolutePath()); //noinspection deprecation long blockCount = SDK_INT < JELLY_BEAN_MR2 ? (long) statFs.getBlockCount() : statFs.getBlockCountLong(); //noinspection deprecation long blockSize = SDK_INT < JELLY_BEAN_MR2 ? (long) statFs.getBlockSize() : statFs.getBlockSizeLong(); long available = blockCount * blockSize; // Target 2% of the total space. size = available / 50; } catch (IllegalArgumentException ignored) { } // Bound inside min/max size for disk cache. return Math.max(Math.min(size, MAX_DISK_CACHE_SIZE), MIN_DISK_CACHE_SIZE); }
From source file:mx.klozz.xperience.tweaker.fragments.DiskInfo.java
public static long Totalbytes(File f) { StatFs stat = new StatFs(f.getPath()); //return (long) stat.getBlockSize() * (long) stat.getBlockCount(); Deprecated xD the same of the last :) return stat.getBlockSizeLong() * stat.getBlockCountLong(); }