Package org.basex.util
Class Util
- java.lang.Object
-
- org.basex.util.Util
-
public final class Util extends Object
This class contains static methods, which are used throughout the project. The methods are used for dumping error output, debugging information, getting the application path, etc.- Author:
- BaseX Team 2005-23, BSD License, Christian Gruen
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
bug(Throwable throwable)
Returns an information string for an unexpected exception.static String
className(Class<?> clazz)
Returns the name of the specified class, excluding its path.static String
className(Object object)
Returns the class name of the specified object, excluding its path.static void
debug(Object string, Object... ext)
Prints a string to standard error if theProp.debug
flag is set.static void
debug(Throwable throwable)
Prints the exception stack trace if theProp.debug
flag is set.static void
err(String string, Object... ext)
Prints a string to standard error.static void
errln(Object object, Object... ext)
Prints a string to standard error, followed by a newline.static String
error(Process process, int timeout)
Returns the error message of a process.static byte[]
inf(Object string, Object... ext)
Returns a token and replaces all % characters by the specified extensions (seeTokenBuilder.addExt(java.lang.Object, java.lang.Object...)
for details).static String
info(Object string, Object... ext)
Returns a string and replaces all % characters by the specified extensions (seeTokenBuilder.addExt(java.lang.Object, java.lang.Object...)
for details).static String
input()
Returns a single line from standard input.static String
message(Throwable throwable)
Returns a more user-friendly error message for the specified exception.static RuntimeException
notExpected()
Throws a runtime exception for an unexpected exception.static RuntimeException
notExpected(Object message, Object... ext)
Throws a runtime exception for an unexpected exception.static void
out(Object string, Object... ext)
Prints a string to standard output.static void
outln()
Prints a newline to standard output.static void
outln(Object string, Object... ext)
Prints a string to standard output, followed by a newline.static String
password()
Returns a password from standard input.static TokenMap
properties(String name)
Returns the contents of a property resource.static Throwable
rootException(Throwable throwable)
Returns the root query exception.static void
stack(int depth)
Prints the current stack trace to System.err.static void
stack(String message)
Prints the current stack trace to System.err.static void
stack(Throwable throwable)
Prints the stack of the specified error to standard error.static Process
start(Class<?> clazz, String... args)
Starts the specified class in a separate process.
-
-
-
Method Detail
-
bug
public static String bug(Throwable throwable)
Returns an information string for an unexpected exception.- Parameters:
throwable
- exception- Returns:
- dummy object
-
notExpected
public static RuntimeException notExpected()
Throws a runtime exception for an unexpected exception.- Returns:
- runtime exception (indicates that an error is raised)
-
notExpected
public static RuntimeException notExpected(Object message, Object... ext)
Throws a runtime exception for an unexpected exception.- Parameters:
message
- messageext
- optional extension- Returns:
- runtime exception (indicates that an error is raised)
-
className
public static String className(Object object)
Returns the class name of the specified object, excluding its path.- Parameters:
object
- object- Returns:
- class name
-
className
public static String className(Class<?> clazz)
Returns the name of the specified class, excluding its path.- Parameters:
clazz
- class- Returns:
- class name
-
input
public static String input()
Returns a single line from standard input.- Returns:
- string
-
password
public static String password()
Returns a password from standard input.- Returns:
- password or empty string
-
outln
public static void outln()
Prints a newline to standard output.
-
outln
public static void outln(Object string, Object... ext)
Prints a string to standard output, followed by a newline.- Parameters:
string
- output stringext
- text optional extensions
-
out
public static void out(Object string, Object... ext)
Prints a string to standard output.- Parameters:
string
- output stringext
- text optional extensions
-
rootException
public static Throwable rootException(Throwable throwable)
Returns the root query exception.- Parameters:
throwable
- throwable- Returns:
- root exception
-
errln
public static void errln(Object object, Object... ext)
Prints a string to standard error, followed by a newline.- Parameters:
object
- error objectext
- text optional extensions
-
err
public static void err(String string, Object... ext)
Prints a string to standard error.- Parameters:
string
- debug stringext
- text optional extensions
-
message
public static String message(Throwable throwable)
Returns a more user-friendly error message for the specified exception.- Parameters:
throwable
- throwable reference- Returns:
- error message
-
debug
public static void debug(Throwable throwable)
Prints the exception stack trace if theProp.debug
flag is set.- Parameters:
throwable
- exception
-
debug
public static void debug(Object string, Object... ext)
Prints a string to standard error if theProp.debug
flag is set.- Parameters:
string
- debug stringext
- text optional extensions
-
info
public static String info(Object string, Object... ext)
Returns a string and replaces all % characters by the specified extensions (seeTokenBuilder.addExt(java.lang.Object, java.lang.Object...)
for details).- Parameters:
string
- string to be extendedext
- text text extensions- Returns:
- extended string
-
inf
public static byte[] inf(Object string, Object... ext)
Returns a token and replaces all % characters by the specified extensions (seeTokenBuilder.addExt(java.lang.Object, java.lang.Object...)
for details).- Parameters:
string
- string to be extendedext
- text text extensions- Returns:
- token
-
stack
public static void stack(String message)
Prints the current stack trace to System.err.- Parameters:
message
- error message
-
stack
public static void stack(int depth)
Prints the current stack trace to System.err. Used for testing.- Parameters:
depth
- number of steps to print
-
stack
public static void stack(Throwable throwable)
Prints the stack of the specified error to standard error.- Parameters:
throwable
- error/exception instance
-
start
public static Process start(Class<?> clazz, String... args)
Starts the specified class in a separate process. A -D (daemon) flag will be added to the command-line options.- Parameters:
clazz
- class to startargs
- command-line arguments- Returns:
- reference to a
Process
instance representing the started process
-
error
public static String error(Process process, int timeout)
Returns the error message of a process.- Parameters:
process
- processtimeout
- time out in milliseconds- Returns:
- error message or
null
-
-