Example usage for android.os StatFs getBlockCount

List of usage examples for android.os StatFs getBlockCount

Introduction

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

Prototype

@Deprecated
public int getBlockCount() 

Source Link

Usage

From source file:Main.java

public static String getSavePath() {
    String savePath = null;//  w w w .j  a va2  s .c o  m
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        savePath = Environment.getExternalStorageDirectory().getAbsolutePath();
    } else {
        File[] files = new File("/mnt/").listFiles();
        if (files.length > 0) {
            String filePath = null;
            for (int p = 0; p < files.length; p++) {
                if (files[p].isDirectory()) {
                    if (files[p].getPath().indexOf("sdcard") >= 0) {
                        StatFs st = new StatFs(files[p].getPath());
                        int blocksize = st.getBlockSize();
                        int blockcount = st.getBlockCount();
                        if ((blocksize * blockcount) > 0) {
                            filePath = files[p].getPath();
                        }
                    }

                }
            }
            if (filePath != null) {
                savePath = filePath;
            } else {
                savePath = null;
            }
        }
    }
    return savePath;
}

From source file:Main.java

/**
 * the number of bytes on the filesystem rooted at the given File
 * /*w w w.  j  a  va2s .  co m*/
 * @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

@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:Main.java

@SuppressWarnings("unused")
public static long getTotalBytes(File dir) {
    if (!dir.exists() && !dir.mkdirs()) {
        return 0;
    }/*  www. j a  va2s . c o  m*/
    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

/**
 * Gets the free disk space at the specified location.
 *
 * @param dir//w  ww  . j  a  v  a 2  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:com.bt.download.android.util.SystemUtils.java

public static long calculateDiskCacheSize(File dir, int minSize, int maxSize) {
    long size = minSize;

    try {/*from www .  j  a v a2s. com*/
        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:Main.java

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

    try {/*  w  w w . j  a v  a2  s  .c o  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:com.squareup.picasso3.Utils.java

static long calculateDiskCacheSize(File dir) {
    long size = MIN_DISK_CACHE_SIZE;

    try {/*  ww w  . ja v  a  2  s  .  c  om*/
        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: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.//from  w w w  .j  ava  2 s. com
 *
 * @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:count.ly.messaging.CrashDetails.java

/**
 * Returns the current device disk space.
 *///from  www  .  ja  va 2  s. c om
static String getDiskTotal() {
    if (android.os.Build.VERSION.SDK_INT < 18) {
        StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
        long total = (statFs.getBlockCount() * statFs.getBlockSize());
        return Long.toString(total / 1048576L);
    } else {
        StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
        long total = (statFs.getBlockCountLong() * statFs.getBlockSizeLong());
        return Long.toString(total / 1048576L);
    }
}