This class provides static utility methods for general file system
functions not provided via the JDK File class.
The current functions provided are:
| Modifier and Type | Field and Description |
|---|---|
| private static final int | INIT_PROBLEM
Operating system state flag for error. |
| private static final FileSystemUtils | INSTANCE
Singleton instance, used mainly for testing. |
| private static final int | OS
The operating system flag. |
| private static final int | OTHER
Operating system state flag for neither Unix nor Windows. |
| private static final int | POSIX_UNIX
Operating system state flag for Posix flavour Unix. |
| private static final int | UNIX
Operating system state flag for Unix. |
| private static final int | WINDOWS
Operating system state flag for Windows. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static long | |
| public static long | Returns: the amount of free drive space on the drive or volume in kilobytesthe path to get free space for, not null, not empty on Unix path)Returns the free space on a drive or volume in kilobytes by invoking the command line. |
| pack-priv long | Returns: the amount of free drive space on the drive or volumethe path to get free space for, not null, not empty on Unix path, int the operating system code os, boolean whether to normalize to kilobytes kb)Returns the free space on a drive or volume in a cross-platform manner. |
| pack-priv long | Returns: the amount of free drive space on the volumethe path to get free space for path, boolean whether to normalize to kilobytes kb, boolean whether to use the posix standard format flag posix)Find free space on the *nix platform using the 'df' command. |
| pack-priv long | Returns: the amount of free drive space on the drivethe path to get free space for, including the colon path)Find free space on the Windows platform using the 'dir' command. |
| pack-priv Process | Returns: the processthe command line parameters cmdAttribs)Opens the process to the operating system. |
| pack-priv long | Returns: the number of bytesthe free space string freeSpace, String the path path)Parses the bytes from a string. |
| pack-priv long | |
| pack-priv List | Returns: the parsed datathe command line parameters cmdAttribs, int The maximum limit for the lines returned max)Performs the os command. |
| INIT_PROBLEM | back to summary |
|---|---|
| private static final int INIT_PROBLEM Operating system state flag for error. | |
| INSTANCE | back to summary |
|---|---|
| private static final FileSystemUtils INSTANCE Singleton instance, used mainly for testing. | |
| OS | back to summary |
|---|---|
| private static final int OS The operating system flag. | |
| OTHER | back to summary |
|---|---|
| private static final int OTHER Operating system state flag for neither Unix nor Windows. | |
| POSIX_UNIX | back to summary |
|---|---|
| private static final int POSIX_UNIX Operating system state flag for Posix flavour Unix. | |
| UNIX | back to summary |
|---|---|
| private static final int UNIX Operating system state flag for Unix. | |
| WINDOWS | back to summary |
|---|---|
| private static final int WINDOWS Operating system state flag for Windows. | |
| FileSystemUtils | back to summary |
|---|---|
| public FileSystemUtils() Instances should NOT be constructed in standard programming. | |
| freeSpace | back to summary |
|---|---|
| public static long freeSpace(String path) throws IOException
Deprecated Use freeSpaceKb(String) Deprecated from 1.3, may be removed in 2.0 Returns the free space on a drive or volume by invoking
the command line.
This method does not normalize the result, and typically returns
bytes on Windows, 512 byte units on OS X and kilobytes on Unix.
As this is not very useful, this method is deprecated in favour
of
Note that some OS's are NOT currently supported, including OS/390,
OpenVMS and and SunOS 5. (SunOS is supported by
FileSystemUtils.freeSpace("C:"); // Windows
FileSystemUtils.freeSpace("/volume"); // *nix
The free space is calculated via the command line.
It uses 'dir /-c' on Windows and 'df' on *nix.
| |
| freeSpaceKb | back to summary |
|---|---|
| public static long freeSpaceKb(String path) throws IOException Returns the free space on a drive or volume in kilobytes by invoking the command line.
FileSystemUtils.freeSpaceKb("C:"); // Windows
FileSystemUtils.freeSpaceKb("/volume"); // *nix
The free space is calculated via the command line.
It uses 'dir /-c' on Windows, 'df -kP' on AIX/HP-UX and 'df -k' on other Unix.
In order to work, you must be running Windows, or have a implementation of Unix df that supports GNU format when passed -k (or -kP). If you are going to rely on this code, please check that it works on your OS by running some simple tests to compare the command line with the output from this class. If your operating system isn't supported, please raise a JIRA call detailing the exact result from df -k and as much other detail as possible, thanks.
| |
| freeSpaceOS | back to summary |
|---|---|
| pack-priv long freeSpaceOS(String path, int os, boolean kb) throws IOException Returns the free space on a drive or volume in a cross-platform manner. Note that some OS's are NOT currently supported, including OS/390.
FileSystemUtils.freeSpace("C:"); // Windows
FileSystemUtils.freeSpace("/volume"); // *nix
The free space is calculated via the command line.
It uses 'dir /-c' on Windows and 'df' on *nix.
| |
| freeSpaceUnix | back to summary |
|---|---|
| pack-priv long freeSpaceUnix(String path, boolean kb, boolean posix) throws IOException Find free space on the *nix platform using the 'df' command.
| |
| freeSpaceWindows | back to summary |
|---|---|
| pack-priv long freeSpaceWindows(String path) throws IOException Find free space on the Windows platform using the 'dir' command.
| |
| openProcess | back to summary |
|---|---|
| pack-priv Process openProcess(String[] cmdAttribs) throws IOException Opens the process to the operating system.
| |
| parseBytes | back to summary |
|---|---|
| pack-priv long parseBytes(String freeSpace, String path) throws IOException Parses the bytes from a string.
| |
| parseDir | back to summary |
|---|---|
| pack-priv long parseDir(String line, String path) throws IOException Parses the Windows dir response last line
| |
| performCommand | back to summary |
|---|---|
| pack-priv List Performs the os command.
| |