org.backsource.alert.util
Class Drive

java.lang.Object
  extended byorg.backsource.alert.util.Drive

public class Drive
extends java.lang.Object

Represent a drive/partition in the filesystem.

A drive is a simple representation of a partition/harddisk/filesystem that is available on the computer. Through it one can get the partition/harddisk name, such as /dev/hda1 or C:, or the file system name, such as / or C:. The total size and how much of it that is used is also available as bytes.

The only way to get one or more Drives is through the two static methods: getDrives() and getDrive(String driveName).

Currently this is done through the use of the external command df, which is supported on LINUX, FreeBSD, Mac OS X and Windows plattforms wich has CYGWIN installed.

Examples.

   // Get a single drive
   Drive d = Drive.getDrive("/");
   if ( d.percentUsed() > 93) {
      System.err.println("Diskspace is soon full for normal users, percent used = " + d.percentUsed()+"%"); 
   } // end of if ()
  

    // Get all drives
    Drive[] d = Drive.getDrives();
  

Depends on: log4j.jar

Version:
$Revision: 1.1.1.1 $
Author:
Peter Antman

Method Summary
protected static Drive[] df(java.lang.String drive)
          Run the df command an create drives.
protected static Drive dir(java.io.File drive)
          Dir emultion on win with df installed.
static Drive getDrive(java.lang.String driveName)
          Get a drive by its name, may be either device name or mount point name.
protected static Drive getDriveFromDf(java.lang.String line)
          Parse a df line output and instantiate a Drive from it.
 java.lang.String getDriveName()
          Get the name of the device.
static Drive[] getDrives()
          Get all drives available on the system.
protected static Drive[] getDrives(java.lang.String driveName)
          main entry for internal methods, delegates to correct os methods.
 java.io.File getFile()
          Get a file represenation of device, i.e filsystem mounted on device.
 int getPercentUsed()
          Get percent of disk used.
 long getSize()
          Get size of device in bytes.
 long getUsed()
          Get number of bytes used.
protected static Drive[] getWinDrives(java.lang.String drive)
          Entry for windows.
protected static boolean hasCygwin()
          Check if system has Cygwin installed (does a uname).
static void main(java.lang.String[] args)
           
 java.lang.String toString()
          Get a string rep of device, looking like a df line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getDriveName

public java.lang.String getDriveName()
Get the name of the device.


getSize

public long getSize()
Get size of device in bytes.


getUsed

public long getUsed()
Get number of bytes used.


getPercentUsed

public int getPercentUsed()
Get percent of disk used.


getFile

public java.io.File getFile()
Get a file represenation of device, i.e filsystem mounted on device.


toString

public java.lang.String toString()
Get a string rep of device, looking like a df line.


getDrive

public static Drive getDrive(java.lang.String driveName)
                      throws java.io.IOException
Get a drive by its name, may be either device name or mount point name.

Returns:
a Drive or null if no drive by the given name exists.
Throws:
java.io.IOException

getDrives

public static Drive[] getDrives()
                         throws java.io.IOException
Get all drives available on the system.

Returns:
an array of Drives, which is empty if no drives are found.
Throws:
java.io.IOException

getDrives

protected static Drive[] getDrives(java.lang.String driveName)
                            throws java.io.IOException
main entry for internal methods, delegates to correct os methods. If driveName is null, all drives on system is returned.

Throws:
java.io.IOException

df

protected static Drive[] df(java.lang.String drive)
                     throws java.io.IOException
Run the df command an create drives.

Parameters:
drive - get single drive (by device name or file system name) or if null all drives.
Throws:
java.io.IOException

getDriveFromDf

protected static Drive getDriveFromDf(java.lang.String line)
Parse a df line output and instantiate a Drive from it.


getWinDrives

protected static Drive[] getWinDrives(java.lang.String drive)
                               throws java.io.IOException
Entry for windows.

Does not use df directly since cygwin df emulates a lot of extra drives to help unix commands. The file system will be constructed from the driveName.

Throws:
java.io.IOException

dir

protected static Drive dir(java.io.File drive)
                    throws java.io.IOException
Dir emultion on win with df installed.

Throws:
java.io.IOException

hasCygwin

protected static boolean hasCygwin()
Check if system has Cygwin installed (does a uname).


main

public static void main(java.lang.String[] args)


Copyright © 2002-2004 Backsource. All Rights Reserved.