List of usage examples for android.os StatFs getBlockSize
@Deprecated public int getBlockSize()
From source file:Main.java
/** * @return the number of bytes available on the filesystem rooted at the * given File//from w w w.j a v a2s .c o m */ @SuppressLint("NewApi") public static long getAvailableBytes(File root) { StatFs stat = new StatFs(root.getPath()); // put a bit of margin (in case creating the file grows the system by a // few blocks) if (android.os.Build.VERSION.SDK_INT < 18) { long availableBlocks = (long) stat.getAvailableBlocks() - 4; return stat.getBlockSize() * availableBlocks; } else { long availableBlocks = (long) stat.getAvailableBlocksLong() - 4; return stat.getBlockSizeLong() * availableBlocks; } }
From source file:com.addbean.autils.tools.OtherUtils.java
public static long getAvailableSpace(File dir) { try {//from ww w .ja v a 2 s. c om final StatFs stats = new StatFs(dir.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); } catch (Throwable e) { return -1; } }
From source file:net.tatans.rhea.network.view.OtherUtils.java
public static long getAvailableSpace(File dir) { try {/* w w w . jav a2 s. co m*/ final StatFs stats = new StatFs(dir.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); } catch (Throwable e) { TatansLogUtils.e(e.getMessage(), e); return -1; } }
From source file:com.bt.download.android.util.SystemUtils.java
public static long calculateDiskCacheSize(File dir, int minSize, int maxSize) { long size = minSize; try {/*from ww w.j av a2 s .c o m*/ StatFs statFs = new StatFs(dir.getAbsolutePath()); long 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, maxSize), minSize); }
From source file:cn.isif.util_plus.util.OtherUtils.java
public static long getAvailableSpace(File dir) { try {/*from w w w . j a v a2 s . c o m*/ final StatFs stats = new StatFs(dir.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); } catch (Throwable e) { LogUtils.e(e.getMessage(), e); return -1; } }
From source file:com.ddiiyy.xydz.xutils.util.OtherUtils.java
@SuppressWarnings("deprecation") public static long getAvailableSpace(File dir) { try {// www . j a v a2 s . com final StatFs stats = new StatFs(dir.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); } catch (Throwable e) { LogUtils.e(e.getMessage(), e); return -1; } }
From source file:com.android.volley.misc.Utils.java
/** * Check how much usable space is available at a given path. * //from w w w .j a va2 s .c o m * @param path * The path to check * @return The space available in bytes */ @SuppressWarnings("deprecation") @TargetApi(9) public static long getUsableSpace(File path) { if (Utils.hasGingerbread()) { return path.getUsableSpace(); } final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }
From source file:com.phonegap.DirectoryManager.java
/** * Get the free disk space on the SD card * //from w ww . j a v a2 s .co m * @return Size in KB or -1 if not available */ protected static long getFreeDiskSpace() { String status = Environment.getExternalStorageState(); long freeSpace = 0; // If SD card exists if (status.equals(Environment.MEDIA_MOUNTED)) { try { File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); freeSpace = availableBlocks * blockSize / 1024; } catch (Exception e) { e.printStackTrace(); } } // If no SD card, then return -1 else { return -1; } return (freeSpace); }
From source file:Main.java
static long calculateApiDiskCacheSize(File dir) { long size = MIN_DISK_API_CACHE_SIZE; try {/*from w w w.j av a2 s . c om*/ 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
public static boolean hasEnoughSpace(float needSize) { if (isSDCardExist()) { File path = Environment.getExternalStorageDirectory(); StatFs sf = new StatFs(path.getPath()); long blockSize; long availCount; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { blockSize = sf.getBlockSizeLong(); availCount = sf.getAvailableBlocksLong(); } else {/*from w ww .j av a 2 s . c o m*/ blockSize = sf.getBlockSize(); availCount = sf.getAvailableBlocks(); } long restSize = availCount * blockSize; if (restSize > needSize) { return true; } } return false; }