Top Description Constructors Methods
org.codehaus.groovy.runtime

public Class DefaultGroovyStaticMethods

extends Object
Class Inheritance
Imports
groovy.lang.Closure, org.codehaus.groovy.reflection.ReflectionUtils, org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation, java.io.File, .IOException, java.lang.management.ManagementFactory, .ThreadInfo, .ThreadMXBean, java.nio.file.Files, .Path, java.text.ParseException, .SimpleDateFormat, java.util.Arrays, .Date, .Locale, .ResourceBundle, .TimeZone, java.util.regex.Matcher, java.util.stream.Collectors

This class defines all the new static groovy methods which appear on normal JDK classes inside the Groovy environment. Static methods are used with the first parameter as the destination class.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static File
public static File
createTempDir(File self, final String prefix)

public static File
createTempDir(File self, final String prefix, final String suffix)

private static File
private static Thread
createThread(String name, boolean daemon, Closure<V> closure)

public static long

Returns:

the difference, measured in seconds, between the current time and midnight, January 1, 1970 UTC.
currentTimeSeconds
(System
placeholder variable used by Groovy categories; ignored for default static methods
self
)

Get the current time in seconds

public static String

Returns:

the thread dump of all threads
dumpAll
(Thread
placeholder variable used by Groovy categories; ignored for default static methods
self
)

Dump the thread dump of all threads

public static ResourceBundle

Returns:

the resource bundle
getBundle
(ResourceBundle
placeholder variable used by Groovy categories; ignored for default static methods
self
,
String
the name of the bundle.
bundleName
)

Works exactly like ResourceBundle.getBundle(String).

public static ResourceBundle

Returns:

the resource bundle
getBundle
(ResourceBundle
placeholder variable used by Groovy categories; ignored for default static methods
self
,
String
the name of the bundle.
bundleName
,
Locale
the specific locale
locale
)

Works exactly like ResourceBundle.getBundle(String, Locale).

public static Matcher

Returns:

the last regex matcher
getLastMatcher
(Matcher
placeholder variable used by Groovy categories; ignored for default static methods
self
)

Get the last hidden matcher that the system used to do a match.

public static Date
parse(Date self, String format, String input)

Deprecated
public static Date
parse(Date self, String format, String input, TimeZone zone)

Deprecated
public static Date
parseToStringDate(Date self, String dateToString)

Deprecated
public static void
sleep(Object
placeholder variable used by Groovy categories; ignored for default static methods
self
,
long
the number of milliseconds to sleep
milliseconds
)

Sleep for so many milliseconds, even if interrupted.

public static void
sleep(Object
placeholder variable used by Groovy categories; ignored for default static methods
self
,
long
the number of milliseconds to sleep
milliseconds
,
Closure<V>
interrupt handler, InterruptedException is passed to the Closure as long as it returns false, the sleep continues
onInterrupt
)

Sleep for so many milliseconds, using a given closure for interrupt processing.

private static void
sleepImpl(long
the number of milliseconds to sleep
millis
,
Closure<V>
optional closure called when interrupted as long as the closure returns false the sleep continues
closure
)

This method is used by both sleep() methods to implement sleeping for the given time even if interrupted

public static Thread

Returns:

the started thread
start
(Thread
placeholder variable used by Groovy categories; ignored for default static methods
self
,
Closure<V>
the Runnable closure
closure
)

Start a Thread with the given closure as a Runnable instance.

public static Thread

Returns:

the started thread
start
(Thread
placeholder variable used by Groovy categories; ignored for default static methods
self
,
String
the name to give the thread
name
,
Closure<V>
the Runnable closure
closure
)

Start a Thread with a given name and the given closure as a Runnable instance.

public static Thread

Returns:

the started thread
startDaemon
(Thread
placeholder variable used by Groovy categories; ignored for default static methods
self
,
Closure<V>
the Runnable closure
closure
)

Start a daemon Thread with the given closure as a Runnable instance.

public static Thread

Returns:

the started thread
startDaemon
(Thread
placeholder variable used by Groovy categories; ignored for default static methods
self
,
String
the name to give the thread
name
,
Closure<V>
the Runnable closure
closure
)

Start a daemon Thread with a given name and the given closure as a Runnable instance.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

DefaultGroovyStaticMethodsback to summary
public DefaultGroovyStaticMethods()

Method Detail

createTempDirback to summary
public static File createTempDir(File self) throws IOException
createTempDirback to summary
public static File createTempDir(File self, final String prefix) throws IOException
createTempDirback to summary
public static File createTempDir(File self, final String prefix, final String suffix) throws IOException
createTempDirNioback to summary
private static File createTempDirNio(String prefix) throws IOException
createThreadback to summary
private static Thread createThread(String name, boolean daemon, Closure<V> closure)
currentTimeSecondsback to summary
public static long currentTimeSeconds(System self)

