Package org.esa.snap.core.util
Class SystemUtils
- java.lang.Object
-
- org.esa.snap.core.util.SystemUtils
-
public class SystemUtils extends Object
A collection of SNAP-system level functions.All functions have been implemented with extreme caution in order to provide a maximum performance.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SystemUtils.ImageSelection
This class is used to hold an image while on the clipboard.
-
Field Summary
Fields Modifier and Type Field Description static String
AUXDATA_DIR_NAME
Name of SNAP's auxdata directory.static Logger
LOG
The SNAP system logger.static String
LS
static String
SNAP_CACHE_DIR_PROPERTY_NAME
static String
SNAP_PARALLELISM_PROPERTY_NAME
-
Constructor Summary
Constructors Constructor Description SystemUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
convertToLocalPath(String urlPath)
Replace the separator character '/' with the system-dependent path-separator character.static void
copyToClipboard(Image image)
Copies the given image to the system clipboard.static void
copyToClipboard(String text)
Copies the given text to the system clipboard.static String
createHumanReadableExceptionMessage(Exception e)
Creates a (more) human readable exception message text for the given exception.static void
freeAllMemory()
Empty all tiles from cache and garbage collectstatic String
getApplicationContextId()
Gets the application context ID uses as prefix in a number of application configuration settings.static File
getApplicationDataDir()
Gets the current user's application data directory.static File
getApplicationDataDir(boolean force)
Optionally creates and returns the current user's application data directory.static File
getApplicationHomeDir()
Gets the application's home directory as set by the system property "${snap.context}.home".static String
getApplicationHomepageUrl()
Gets the application home page URL as set by the system property "${ceres.context}.homepage.url".static String
getApplicationName()
Gets the application name used in logger output and information messages.static String
getApplicationRemoteVersionUrl()
static Path
getAuxDataPath()
Gets the auxdata directory which stores dems, orbits, rgb profiles, etc.static File
getCacheDir()
Gets the SNAP cache directory .static String
getClassFileName(Class aClass)
Retrieves the file name of a class.static File[]
getClassPathFiles()
Gets all files (class directory & JAR file pathes) given in the current class path of the Java runtime which loaded this class.static File
getCurrentWorkingDir()
Gets the current working directory, or the directory pointed to by '.' if the actual working directory cannot be determined.static File
getDefaultCacheDir()
Gets the default SNAP cache directory.static double
getMemoryUsed()
static String
getReleaseVersion()
Returns the version string.static File
getUserHomeDir()
Gets the current user's home directory, or the directory pointed to by '.' if the user's actual home directory cannot be determined.static String
getUserName()
Gets the current user's name, or the string"unknown"
if the the user's name cannot be determined.static void
init3rdPartyLibs(Class<?> cls)
Initialize third party libraries of SNAP.static void
init3rdPartyLibsByCl(ClassLoader cl)
Initialize third party libraries of SNAP.static void
initGeoTools()
static void
initJAI(Class<?> cls)
static void
initJAI(ClassLoader cl)
static ModuleMetadata
loadModuleMetadata(Class<?> aClass)
Tries to load the metadata fromMETA-INF/MANIFEST.MF
contained in the module jar of the specified class.static <S> Iterable<S>
loadServices(Class<S> serviceType)
Loads services from allMETA-INF/services/
resources.static <S> Iterable<S>
loadServices(Class<S> serviceType, ClassLoader classLoader)
Loads services from allMETA-INF/services/
resources.static void
tileCacheFreeOldTiles()
tell tileCache that some old tiles can be removed
-
-
-
Field Detail
-
SNAP_PARALLELISM_PROPERTY_NAME
public static final String SNAP_PARALLELISM_PROPERTY_NAME
-
SNAP_CACHE_DIR_PROPERTY_NAME
public static final String SNAP_CACHE_DIR_PROPERTY_NAME
-
LOG
public static final Logger LOG
The SNAP system logger. Default name is "org.esa.snap" which may be overridden by system property "snap.logger.name".
-
LS
public static final String LS
-
AUXDATA_DIR_NAME
public static final String AUXDATA_DIR_NAME
Name of SNAP's auxdata directory.- See Also:
- Constant Field Values
-
-
Method Detail
-
getUserName
public static String getUserName()
Gets the current user's name, or the string"unknown"
if the the user's name cannot be determined.- Returns:
- the current user's name, never
null
-
getUserHomeDir
public static File getUserHomeDir()
Gets the current user's home directory, or the directory pointed to by '.' if the user's actual home directory cannot be determined.- Returns:
- the current working directory, never
null
-
getApplicationHomepageUrl
public static String getApplicationHomepageUrl()
Gets the application home page URL as set by the system property "${ceres.context}.homepage.url". Default is "http://sentinel.esa.int".- Returns:
- the application homepage url
- Since:
- BEAM 4.10
-
getApplicationDataDir
public static File getApplicationDataDir()
Gets the current user's application data directory.- Returns:
- the current user's application data directory
- Since:
- BEAM 4.2
-
getAuxDataPath
public static Path getAuxDataPath()
Gets the auxdata directory which stores dems, orbits, rgb profiles, etc.- Returns:
- the auxiliary data directory
- Since:
- SNAP 2.0
-
getCacheDir
public static File getCacheDir()
Gets the SNAP cache directory . This is the directory where SNAP stores cached & temporary data.The SNAP cache directory can be configured using the
snap.cachedir
configuration property (or Java system property).- Returns:
- the cache directory
- Since:
- SNAP 2
-
getDefaultCacheDir
public static File getDefaultCacheDir()
Gets the default SNAP cache directory.- Returns:
- the default cache directory
- See Also:
getCacheDir()
-
getApplicationDataDir
public static File getApplicationDataDir(boolean force)
Optionally creates and returns the current user's application data directory.- Parameters:
force
- if true, the directory will be created if it didn't exist before- Returns:
- the current user's application data directory
- Since:
- BEAM 4.2
-
getApplicationContextId
public static String getApplicationContextId()
Gets the application context ID uses as prefix in a number of application configuration settings. The context ID is configured using the system property "snap.context". If this property is not set, the string "snap" is used.- Returns:
- The application context ID.
- Since:
- BEAM 4.10
-
getApplicationName
public static String getApplicationName()
Gets the application name used in logger output and information messages. The context ID is configured using the system property "${ceres.context}.application.name". If this property is not set, the string "SNAP" is used.- Returns:
- The application name.
- Since:
- BEAM 4.10
- See Also:
getApplicationContextId()
-
getCurrentWorkingDir
public static File getCurrentWorkingDir()
Gets the current working directory, or the directory pointed to by '.' if the actual working directory cannot be determined.- Returns:
- the current working directory, never
null
-
getClassPathFiles
public static File[] getClassPathFiles()
Gets all files (class directory & JAR file pathes) given in the current class path of the Java runtime which loaded this class.The files pathes returned are either relative or absolute, just as they where defined for the runtime's class path.
- Returns:
- all files in the current class path, never
null
-
getApplicationHomeDir
public static File getApplicationHomeDir()
Gets the application's home directory as set by the system property "${snap.context}.home".- Returns:
- an assumption of an application's home directory, never
null
-
getClassFileName
public static String getClassFileName(Class aClass)
Retrieves the file name of a class. For example, the string"Date.class"
is returned for the classjava.util.Date
.- Parameters:
aClass
- The class.- Returns:
- the file name of the given class
- Throws:
IllegalArgumentException
- if the given parameter isnull
.
-
convertToLocalPath
public static String convertToLocalPath(String urlPath)
Replace the separator character '/' with the system-dependent path-separator character.- Parameters:
urlPath
- an URL path or any other string containing the forward slash '/' as directory separator.- Returns:
- a path string with all occurrences of '/'
- Throws:
IllegalArgumentException
- if the given parameter isnull
.
-
createHumanReadableExceptionMessage
public static String createHumanReadableExceptionMessage(Exception e)
Creates a (more) human readable exception message text for the given exception. This method should be used when exception messages are to be presented to the user in a GUI.Currently the only modifications are
1. the first letter is turned into upper case
2. the message is suffixed with a dot ('.') character.- Parameters:
e
- the exception- Returns:
- a modified message text, or
null
ife
was null.
-
copyToClipboard
public static void copyToClipboard(String text)
Copies the given text to the system clipboard.- Parameters:
text
- the text to copy
-
copyToClipboard
public static void copyToClipboard(Image image)
Copies the given image to the system clipboard.- Parameters:
image
- the image to copy
-
loadServices
public static <S> Iterable<S> loadServices(Class<S> serviceType)
Loads services from allMETA-INF/services/
resources.- Parameters:
serviceType
- the type of the service to be loaded.- Returns:
- the services of type
serviceType
found.
-
loadServices
public static <S> Iterable<S> loadServices(Class<S> serviceType, ClassLoader classLoader)
Loads services from allMETA-INF/services/
resources.- Parameters:
serviceType
- the type of the service to be loaded.classLoader
- the class loader.- Returns:
- the services of type
serviceType
found.
-
init3rdPartyLibs
public static void init3rdPartyLibs(Class<?> cls)
Initialize third party libraries of SNAP.- Parameters:
cls
- The most useful class.- Since:
- BEAM 4.8
-
init3rdPartyLibsByCl
public static void init3rdPartyLibsByCl(ClassLoader cl)
Initialize third party libraries of SNAP.- Parameters:
cl
- The most useful class loader.- Since:
- SNAP 8.0
-
initGeoTools
public static void initGeoTools()
-
initJAI
public static void initJAI(Class<?> cls)
-
initJAI
public static void initJAI(ClassLoader cl)
-
getApplicationRemoteVersionUrl
public static String getApplicationRemoteVersionUrl()
-
loadModuleMetadata
public static ModuleMetadata loadModuleMetadata(Class<?> aClass)
Tries to load the metadata fromMETA-INF/MANIFEST.MF
contained in the module jar of the specified class.- Parameters:
aClass
- The module jar which contains this specified class will be used to look-up theMETA-INF/MANIFEST.MF
- Returns:
- the module metadata, or
null
if aMETA-INF/MANIFEST.MF
could not be found.
-
getReleaseVersion
public static String getReleaseVersion()
Returns the version string. It'S the version uf the last major release.- Returns:
- the version string
-
freeAllMemory
public static void freeAllMemory()
Empty all tiles from cache and garbage collect
-
getMemoryUsed
public static double getMemoryUsed()
-
tileCacheFreeOldTiles
public static void tileCacheFreeOldTiles()
tell tileCache that some old tiles can be removed
-
-