Example usage for android.os StatFs getBlockSize

List of usage examples for android.os StatFs getBlockSize

Introduction

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

Prototype

@Deprecated
public int getBlockSize() 

Source Link

Usage

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  om
 */
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)
    long availableBlocks = (long) stat.getAvailableBlocks() - 4;
    return stat.getBlockSize() * availableBlocks;
}

From source file:org.dkf.jmule.util.SystemUtils.java

public static long getAvailableStorageSize(File dir) {
    long size;//from   w  w w.j a  v  a 2  s  . c  o  m
    try {
        StatFs stat = new StatFs(dir.getAbsolutePath());
        size = ((long) stat.getAvailableBlocks()) * stat.getBlockSize();
    } catch (Exception e) {
        size = -1; // system error computing the available storage size
    }

    return size;
}

From source file:com.scsy150.util.OtherUtils.java

public static long getAvailableSpace(File dir) {
    try {//ww  w. j  a  v a 2 s .  c  o  m
        final StatFs stats = new StatFs(dir.getPath());
        return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
    } catch (Throwable e) {
        LogUtil.e("", e.getMessage());
        return -1;
    }

}

From source file:Main.java

@SuppressWarnings("unused")
public static long getTotalBytes(File dir) {
    if (!dir.exists() && !dir.mkdirs()) {
        return 0;
    }/* w ww.  jav a 2s .  c om*/
    StatFs dirStatFs = new StatFs(dir.getPath());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return dirStatFs.getTotalBytes();
    } else {
        //noinspection deprecation
        return (long) dirStatFs.getBlockCount() * dirStatFs.getBlockSize();
    }
}

From source file:Main.java

/**
 * the number of bytes on the filesystem rooted at the given File
 * //w  w w. ja  va 2  s  . com
 * @param root
 *            root file dir.
 * @return the number of bytes available on the filesystem rooted at the
 *         given File
 */
public static long getTotaltes(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)
    long availableBlocks = (long) stat.getBlockCount() - 4; // SUPPRESS
    // CHECKSTYLE //
    // CHECKSTYLE
    return stat.getBlockSize() * availableBlocks;
}

From source file:Main.java

/**
 * Gets the free disk space at the specified location.
 *
 * @param dir//from   w  ww.  j  a v  a 2 s. co  m
 *         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("WeakerAccess")
public static long getAvailableBytes(File dir) {
    if (!dir.exists() && !dir.mkdirs()) {
        return 0;
    }// w ww .  java  2s . co m
    StatFs dirStatFs = new StatFs(dir.getPath());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return dirStatFs.getAvailableBytes();
    } else {
        //noinspection deprecation
        return (long) dirStatFs.getAvailableBlocks() * dirStatFs.getBlockSize();
    }
}

From source file:com.bt.download.android.util.SystemUtils.java

public static long getAvailableStorageSize(File dir) {
    long size = -1;
    try {/* www  .ja  va2  s  .co  m*/
        StatFs stat = new StatFs(dir.getAbsolutePath());
        size = ((long) stat.getAvailableBlocks()) * stat.getBlockSize();
    } catch (Throwable e) {
        size = -1; // system error computing the available storage size
    }

    return size;
}

From source file:com.frostwire.android.util.SystemUtils.java

public static long getCurrentMountAvailableBytes() {
    StatFs stat = new StatFs(ConfigurationManager.instance().getStoragePath());
    return ((long) stat.getBlockSize() * (long) stat.getAvailableBlocks());
}

From source file:com.lidroid.util.OtherUtils.java

public static long getAvailableSpace(File dir) {
    try {//from w ww. j a  v a  2 s.c om
        final StatFs stats = new StatFs(dir.getPath());
        return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
    } catch (Throwable e) {
        Logger.e(e.getMessage(), e);
        return -1;
    }

}