|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnl.lxtreme.ols.util.HostUtils
public final class HostUtils
Provides some host/OS specific utilities.
Method Summary | ||
---|---|---|
static boolean |
closeResource(Closeable aResource)
Closes a given resource. |
|
static File |
createLocalDataFile(String aName,
String aExtension)
Creates an OS-specific file location to store data. |
|
static File |
createLocalPropertiesFile(String aName)
Creates an OS-specific file location to store properties. |
|
static void |
flushInputStream(InputStream aResource)
Flushes the given input stream by reading as many bytes as there are still available. |
|
static String |
getFileExtension(File aFile)
Returns the "presumed" filename extension (like '.jpg', '.zip') from a given file. |
|
static HostInfo |
getHostInfo()
Returns the current value of hostinfo. |
|
static boolean |
handleInterruptedException(Throwable aThrowable)
This method calls Thread.currentThread().interrupt() if any exception in the hierarchy (including all parent causes) is either an InterruptedIOException or InterruptedException . |
|
static void |
initLogging(InputStream aInputStream)
Allows the logging properties of the JVM to be set at any moment in time providing the logging configuration in an input-stream. |
|
boolean |
isLinux()
Returns whether the current host's operating system is Linux or any other UNIX-like operating system, such as Solaris (SunOS). |
|
boolean |
isMacOS()
Returns whether the current host's operating system is Mac OS X. |
|
boolean |
isSolaris()
Returns whether the current host's operating system is Sun/Open Solaris. |
|
boolean |
isUnix()
Returns whether the current host's operating system is Linux or any other UNIX-like operating system, such as Solaris (SunOS). |
|
boolean |
isWindows()
Returns whether the current host's operating system is Windows. |
|
boolean |
needsAboutMenuItem()
|
|
boolean |
needsExitMenuItem()
|
|
boolean |
needsPreferencesMenuItem()
|
|
static void |
reverse(int[] aArray)
Reverses the elements in the given array. |
|
static
|
reverse(T[] aArray)
Reverses the elements in the given array. |
|
static File |
setFileExtension(File aFile,
String aFileExtension)
Sets the filename to end with the given file extension, if this is not already the case. |
|
static String |
stripFileExtension(File aFile,
String... aExtensions)
Returns the "presumed" filename extension (like '.jpg', '.zip') from a given file. |
|
static String |
stripFileExtension(String aFilename,
String... aExtensions)
Returns the "presumed" filename extension (like '.jpg', '.zip') from a given file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static final boolean closeResource(Closeable aResource)
If the given resource also implements the Flushable
interface, the
resource is flushed before being closed.
aResource
- the resource to close, can be null
, it might already
be closed.
true
if the close operation succeeded,
false
if it is unsure whether it succeeded.public static final File createLocalDataFile(String aName, String aExtension)
aName
- the name of the data file, excluding the file extension, cannot be
null
or empty;aExtension
- the extension of the data file to use, note that this is an
indication an might not be used for a particular host
operating system.
null
.public static final File createLocalPropertiesFile(String aName)
aName
- the name of the properties file, excluding .properties,
cannot be null
or empty. By convention, the name of a
properties file should be in the "reverse package name", e.g.,
"com.foo.bar".
null
.public static final void flushInputStream(InputStream aResource) throws IOException
aResource
- the resource to flush, can be null
.
IOException
- in case of I/O problems/public static final String getFileExtension(File aFile)
aFile
- the file to return the extension for, cannot be null
.
null
but can be empty if the given file has no file extension.public static HostInfo getHostInfo()
null
.public static boolean handleInterruptedException(Throwable aThrowable)
InterruptedIOException
or InterruptedException
. This method
should be called in every catch(IOException), catch(Exception) or
catch(Throwable) block.
aThrowable
- the exception to be checked for interruption. Does nothing if
null
.
true
if the exception is "handled" by this method,
false
otherwise.public static final void initLogging(InputStream aInputStream)
aInputStream
- the input stream providing the logging properties, cannot be
null
.public static final void reverse(int[] aArray)
aArray
- the array to reverse, cannot be null
.
IllegalArgumentException
- in case the given array was null
.public static final <T> void reverse(T[] aArray)
aArray
- the array to reverse, cannot be null
.
IllegalArgumentException
- in case the given array was null
.public static final File setFileExtension(File aFile, String aFileExtension)
aFile
- the file that should get the given file extension, cannot be
null
;aFileExtension
- the new file extension to add to the given file, cannot be
null
.
null
.public static final String stripFileExtension(File aFile, String... aExtensions)
aFile
- the file to return the extension for, cannot be null
.
null
but can be empty if the given file has no file extension.public static final String stripFileExtension(String aFilename, String... aExtensions)
aFilename
- the name of the file to strip the extension from, cannot be
null
;aExtensions
- the (optional) extensions that should be stripped. If omitted,
everything behind the last dot will be removed.
null
but can be empty if the given file has no file extension.public boolean isLinux()
isLinux
in interface HostInfo
true
if running on Linux or any other UNIX system,
false
otherwise.public boolean isMacOS()
isMacOS
in interface HostInfo
true
if running on Mac OS X, false
otherwise.public boolean isSolaris()
isSolaris
in interface HostInfo
true
if running on Sun/Open Solaris system,
false
otherwise.public boolean isUnix()
isUnix
in interface HostInfo
true
if running on Linux or any other UNIX system,
false
otherwise.public boolean isWindows()
isWindows
in interface HostInfo
true
if running on Windows, false
otherwise.public boolean needsAboutMenuItem()
needsAboutMenuItem
in interface HostInfo
true
if an explicit about menu item needs to be
added to a UI created on the running host, false
if
the running host already provides an about menu item by default.public final boolean needsExitMenuItem()
needsExitMenuItem
in interface HostInfo
true
if an explicit exit menu item needs to be added
to a UI created on the running host, false
if the
running host already provides an exit menu item by default.public boolean needsPreferencesMenuItem()
needsPreferencesMenuItem
in interface HostInfo
true
if an explicit preferences menu item needs to
be added to a UI created on the running host, false
if the running host already provides a preferences menu item by
default.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |