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:com.pdftron.pdf.utils.Utils.java

public static String copyResourceToTempFolder(Context context, int resId, boolean force, String resourceName)
        throws PDFNetException {
    if (context == null) {
        throw new PDFNetException("", 0L, "com.pdftron.pdf.PDFNet", "copyResourceToTempFolder()",
                "Context cannot be null to initialize resource file.");
    } else {//  w ww .  ja  v  a2s.  c  o m
        File resFile = new File(context.getFilesDir() + File.separator + "resourceName");
        if (!resFile.exists() || force) {
            File filesDir = context.getFilesDir();
            StatFs stat = new StatFs(filesDir.getPath());
            long size = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
            if (size < 2903023L) {
                throw new PDFNetException("", 0L, "com.pdftron.pdf.PDFNet", "copyResourceToTempFolder()",
                        "Not enough space available to copy resources file.");
            }

            Resources rs = context.getResources();

            try {
                InputStream e = rs.openRawResource(resId);
                FileOutputStream fos = context.openFileOutput(resourceName, 0);
                byte[] buffer = new byte[1024];

                int read;
                while ((read = e.read(buffer)) != -1) {
                    fos.write(buffer, 0, read);
                }

                e.close();
                fos.flush();
                fos.close();

            } catch (Resources.NotFoundException var13) {
                throw new PDFNetException("", 0L, "com.pdftron.pdf.PDFNet", "initializeResource()",
                        "Resource file ID does not exist.");
            } catch (FileNotFoundException var14) {
                throw new PDFNetException("", 0L, "com.pdftron.pdf.PDFNet", "initializeResource()",
                        "Resource file not found.");
            } catch (IOException var15) {
                throw new PDFNetException("", 0L, "com.pdftron.pdf.PDFNet", "initializeResource()",
                        "Error writing resource file to internal storage.");
            } catch (Exception var16) {
                throw new PDFNetException("", 0L, "com.pdftron.pdf.PDFNet", "initializeResource()",
                        "Unknown error.");
            }
        }

        return context.getFilesDir().getAbsolutePath();
    }
}

From source file:com.almalence.util.Util.java

public static long FreeDeviceMemory() {
    StatFs statFs = new StatFs(Environment.getDataDirectory().getPath());
    long blockSize = statFs.getBlockSize();
    long availableBloks = statFs.getAvailableBlocks();
    return (availableBloks * blockSize) / 1048576;
}

From source file:com.almalence.util.Util.java

/*************************************************************************************************
 * Returns size in MegaBytes.// w w  w.ja v  a 2s. c  o  m
 * 
 * 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 TotalDeviceMemory() {
    StatFs statFs = new StatFs(Environment.getDataDirectory().getPath());
    long blockSize = statFs.getBlockSize();
    long blockCount = statFs.getBlockCount();
    return (blockCount * blockSize) / 1048576;
}

From source file:com.almalence.util.Util.java

public static long TotalExternalMemory() {
    StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getPath());
    long blockSize = statFs.getBlockSize();
    long blockCount = statFs.getBlockCount();
    return (blockCount * blockSize) / 1048576;
}

From source file:com.almalence.util.Util.java

public static long FreeExternalMemory() {
    StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getPath());
    long blockSize = statFs.getBlockSize();
    long availableBloks = statFs.getAvailableBlocks();
    return (availableBloks * blockSize) / 1048576;
}

From source file:com.almalence.util.Util.java

public static long BusyDeviceMemory() {
    StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
    long Total = (statFs.getBlockCount() * statFs.getBlockSize()) / 1048576;
    long Free = (statFs.getAvailableBlocks() * statFs.getBlockSize()) / 1048576;
    return (Total - Free);
}

From source file:com.almalence.util.Util.java

public static long BusyExternalMemory() {
    StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
    long Total = (statFs.getBlockCount() * statFs.getBlockSize()) / 1048576;
    long Free = (statFs.getAvailableBlocks() * statFs.getBlockSize()) / 1048576;
    return (Total - Free);
}

From source file:Main.java

public long getTotalExternalMemorySize() {
    if (!isHaveSDCard()) {
        return -1;
    }//  w  ww  . ja v  a  2 s  . c o m
    File path = Environment.getExternalStorageDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long blockCount = stat.getBlockCount();
    return blockSize * blockCount;
}

From source file:com.atwal.wakeup.battery.util.Utilities.java

public static long getAvailableInternalMemorySize() {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    return stat.getAvailableBlocks() * blockSize;
}

From source file:com.atwal.wakeup.battery.util.Utilities.java

public static long getAvailableExternalMemorySize() {
    if (externalMemoryAvailable()) {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSize();
        long availableBlocks = stat.getAvailableBlocks();
        return availableBlocks * blockSize;
    } else {//from  w  w w  . java 2  s .  c o m
        return 0;
    }
}