package com.hivedi.statfscompat;

import android.os.Build;
import android.os.StatFs;

import java.io.File;

/**
 * Created by Hivedi2 on 2015-11-24.
 *
 */
public class StatFsCompat {

	@SuppressWarnings("deprecation")
	public static long getStatFsTotal(File f) {
		StatFs statFs = new StatFs(f.getAbsolutePath());
		if (Build.VERSION.SDK_INT >= 18) {
			return statFs.getTotalBytes();
		} else {
			return statFs.getBlockCount() * statFs.getBlockSize();
		}
	}

	@SuppressWarnings("deprecation")
	public static long getStatFsFree(File f) {
		StatFs statFs = new StatFs(f.getAbsolutePath());
		if (Build.VERSION.SDK_INT >= 18) {
			return statFs.getAvailableBlocksLong() * statFs.getBlockSizeLong();
		} else {
			return statFs.getAvailableBlocks() * (long) statFs.getBlockSize();
		}
	}

}

@@ -178,16 +178,64 @@
 mpat %7B%0A%0A
+%09public static final long STAT_FS_ERROR = -1L;%0A%0A
 %09@Suppre
@@ -297,32 +297,41 @@
 Total(File f) %7B%0A
+%09%09try %7B%0A%09
 %09%09StatFs statFs 
@@ -357,32 +357,33 @@
 bsolutePath());%0A
+%09
 %09%09if (Build.VERS
@@ -398,32 +398,33 @@
 INT %3E= 18) %7B%0A%09%09%09
+%09
 return statFs.ge
@@ -436,24 +436,25 @@
 lBytes();%0A%09%09
+%09
 %7D else %7B%0A%09%09%09
@@ -442,32 +442,33 @@
 ();%0A%09%09%09%7D else %7B%0A
+%09
 %09%09%09return statFs
@@ -501,32 +501,103 @@
 getBlockSize();%0A
+%09%09%09%7D%0A%09%09%7D catch (IllegalArgumentException e) %7B%0A%09%09%09return STAT_FS_ERROR;%0A
 %09%09%7D%0A%09%7D%0A%0A%09@Suppre
@@ -666,16 +666,25 @@
 le f) %7B%0A
+%09%09try %7B%0A%09
 %09%09StatFs
@@ -726,16 +726,17 @@
 ath());%0A
+%09
 %09%09if (Bu
@@ -763,24 +763,25 @@
 %3E= 18) %7B%0A%09%09%09
+%09
 return statF
@@ -836,16 +836,17 @@
 Long();%0A
+%09
 %09%09%7D else
@@ -847,24 +847,25 @@
 %7D else %7B%0A%09%09%09
+%09
 return statF
@@ -919,16 +919,87 @@
 Size();%0A
+%09%09%09%7D%0A%09%09%7D catch (IllegalArgumentException e) %7B%0A%09%09%09return STAT_FS_ERROR;%0A
 %09%09%7D%0A%09%7D%0A%0A

Handle error if file not exists