List of usage examples for java.io File getUsableSpace
public long getUsableSpace()
From source file:com.boko.vimusic.cache.ImageCache.java
/** * Check how much usable space is available at a given path. * /*from w w w .j ava 2 s .c o m*/ * @param path * The path to check * @return The space available in bytes */ public static final long getUsableSpace(final File path) { return path.getUsableSpace(); }
From source file:com.nf2m.util.ImageCache.java
/** * Check how much usable space is available at UriObserver given path. * * @param path The path to check/*from ww w. j av a 2 s . co m*/ * @return The space available in bytes */ @TargetApi(VERSION_CODES.GINGERBREAD) static long getUsableSpace(@NonNull 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.common.library.bitmap.ImageCache.java
/** * Check how much usable space is available at a given path. * * @param path The path to check// w ww .j av a 2 s.c o m * @return The space available in bytes */ @TargetApi(VERSION_CODES.GINGERBREAD) public static long getUsableSpace(File path) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { return path.getUsableSpace(); } final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }
From source file:com.sughimura.samplebitmaps.util.ImageCache.java
/** * Check how much usable space is available at a given path. * * @param path The path to check//from w w w. j a v a2s . c o m * @return The space available in bytes */ @TargetApi(VERSION_CODES.GINGERBREAD) public static long getUsableSpace(File path) { if (com.sughimura.samplebitmaps.util.Utils.hasGingerbread()) { return path.getUsableSpace(); } final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }
From source file:com.androidpi.bricks.gallery.lru.cache.ImageCache.java
/** * Check how much usable space is available at a given path. * * @param path The path to check//from w w w.j av a 2 s .c o m * @return The space available in bytes */ @TargetApi(VERSION_CODES.GINGERBREAD) public static long getUsableSpace(File path) { if (AppUtil.hasGingerbread()) { return path.getUsableSpace(); } final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }
From source file:air.com.snagfilms.utils.ImageCache.java
/** * Check how much usable space is available at a given path. * /* w w w.j a v a 2 s .c o m*/ * @param path * The path to check * @return The space available in bytes */ @SuppressWarnings("deprecation") @TargetApi(VERSION_CODES.GINGERBREAD) 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.andrew.apollo.cache.ImageCache.java
/** * Check how much usable space is available at a given path. * /*from w ww . j av a 2s.c o m*/ * @param path The path to check * @return The space available in bytes */ @TargetApi(Build.VERSION_CODES.GINGERBREAD) public static final long getUsableSpace(final File path) { if (ApolloUtils.hasGingerbread()) { return path.getUsableSpace(); } final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }
From source file:com.doplgangr.secrecy.utils.Util.java
public static Map<String, File> getAllStorageLocations() { Map<String, File> map = new TreeMap<String, File>(); List<String> mMounts = new ArrayList<String>(99); //List<String> mVold = new ArrayList<String>(99); mMounts.add(Environment.getExternalStorageDirectory().getAbsolutePath()); try {//from w ww . j a v a 2 s .c o m File mountFile = new File("/proc/mounts"); if (mountFile.exists()) { Scanner scanner = new Scanner(mountFile); while (scanner.hasNext()) { String line = scanner.nextLine(); //if (line.startsWith("/dev/block/vold/")) { String[] lineElements = line.split(" "); String element = lineElements[1]; mMounts.add(element); } } } catch (Exception e) { e.printStackTrace(); } List<String> mountHash = new ArrayList<String>(99); for (String mount : mMounts) { File root = new File(mount); Util.log(mount, "is checked"); Util.log(mount, root.exists(), root.isDirectory(), canWrite(root)); if (canWrite(root)) { Util.log(mount, "is writable"); File[] list = root.listFiles(); String hash = "["; if (list != null) for (File f : list) hash += f.getName().hashCode() + ":" + f.length() + ", "; hash += "]"; if (!mountHash.contains(hash)) { String key = root.getAbsolutePath() + " (" + org.apache.commons.io.FileUtils.byteCountToDisplaySize(root.getUsableSpace()) + " free space)"; mountHash.add(hash); map.put(key, root); } } } mMounts.clear(); return map; }
From source file:com.doplgangr.secrecy.Util.java
public static Map<String, java.io.File> getAllStorageLocations() { Map<String, java.io.File> map = new TreeMap<String, File>(); List<String> mMounts = new ArrayList<String>(99); //List<String> mVold = new ArrayList<String>(99); mMounts.add(Environment.getExternalStorageDirectory().getAbsolutePath()); try {// w w w. j a v a 2s. com java.io.File mountFile = new java.io.File("/proc/mounts"); if (mountFile.exists()) { Scanner scanner = new Scanner(mountFile); while (scanner.hasNext()) { String line = scanner.nextLine(); //if (line.startsWith("/dev/block/vold/")) { String[] lineElements = line.split(" "); String element = lineElements[1]; mMounts.add(element); } } } catch (Exception e) { e.printStackTrace(); } /** try { java.io.File voldFile = new java.io.File("/system/etc/vold.fstab"); if (voldFile.exists()) { Scanner scanner = new Scanner(voldFile); while (scanner.hasNext()) { String line = scanner.nextLine(); //if (line.startsWith("dev_mount")) { String[] lineElements = line.split(" "); String element = lineElements[2]; if (element.contains(":")) element = element.substring(0, element.indexOf(":")); mVold.add(element); } } } catch (Exception e) { e.printStackTrace(); } **/ /* for (int i = 0; i < mMounts.size(); i++) { String mount = mMounts.get(i); if (!mVold.contains(mount)) mMounts.remove(i--); } mVold.clear(); */ List<String> mountHash = new ArrayList<String>(99); for (String mount : mMounts) { java.io.File root = new java.io.File(mount); Util.log(mount, "is checked"); Util.log(mount, root.exists(), root.isDirectory(), canWrite(root)); if (canWrite(root)) { Util.log(mount, "is writable"); java.io.File[] list = root.listFiles(); String hash = "["; if (list != null) for (java.io.File f : list) hash += f.getName().hashCode() + ":" + f.length() + ", "; hash += "]"; if (!mountHash.contains(hash)) { String key = root.getAbsolutePath() + " (" + org.apache.commons.io.FileUtils.byteCountToDisplaySize(root.getUsableSpace()) + " free space)"; mountHash.add(hash); map.put(key, root); } } } mMounts.clear(); return map; }
From source file:org.apache.bookkeeper.util.TestDiskChecker.java
/** * Check the disk full/* w w w. j ava 2s. c o m*/ */ @Test(expected = DiskOutOfSpaceException.class) public void testCheckDiskFull() throws IOException { File file = createTempDir("DiskCheck", "test"); long usableSpace = file.getUsableSpace(); long totalSpace = file.getTotalSpace(); float threshold = (1f - ((float) usableSpace / (float) totalSpace)) * 0.5f; diskChecker.setDiskSpaceThreshold(threshold, threshold); diskChecker.checkDiskFull(file); }