Example usage for android.os StatFs getBlockSizeLong

List of usage examples for android.os StatFs getBlockSizeLong

Introduction

In this page you can find the example usage for android.os StatFs getBlockSizeLong.

Prototype

public long getBlockSizeLong() 

Source Link

Document

The size, in bytes, of a block on the file system.

Usage

From source file:Main.java

static long calculateApiDiskCacheSize(File dir) {
    long size = MIN_DISK_API_CACHE_SIZE;

    try {/*from   ww w.  j  a  va 2s . 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

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  w w.  ja  va2  s.  c  o m
            blockSize = sf.getBlockSize();
            availCount = sf.getAvailableBlocks();
        }

        long restSize = availCount * blockSize;
        if (restSize > needSize) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public static Boolean hasExternalStorageFreeMemory() {
    StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
    double sdAvailSize;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        sdAvailSize = (double) stat.getAvailableBlocksLong() * (double) stat.getBlockSizeLong();
    } else {//from  w  w  w. ja va  2s.  co m
        sdAvailSize = (double) stat.getAvailableBlocks() * (double) stat.getBlockSize();
    }

    return sdAvailSize >= 10 * SIZE_MB;
}

From source file:Main.java

@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public static long getExternalStorageFreeMemory() {
    StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
    double sdAvailSize;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        sdAvailSize = (double) stat.getAvailableBlocksLong() * (double) stat.getBlockSizeLong();
    } else {/*from  w w  w  .  j av  a 2s .  c o m*/
        sdAvailSize = (double) stat.getAvailableBlocks() * (double) stat.getBlockSize();
    }

    return Math.round(sdAvailSize / SIZE_MB);
}

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();
    }/*from   w  ww .  ja v  a 2  s  .c o  m*/
    return statFs.getBlockCountLong() * statFs.getBlockSizeLong();
}

From source file:com.callrecorder.android.FileHelper.java

@SuppressWarnings("deprecation")
public static long getFreeSpaceAvailable(String path) {
    StatFs stat = new StatFs(path);
    long availableBlocks;
    long blockSize;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        availableBlocks = stat.getAvailableBlocksLong();
        blockSize = stat.getBlockSizeLong();
    } else {// w  ww  .  ja  v a  2  s .com
        availableBlocks = stat.getAvailableBlocks();
        blockSize = stat.getBlockSize();
    }
    return availableBlocks * blockSize;
}

From source file:Main.java

@SuppressLint("NewApi")
public static long getSDCardAvailableSize() {
    if (isSDCardEnable()) {
        StatFs statFs = new StatFs(
                Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator);
        if (android.os.Build.VERSION.SDK_INT < 18) {
            int blockSize = statFs.getBlockSize();
            int blockCount = statFs.getAvailableBlocks();
            return blockCount * blockSize;
        } else {/*  ww w. j  a v  a2  s .  com*/
            long blockSize = statFs.getBlockSizeLong();
            long blockCount = statFs.getAvailableBlocksLong();
            return blockCount * blockSize;
        }
    }
    return -1;
}

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();
}

From source file:Main.java

/**
 * @return the number of bytes available on the filesystem rooted at the
 *         given File//from w  w  w . j ava2s.  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:mx.klozz.xperience.tweaker.fragments.DiskInfo.java

public static long Freebytes(File f) {
    StatFs stat = new StatFs(f.getPath());
    //return (long) stat.getBlockSizeLong() * (long) stat.getAvailableBlocksLong(); <-- deprecated :) now can unse LONG in name
    return stat.getBlockSizeLong() * stat.getAvailableBlocksLong();
}