SoftNet-Consult Java Utility Library

com.softnetConsult.utils.sys
Class SystemTools

java.lang.Object
  extended by com.softnetConsult.utils.sys.SystemTools

public final class SystemTools
extends java.lang.Object

Static system, memory and time management utility functions.

This product includes software developed by the SoftNet-Consult Java Utility Library project and its contributors.
(http://java-tools.sourceforge.net)
Copyright (c) 2007-2008 SoftNet-Consult.
Copyright (c) 2007-2008 G. Paperin.
All rights reserved.

File: SystemTools.java
Library API version: "2.02"
Java compliance version: "1.5"

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following terms and conditions are met:

1. Redistributions of source code must retain the above acknowledgement of the SoftNet-Consult Java Utility Library project, the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above acknowledgement of the SoftNet-Consult Java Utility Library project, the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software or any derived software must display the following acknowledgement:
This product includes software developed by the SoftNet-Consult Java Utility Library project and its contributors.

THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Version:
"2.02"
Author:
Greg Paperin (http://www.paperin.org)

Constructor Summary
private SystemTools()
          Prevents instances of this class from being created as this class contains only static utility methods.
 
Method Summary
static java.lang.String formatTime(int millis, int secs, int mins, int hours, int days)
          Formats a time interval to a nicely readable format without the need to involve a formatter.
static java.lang.String formatTimePeriod(long startMillis, long endMillis)
          Formats the specified time period as specified in formatTime(int, int, int, int, int); note that timePeriod(long, long) is used to process the time period and therefore the same restrictions as in that method apply to this method.
static ClassVersionInfo getClassVersionInfo(java.io.File classfile)
          Gets the class version info of the specified Java class file.
static ClassVersionInfo getClassVersionInfo(java.lang.String classfile)
          Gets the class version info of the specified Java class file.
static java.lang.String getMemInfoString()
          Fetches the current memory information and formats the data in a human readable string.
static void printMemInfoLine()
          Prints a human readable line with the current memory information to std-out, equivalent to System.out.println(getMemInfoString()).
static void sleep(long millis)
          Allows calling Thread.sleep without the nuisance of surrounding the call with a try-catch block.
static void sleep(long millis, int nanos)
          Allows calling Thread.sleep without the nuisance of surrounding the call with a try-catch block.
static int[] timePeriod(long startMillis, long endMillis)
          Determines how many days, hours, minutes, seconds and milliseconds the specified time period contains.
static void wait(long millis, int nanos, java.lang.Object object)
          Allows calling Object.wait without the nuisance of surrounding the call with a try-catch block.
static void wait(long millis, java.lang.Object object)
          Allows calling Object.wait without the nuisance of surrounding the call with a try-catch block.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SystemTools

private SystemTools()
Prevents instances of this class from being created as this class contains only static utility methods.

Method Detail

getMemInfoString

public static java.lang.String getMemInfoString()
Fetches the current memory information and formats the data in a human readable string.

Returns:
A human readable string containing information on available free memory, memory used by the current application, the total memory size of the current JVM and the maximum amount of memory that the current JVM will attempt to use.

printMemInfoLine

public static void printMemInfoLine()
Prints a human readable line with the current memory information to std-out, equivalent to System.out.println(getMemInfoString()).


sleep

public static void sleep(long millis)
Allows calling Thread.sleep without the nuisance of surrounding the call with a try-catch block. A possible InterruptedException is caught and ignored.

Parameters:
millis - The length of time to sleep in milliseconds.

sleep

public static void sleep(long millis,
                         int nanos)
Allows calling Thread.sleep without the nuisance of surrounding the call with a try-catch block. A possible InterruptedException is caught and ignored.

Parameters:
millis - The length of time to sleep in milliseconds.
nanos - 0-999999 additional nanoseconds to sleep.

wait

public static void wait(long millis,
                        java.lang.Object object)
Allows calling Object.wait without the nuisance of surrounding the call with a try-catch block. A possible InterruptedException is caught and ignored.

Parameters:
millis - The length of time to sleep in milliseconds.
object - The object for which to wait.

wait

public static void wait(long millis,
                        int nanos,
                        java.lang.Object object)
Allows calling Object.wait without the nuisance of surrounding the call with a try-catch block. A possible InterruptedException is caught and ignored.

Parameters:
millis - The length of time to sleep in milliseconds.
nanos - 0-999999 additional nanoseconds to sleep.
object - The object for which to wait.

timePeriod

public static int[] timePeriod(long startMillis,
                               long endMillis)
Determines how many days, hours, minutes, seconds and milliseconds the specified time period contains. Note that the specified time period, i.e. the absolude difference between startMillis and endMillis may not be larger than 185542587187199999L milliseconds, as an internal overflow would occur otherwise. The limit of 185542587187199999L milliseconds corrsponds to ( (Integer.MAX_VALUE + 1L) * 86400000L - 1L ) milliseconds or Integer.MAX_VALUE days, 23 hours, 59 minures and 59.999 seconds or 2147483647 days, 23:59:59.999.

Parameters:
startMillis - The milliseconds marking the beginning of a time period.
endMillis - The milliseconds marking the end of a time period.
Returns:
An int-array containg exactly 5 following elements:
index [4]: number of whole days in the specified time period;
index [3]: number of whole hours not covered by the whole days in the specified time period;
index [2]: number of whole minutes not covered by the whole hours in the specified time period;
index [1]: number of whole seconds not covered by the whole mins in the specified time period;
index [0]: number of whole millisecs not covered by the whole secs in the specified time period;
Throws:
java.lang.IllegalArgumentException - If the absolute value of the difference between startMillis and endMillis is larger than 185542587187199999L.

formatTime

public static java.lang.String formatTime(int millis,
                                          int secs,
                                          int mins,
                                          int hours,
                                          int days)
Formats a time interval to a nicely readable format without the need to involve a formatter. No validity checks are performed.

Parameters:
millis - Milliseconds
secs - Seconds.
mins - Minutes.
hours - Hours.
days - Days.
Returns:
Time formated as in for example 3 days, 17:08:53.006.

formatTimePeriod

public static java.lang.String formatTimePeriod(long startMillis,
                                                long endMillis)
Formats the specified time period as specified in formatTime(int, int, int, int, int); note that timePeriod(long, long) is used to process the time period and therefore the same restrictions as in that method apply to this method.

Parameters:
startMillis - The milliseconds marking the beginning of a time period.
endMillis - The milliseconds marking the end of a time period.
Returns:
Time period formated as in for example 3 days, 17:08:53.006.
See Also:
timePeriod(long, long), formatTime(int, int, int, int, int)

getClassVersionInfo

public static ClassVersionInfo getClassVersionInfo(java.io.File classfile)
                                            throws java.io.IOException
Gets the class version info of the specified Java class file.

Parameters:
classfile - A File representing a physical Java class file.
Returns:
A ClassVersionInfo-object containing information about the major and the minor versions of the specified class file as well as the minimum JVM version required to run that class file. If the specified file is not a valid Java class file (according to the magic numer check) this method returns null.
Throws:
java.io.IOException - If there was an error when reading the specified file.

getClassVersionInfo

public static ClassVersionInfo getClassVersionInfo(java.lang.String classfile)
                                            throws java.io.IOException
Gets the class version info of the specified Java class file.

Parameters:
classfile - The full path of a physical Java class file.
Returns:
A ClassVersionInfo-object containing information about the major and the minor versions of the specified class file as well as the minimum JVM version required to run that class file. If the specified file is not a valid Java class file (according to the magic numer check) this method returns null.
Throws:
java.io.IOException - If there was an error when reading the specified file.

SoftNet-Consult Java Utility Library is a member of SourceForge.net