List of usage examples for android.os StatFs StatFs
public StatFs(String path)
From source file:com.ddiiyy.xydz.xutils.util.OtherUtils.java
@SuppressWarnings("deprecation") public static long getAvailableSpace(File dir) { try {//from w w w . j av a2 s. c om final StatFs stats = new StatFs(dir.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); } catch (Throwable e) { LogUtils.e(e.getMessage(), e); return -1; } }
From source file:com.fallahpoor.infocenter.fragments.StorageFragment.java
@SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) private String getInternalFree() { long size;//from w w w. j a v a2 s .c om StatFs internalStatFs = new StatFs(Environment.getDataDirectory().getAbsolutePath()); if (mIsApiAtLeast18) { size = internalStatFs.getAvailableBytes(); } else { size = (long) internalStatFs.getAvailableBlocks() * (long) internalStatFs.getBlockSize(); } return Utils.getFormattedSize(size); }
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 {//from w ww . j av a2s.c om availableBlocks = stat.getAvailableBlocks(); blockSize = stat.getBlockSize(); } return availableBlocks * blockSize; }
From source file:com.android.volley.misc.Utils.java
/** * Check how much usable space is available at a given path. * /*from w w w. j av a2 s. co m*/ * @param path * The path to check * @return The space available in bytes */ @SuppressWarnings("deprecation") @TargetApi(9) public static long getUsableSpace(File path) { if (Utils.hasGingerbread()) { return path.getUsableSpace(); } final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }
From source file:com.bellman.bible.service.common.CommonUtils.java
public static long getFreeSpace(String path) { StatFs stat = new StatFs(path); long bytesAvailable = (long) stat.getBlockSize() * (long) stat.getAvailableBlocks(); Log.d(TAG, "Free space :" + bytesAvailable); return bytesAvailable; }
From source file:com.lxh.util.image.OtherUtils.java
/** * ??//from www .j a v a 2 s .c o m * @param dir {@link java.io.File} * @return ????byte-1 */ public static long getAvailableSpace(File dir) { try { final StatFs stats = new StatFs(dir.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); } catch (Throwable e) { return -1; } }
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 {/*from w w w . j a v a 2s .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.open.file.manager.CutCopyService.java
/** * Checks weither there's enough space to perform the operation * @param current/*from ww w. ja va 2 s. c om*/ * @return */ private boolean notEnoughSpace(FileCopyNode current) { StatFs targetfs = new StatFs(current.dstFile.getParent()); return current.size > (long) targetfs.getAvailableBlocks() * (long) targetfs.getBlockSize(); }
From source file:com.fallahpoor.infocenter.fragments.StorageFragment.java
@SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) private String getExternalTotal() { long size;// w ww .ja v a 2 s. co m StatFs extStorageStatFs; String extStoragePath = getExternalStoragePath(); if (extStoragePath == null || !(new File(extStoragePath).exists())) { return getString(R.string.sto_sub_item_ext_storage_not_available); } extStorageStatFs = new StatFs(new File(extStoragePath).getAbsolutePath()); if (mIsApiAtLeast18) { size = extStorageStatFs.getTotalBytes(); } else { size = (long) extStorageStatFs.getBlockCount() * (long) extStorageStatFs.getBlockSize(); } return Utils.getFormattedSize(size); }
From source file:org.ormma.controller.OrmmaAssetController.java
/** * Cache remaining.//from w w w . j a v a2 s . c o m * * @return the cache remaining */ public int cacheRemaining() { File filesDir = mContext.getFilesDir(); StatFs stats = new StatFs(filesDir.getPath()); int free = stats.getFreeBlocks() * stats.getBlockSize(); return free; }