Get the current time in seconds

Parameters
self:System

placeholder variable used by Groovy categories; ignored for default static methods

Returns:long

the difference, measured in seconds, between the current time and midnight, January 1, 1970 UTC.

See Also
System#currentTimeMillis()
dumpAllback to summary
public static String dumpAll(Thread self)

Dump the thread dump of all threads

Parameters
self:Thread

placeholder variable used by Groovy categories; ignored for default static methods

Returns:String

the thread dump of all threads

Since
3.0.0
getBundleback to summary
public static ResourceBundle getBundle(ResourceBundle self, String bundleName)

Works exactly like ResourceBundle.getBundle(String). This is needed because the java method depends on a particular stack configuration that is not guaranteed in Groovy when calling the Java method.

Parameters
self:ResourceBundle

placeholder variable used by Groovy categories; ignored for default static methods

bundleName:String

the name of the bundle.

Returns:ResourceBundle

the resource bundle

Since
1.6.0
See Also
java.util.ResourceBundle#getBundle(java.lang.String)
getBundleback to summary
public static ResourceBundle getBundle(ResourceBundle self, String bundleName, Locale locale)

Works exactly like ResourceBundle.getBundle(String, Locale). This is needed because the java method depends on a particular stack configuration that is not guaranteed in Groovy when calling the Java method.

Parameters
self:ResourceBundle

placeholder variable used by Groovy categories; ignored for default static methods

bundleName:String

the name of the bundle.

locale:Locale

the specific locale

Returns:ResourceBundle

the resource bundle

Since
1.6.0
See Also
java.util.ResourceBundle#getBundle(java.lang.String, java.util.Locale)
getLastMatcherback to summary
public static Matcher getLastMatcher(Matcher self)

Get the last hidden matcher that the system used to do a match.

Parameters
self:Matcher

placeholder variable used by Groovy categories; ignored for default static methods

Returns:Matcher

the last regex matcher

Since
1.0
parseback to summary
public static Date parse(Date self, String format, String input) throws ParseException

Deprecated

Annotations
@Deprecated
parseback to summary
public static Date parse(Date self, String format, String input, TimeZone zone) throws ParseException

Deprecated

Annotations
@Deprecated
parseToStringDateback to summary
public static Date parseToStringDate(Date self, String dateToString) throws ParseException

Deprecated

Annotations
@Deprecated
sleepback to summary
public static void sleep(Object self, long milliseconds)

Sleep for so many milliseconds, even if interrupted.

Parameters
self:Object

placeholder variable used by Groovy categories; ignored for default static methods

milliseconds:long

the number of milliseconds to sleep

Since
1.0
sleepback to summary
public static void sleep(Object self, long milliseconds, Closure<V> onInterrupt)

Sleep for so many milliseconds, using a given closure for interrupt processing.

Parameters
self:Object

placeholder variable used by Groovy categories; ignored for default static methods

milliseconds:long

the number of milliseconds to sleep

onInterrupt:Closure<V>

interrupt handler, InterruptedException is passed to the Closure as long as it returns false, the sleep continues

Since
1.0
sleepImplback to summary
private static void sleepImpl(long millis, Closure<V> closure)

This method is used by both sleep() methods to implement sleeping for the given time even if interrupted

Parameters
millis:long

the number of milliseconds to sleep

closure:Closure<V>

optional closure called when interrupted as long as the closure returns false the sleep continues

startback to summary
public static Thread start(Thread self, Closure<V> closure)

Start a Thread with the given closure as a Runnable instance.

Parameters
self:Thread

placeholder variable used by Groovy categories; ignored for default static methods

closure:Closure<V>

the Runnable closure

Returns:Thread

the started thread

Since
1.0
startback to summary
public static Thread start(Thread self, String name, Closure<V> closure)

Start a Thread with a given name and the given closure as a Runnable instance.

Parameters
self:Thread

placeholder variable used by Groovy categories; ignored for default static methods

name:String

the name to give the thread

closure:Closure<V>

the Runnable closure

Returns:Thread

the started thread

Since
1.6
startDaemonback to summary
public static Thread startDaemon(Thread self, Closure<V> closure)

Start a daemon Thread with the given closure as a Runnable instance.

Parameters
self:Thread

placeholder variable used by Groovy categories; ignored for default static methods

closure:Closure<V>

the Runnable closure

Returns:Thread

the started thread

Since
1.0
startDaemonback to summary
public static Thread startDaemon(Thread self, String name, Closure<V> closure)

Start a daemon Thread with a given name and the given closure as a Runnable instance.

Parameters
self:Thread

placeholder variable used by Groovy categories; ignored for default static methods

name:String

the name to give the thread

closure:Closure<V>

the Runnable closure

Returns:Thread

the started thread

Since
1.6