public class

StatFsHelper

extends Object
java.lang.Object
   ↳ com.facebook.common.statfs.StatFsHelper

Class Overview

Helper class that periodically checks the amount of free space available.

To keep the overhead low, it caches the free space information, and only updates that info after two minutes.

It is a singleton, and is thread-safe.

Initialization is delayed until first use, so the first call to any method may incur some additional cost.

Summary

Nested Classes
enum StatFsHelper.StorageType  
Protected Constructors
StatFsHelper()
Constructor.
Public Methods
long getAvailableStorageSpace(StatFsHelper.StorageType storageType)
Gets the information about the available storage space either internal or external depends on the give input
long getFreeStorageSpace(StatFsHelper.StorageType storageType)
Gets the information about the free storage space, including reserved blocks, either internal or external depends on the given input
synchronized static StatFsHelper getInstance()
long getTotalStorageSpace(StatFsHelper.StorageType storageType)
Gets the information about the total storage space, either internal or external depends on the given input
void resetStats()
Thread-safe call to reset the disk stats.
boolean testLowDiskSpace(StatFsHelper.StorageType storageType, long freeSpaceThreshold)
Check if available space in the filesystem is greater than the given threshold.
Protected Methods
static StatFs createStatFs(String path)
[Expand]
Inherited Methods
From class java.lang.Object

Protected Constructors

protected StatFsHelper ()

Constructor.

Initialization is delayed until first use, so we must call #ensureInitialized() when implementing member methods.

Public Methods

public long getAvailableStorageSpace (StatFsHelper.StorageType storageType)

Gets the information about the available storage space either internal or external depends on the give input

Parameters
storageType Internal or external storage type
Returns
  • available space in bytes, 0 if no information is available

public long getFreeStorageSpace (StatFsHelper.StorageType storageType)

Gets the information about the free storage space, including reserved blocks, either internal or external depends on the given input

Parameters
storageType Internal or external storage type
Returns
  • available space in bytes, -1 if no information is available

public static synchronized StatFsHelper getInstance ()

public long getTotalStorageSpace (StatFsHelper.StorageType storageType)

Gets the information about the total storage space, either internal or external depends on the given input

Parameters
storageType Internal or external storage type
Returns
  • available space in bytes, -1 if no information is available

public void resetStats ()

Thread-safe call to reset the disk stats. If we know that the free space has changed recently (for example, if we have deleted files), use this method to reset the internal state and start tracking disk stats afresh, resetting the internal timer for updating stats.

public boolean testLowDiskSpace (StatFsHelper.StorageType storageType, long freeSpaceThreshold)

Check if available space in the filesystem is greater than the given threshold. Note that the free space stats are cached and updated in intervals of RESTAT_INTERVAL_MS. If the amount of free space has crossed over the threshold since the last update, it will return incorrect results till the space stats are updated again.

Parameters
storageType StorageType (internal or external) to test
freeSpaceThreshold compare the available free space to this size
Returns
  • whether free space is lower than the input freeSpaceThreshold, returns true if disk information is not available

Protected Methods

protected static StatFs createStatFs (String path)