Groovy Documentation

org.linkedin.glu.agent.api
[Groovy] Interface Shell


interface Shell

Contains shell related methods. Accessible in any script under the variable shell.


Method Summary
java.lang.Object ant(groovy.lang.Closure closure)

Exporting ant access to the shell to run any ant command.

java.lang.String cat(java.lang.Object location)

Returns the content of the location as a String or null if the location is not reachable

java.lang.Object chmod(java.lang.Object file, java.lang.Object perm)

Changes the permission of the file

Resource chmodPlusX(java.lang.Object file)

Shortcut/More efficient implementation of the more generic chmod(Object, Object) call

Resource chmodRecursive(java.lang.Object dir, java.lang.Object perm)

Changes the permission of the dir and recursively

Resource cp(java.lang.Object from, java.lang.Object to)

Copy from to to...

Resource createTempDir()

Create a temporary directory

Resource createTempDir(java.lang.Object args)

Create a temporary directory

java.lang.Object demultiplexExecStream(java.io.InputStream execStream, java.io.OutputStream stdout, java.io.OutputStream stderr)

Demultiplexes the exec stream as generated by exec(Map) when args.res is stream.

java.lang.Object deserializeFromFile(java.lang.Object file)

Reads the content of the file and deserializes it (java serialization).

Resource eachChildRecurse(java.lang.Object dir, java.lang.Object closure)

Every child resource of this resource (recursively) is being passed to the closure.

java.lang.String exec(java.lang.Object executable, java.lang.Object executableArgs)

Executes a shell command... the command will be delegated straight to shell and the output of the shell command is returned.

java.lang.String exec(java.lang.Object executable, java.lang.Object executableArgs)

Executes a shell command... the command will be delegated straight to shell and the output of the shell command is returned.

java.lang.String exec(java.lang.String command)

Executes a shell command... the command will be delegated straight to shell and the output of the shell command is returned.

java.lang.String exec(java.util.Collection command)

Executes a shell command... the command will be delegated straight to shell and the output of the shell command is returned.

java.lang.Object exec(java.util.Map args)

More generic form of the exec call which allows you to configure what you provide and what you expect.

void fail(java.lang.Object message)

Calling this method will force a script failure (will throw an exception)

Resource fetch(java.lang.Object location)

Fetches the file pointed to by the location.

Resource fetch(java.lang.Object location, java.lang.Object destination)

Fetches the file pointed to by the location.

java.lang.Object findAll(java.lang.Object dir, java.lang.Object closure)

Every child resource of this resource (recursively) is being passed to the closure.

java.util.Map getEnv()

@return all the environment properties exposed by the glu agent (most are coming from its configuration, others are computed (like glu.agent.pid which is the pid of the agent).

java.util.Collection getMimeTypes(java.lang.Object file)

Try to guess the mime types of a given file

Resource getRoot()

the root of the file system used by this shell.

Resource getTmpRoot()

the tmp root of the file system used by this shell.

java.util.Collection grep(java.lang.Object location, java.lang.Object pattern)

Similarly to the unix grep command, checks the location one line at a time and returns all the lines which matches the pattern.

java.lang.Object grep(java.lang.Object location, java.lang.Object pattern, java.lang.Object options)

Similarly to the unix grep command, checks the location one line at a time and returns all the lines which matches the pattern

Resource gunzip(java.lang.Object file)

Gunzips the provided file in a temporary location

Resource gunzip(java.lang.Object file, java.lang.Object toFile)

Gunzips the provided file in the provided location

Resource gzip(java.lang.Object file)

Compresses the provided file (in the same folder)

Resource gzip(java.lang.Object file, java.lang.Object toFile)

Compresses the provided file as toFile

java.util.Map gzipFileOrFolder(java.lang.Object fileOrFolder, boolean recurse)

Compresses each file in a folder

java.util.Map httpHead(java.lang.Object location)

Issue a 'HEAD' request.

java.util.Map httpPost(java.lang.Object location, java.util.Map parameters)

Issue a 'POST' request.

boolean listening(java.lang.Object server, java.lang.Object port)

@return true if there is a socket open on the server/port combination

java.lang.Object ls(java.lang.Object dir, groovy.lang.Closure closure)

@param dir starting point for listing ({@see #toResource(Object)} for possible values)

java.lang.Object ls(java.lang.Object dir)

list all the files under the provided directory (or root if not provided) (not recursive)

java.lang.Object ls()

list all the files under root only (not recursive)

java.lang.Object ls(groovy.lang.Closure closure)

Same as the other ls, but starts at root

Resource mkdirs(java.lang.Object dir)

Create the directory as well as its parents if they don't exist

Resource mv(java.lang.Object from, java.lang.Object to)

Move from to to...

java.lang.Object noException(groovy.lang.Closure closure)

Runs the closure in a protected block that will not throw an exception but will return null in the case one happens

java.lang.String readContent(java.lang.Object file)

reads the content from the file and return it as a String

java.lang.String replaceTokens(java.lang.String input, java.util.Map tokens)

Replaces the tokens provided in the map in the input.

Resource replaceTokens(java.lang.Object from, java.lang.Object to, java.util.Map tokens)

Processes from through the replacement token mechanism and writes the result to to

void rm(java.lang.Object file)

Delete the file

void rmEmptyDirs(java.lang.Object dir)

Remove all empty directories (that are children (recursively) of the provided directory).

void rmdirs(java.lang.Object dir)

Delete the directory (recursive)

java.lang.Object safeOverwrite(java.lang.Object file, groovy.lang.Closure closure)

This convenient call takes a file you want to (over)write to and a closure.

Resource saveContent(java.lang.Object file, java.lang.String content)

creates a file and populate its content with the provided (String) content

Resource saveContent(java.lang.Object file, java.lang.String content, java.util.Map tokens)

Processes the content to the token replacement method.

Resource serializeToFile(java.lang.Object file, java.lang.Object serializable)

Serializes (java serialization!)

java.io.InputStream tail(java.lang.Object file, long maxLine)

Tail the file

java.io.InputStream tail(java.lang.Object args)

Tail the file

Resource tempFile(java.lang.Object args)

Creates a temp file:

Resource tempFile()

Creates a temp file with all default values

Resource toResource(java.lang.Object file)

Returns a resource relative to this filesystem.

Resource untar(java.lang.Object file)

Untars the provided file in a temporary location.

Resource untar(java.lang.Object file, java.lang.Object toDir)

Untars the provided file in the provided location.

Resource untarAndDecrypt(java.lang.Object file, java.lang.Object toDir, java.lang.Object encryptionKeys)

untar + decrypt using the encryption keys (encrytion keys are automatically provided by glu and are available in any glu script with args.encriptionKeys)

Resource unzip(java.lang.Object file)

Unzips the provided file in a temporary location

Resource unzip(java.lang.Object file, java.lang.Object toDir)

Unzips the provided file in the provided location

boolean waitFor(java.lang.Object args, groovy.lang.Closure condition)

Waits for the condition to be true no longer than the timeout.

boolean waitFor(groovy.lang.Closure condition)

Shortcut when no args

java.lang.Object withInputStream(java.lang.Object file, java.lang.Object closure)

Safe pattern to read from a file: you provide the file and the closure gets called back with an java.io.InputStream object as an argument so you don't have to worry about closing it.

java.lang.Object withMBeanServerConnection(java.lang.Object pid, groovy.lang.Closure closure)

Invokes the closure with an MBeanServerConnection to the jmx control running on the vm started with the provided pid.

java.lang.Object withObjectInputStream(java.lang.Object file, java.lang.Object closure)

Safe pattern to read from a file: you provide the file and the closure gets called back with an java.io.ObjectInputStream object as an argument so you don't have to worry about closing it.

java.lang.Object withObjectOutputStream(java.lang.Object file, java.lang.Object closure)

Safe pattern to write to a file: you provide the file and the closure gets called back with an java.io.ObjectOutputStream object as an argument so you don't have to worry about closing it.

java.lang.Object withOutputStream(java.lang.Object file, java.lang.Object closure)

Safe pattern to write to a file: you provide the file and the closure gets called back with an java.io.OutputStream object as an argument so you don't have to worry about closing it.

java.lang.Object withReader(java.lang.Object file, groovy.lang.Closure closure)

Same as withInputStream but wraps in a reader using a configured charset (defaults to UTF-8).

java.lang.Object withWriter(java.lang.Object file, groovy.lang.Closure closure)

Same as withOutputStream but wraps in a writer using a configured charset (defaults to UTF-8).

 

Method Detail

ant

java.lang.Object ant(groovy.lang.Closure closure)
Exporting ant access to the shell to run any ant command.
Returns:
whatever the closure returns


cat

java.lang.String cat(java.lang.Object location)
Returns the content of the location as a String or null if the location is not reachable
Parameters:
location - the location you want to fetch (usually remote)
Returns:
the content as a Strint or null


chmod

java.lang.Object chmod(java.lang.Object file, java.lang.Object perm)
Changes the permission of the file
Parameters:
file - ({@see #toResource(Object)} for possible values)
perm - expressed in unix fashion (ex: +x)
Returns:
the Resource representation of the file


chmodPlusX

Resource chmodPlusX(java.lang.Object file)
Shortcut/More efficient implementation of the more generic chmod(Object, Object) call
Parameters:
file - ({@see #toResource(Object)} for possible values)
Returns:
file as a Resource


chmodRecursive

Resource chmodRecursive(java.lang.Object dir, java.lang.Object perm)
Changes the permission of the dir and recursively
Parameters:
dir - ({@see #toResource(Object)} for possible values)
perm - expressed in unix fashion (ex: +x)
Returns:
the Resource representation of the dir


cp

Resource cp(java.lang.Object from, java.lang.Object to)
Copy from to to...
Parameters:
from - ({@see #toResource(Object)} for possible values)
to - ({@see #toResource(Object)} for possible values)
Returns:
the Resource representation of to


createTempDir

Resource createTempDir()
Create a temporary directory


createTempDir

Resource createTempDir(java.lang.Object args)
Create a temporary directory
See Also:
for details on the options


demultiplexExecStream

java.lang.Object demultiplexExecStream(java.io.InputStream execStream, java.io.OutputStream stdout, java.io.OutputStream stderr)
Demultiplexes the exec stream as generated by exec(Map) when args.res is stream. The following is equivalent: OutputStream myStdout = ... OutputStream myStderr = ... exec(command: xxx, stdout: myStdout, stderr: myStderr, res: exitValue) is 100% equivalent to: demultiplexExecStream(exec(command: xxx, res: stream), myStdout, myStderr)
throws:
org.linkedin.glu.agent.api.ShellExecException when there was an error executing the shell script and args.failOnError was set to true
Parameters:
execStream - the stream as generated by exec(Map)
stdout - the stream to write the output (optional, can be null)
stderr - the stream to write the error (optional, can be null)
Returns:
the value returned by the executed subprocess


deserializeFromFile

java.lang.Object deserializeFromFile(java.lang.Object file)
Reads the content of the file and deserializes it (java serialization). In order to be deserializable, the classpath must contain the classes required.
Parameters:
file - ({@see #toResource(Object)} for possible values)
Returns:
whatever was deserialized


eachChildRecurse

Resource eachChildRecurse(java.lang.Object dir, java.lang.Object closure)
Every child resource of this resource (recursively) is being passed to the closure.
Parameters:
dir - where to start the recursion ({@see #toResource(Object)} for possible values)
closure - will be called back for all children (recursively) as a Resource and can do whatever it wants with it (return value will be ignored)
Returns:
the Resource representation of the dir


exec

java.lang.String exec(java.lang.Object executable, java.lang.Object executableArgs)
Executes a shell command... the command will be delegated straight to shell and the output of the shell command is returned.
Parameters:
executable - ({@see #toResource(Object)} for possible values)
executableArgs - either a String or a Collection
Returns:
whatever output the shell command returns


exec

java.lang.String exec(java.lang.Object executable, java.lang.Object executableArgs)
Executes a shell command... the command will be delegated straight to shell and the output of the shell command is returned.


exec

java.lang.String exec(java.lang.String command)
Executes a shell command... the command will be delegated straight to shell and the output of the shell command is returned.
Parameters:
command - the full command (including the arguments) as a String
Returns:
whatever output the shell command returns


exec

java.lang.String exec(java.util.Collection command)
Executes a shell command... the command will be delegated straight to shell and the output of the shell command is returned.
Parameters:
command - the full command (including the arguments) as a Collection
Returns:
whatever output the shell command returns


exec

java.lang.Object exec(java.util.Map args)
More generic form of the exec call which allows you to configure what you provide and what you expect. This call is blocking (unless you request a stream for the result). - Note that if you provide a closure for args.stdout or args.stderr it will be executed in a separate thread (in order to avoid blocking indefinitely). - Note that if you request stdout, stderr or all for the result of this call, stdout and stderr are converted to a String using (by default) the "UTF-8" charset and all lines are terminated with "\n" and the last "\n" is removed. Use stdoutBytes or stderrBytes if you wish to get the bytes directly - Note that if you request stream, then the call return immediately (it is non blocking in this case) and you get a single InputStream which multiplexes stdout/stderr and exit value (see MultiplexedInputStream for details). In this case you should make sure to read the entire stream and properly close it as shown in the following code example: InputStream stream = shell.exec(command: 'xxx', res: 'stream') try { // read stream } finally { stream.close() } - Note that if you request stdoutStream or stderrStream, then the call return immediately (it is non blocking in this case) and you get the stream you requested. In this case you should make sure to read the entire stream and properly close it as shown in the following code example: InputStream stream = shell.exec(command: 'xxx', res: 'stdoutStream') try { // read stream } finally { stream.close() }
Parameters:
args.command - the command to execute. It will be delegated to the shell so it should be native to the OS on which the agent runs (either a String or a Collection) (required)
args.pwd - the directory from which the command will be run (optional, will default to the "current" directory)
args.env - a map (String, String) containing environment variables to be passed to sub-process. If the value is null, it will remove it from the inherited environment variables. (optional)
args.inheritEnv - a boolean to determine if the environment variables in effect in the agent will be passed down to the sub-process (optional, default to true)
args.stdin - any input that can "reasonably" be converted into an InputStream) to provide to the command line execution (optional, default to no stdin)
args.stdout - Closure (if you want to handle it yourself), OutputStream (where stdout will be written to), (optional: depends on args.res)
args.stderr - Closure (if you want to handle it yourself), OutputStream (where stdout will be written to), (optional: depends on args.res)
args.redirectStderr - boolean to redirect stderr into stdout (optional, default to false). Note that this can also be accomplished with the command itself with something like "2>&1"
args.failOnError - do you want the command to fail (with an exception) when there is an error (default to true)
args.res - what do you want the call to return stdout, stdoutBytes, stdoutStream stderr, stderrBytes, stderrStream all, allBytes (a map with 3 parameters, exitValue, stdout, stderr) exitValue, stream (default to stdout)
Returns:
whatever is specified in args.res


fail

void fail(java.lang.Object message)
Calling this method will force a script failure (will throw an exception)


fetch

Resource fetch(java.lang.Object location)
Fetches the file pointed to by the location. If the location is already a java.io.File then simply returns it. The location can be a String or URI and must contain a scheme. Example of locations: http://locahost:8080/file.txt', file:/tmp/file.txt, ivy:/org.linkedin/util-core/1.0.0.
Parameters:
location - the location you want to fetch (usually remote)
Returns:
where the location was fetched (locally) (as a Resource)


fetch

Resource fetch(java.lang.Object location, java.lang.Object destination)
Fetches the file pointed to by the location. The location can be File, a String or URI and must contain a scheme. Example of locations: http://locahost:8080/file.txt', file:/tmp/file.txt, ivy:/org.linkedin/util-core/1.0.0. The difference with the other fetch method is that it fetches the file in the provided destination rather than in the tmp space.
Parameters:
location - the location you want to fetch (usually remote)
destination - ({@see #toResource(Object)} for possible values)
Returns:
where the location was fetched (locally) (as a Resource) (if destination is a file then returns destination as a Resource otherwise it will be a Resource inside the destination folder.


findAll

java.lang.Object findAll(java.lang.Object dir, java.lang.Object closure)
Every child resource of this resource (recursively) is being passed to the closure. If the closure returns true then it will be part of the result.
Parameters:
dir - where to start the recursion ({@see #toResource(Object)} for possible values)
closure - will be called back for all children (recursively) as a Resource and should return true or false
Returns:
the list of all resources where the closure returned true


getEnv

java.util.Map getEnv()
Returns:
all the environment properties exposed by the glu agent (most are coming from its configuration, others are computed (like glu.agent.pid which is the pid of the agent).


getMimeTypes

java.util.Collection getMimeTypes(java.lang.Object file)
Try to guess the mime types of a given file
Parameters:
file - ({@see #toResource(Object)} for possible values)
Returns:
a list of mime types (strings)


getRoot

Resource getRoot()
the root of the file system used by this shell. All files created or returned by any methods on this class will be under this root (except for temp files)


getTmpRoot

Resource getTmpRoot()
the tmp root of the file system used by this shell. All temp files created will be under this root


grep

java.util.Collection grep(java.lang.Object location, java.lang.Object pattern)
Similarly to the unix grep command, checks the location one line at a time and returns all the lines which matches the pattern.
Parameters:
location - (see fetch(Object) for possible values)
pattern - regular expression (see java pattern)
Returns:
a list of strings


grep

java.lang.Object grep(java.lang.Object location, java.lang.Object pattern, java.lang.Object options)
Similarly to the unix grep command, checks the location one line at a time and returns all the lines which matches the pattern
Parameters:
location - (see fetch(Object) for possible values)
pattern - regular expression (see java pattern)
options - options to the command: out: an object to output the lines which match (default to []) count: returns the count only (does not use out) maxCount: stop reading after maxCount matches
Returns:
depends on options


gunzip

Resource gunzip(java.lang.Object file)
Gunzips the provided file in a temporary location
Parameters:
file - ({@see #toResource(Object)} for possible values)
Returns:
the location of the temporary location (as a Resource)


gunzip

Resource gunzip(java.lang.Object file, java.lang.Object toFile)
Gunzips the provided file in the provided location
Parameters:
file - ({@see #toResource(Object)} for possible values)
toDir - ({@see #toResource(Object)} for possible values)
Returns:
toDir (as a Resource)


gzip

Resource gzip(java.lang.Object file)
Compresses the provided file (in the same folder)
Parameters:
file - ({@see #toResource(Object)} for possible values)
Returns:
the gziped file or the original file if not zipped (as a Resource)


gzip

Resource gzip(java.lang.Object file, java.lang.Object toFile)
Compresses the provided file as toFile
Parameters:
file - ({@see #toResource(Object)} for possible values)
toFile - ({@see #toResource(Object)} for possible values)
Returns:
toFile (as a Resource)


gzipFileOrFolder

java.util.Map gzipFileOrFolder(java.lang.Object fileOrFolder, boolean recurse)
Compresses each file in a folder
Parameters:
fileOrFolder - a file (behaves like gzip(Object)) or a folder ({@see #toResource(Object)} for possible values)
recurse - if true then recursively process all folders
Returns:
a map with key is resource and value is delta in size (original - new) (note that it contains only the resources that are modified!)


httpHead

java.util.Map httpHead(java.lang.Object location)
Issue a 'HEAD' request. The location should be an http or https link.
Parameters:
location
Returns:
a map with the following entries: responseCode: 200, 404... java.net.HttpURLConnection#getResponseCode() responseMessage: message java.net.HttpURLConnection#getResponseMessage() headers: representing all the headers java.net.URLConnection#getHeaderFields()


httpPost

java.util.Map httpPost(java.lang.Object location, java.util.Map parameters)
Issue a 'POST' request. The location should be an http or https link. The request will be made with application/x-www-form-urlencoded content type.
Parameters:
location
parameters - the parameters of the post as map of key value pairs (value can be a single value or a collection of values)
Returns:
a map with the following entries: responseCode: 200, 404... java.net.HttpURLConnection#getResponseCode() responseMessage: message java.net.HttpURLConnection#getResponseMessage() headers: representing all the headers java.net.URLConnection#getHeaderFields()


listening

boolean listening(java.lang.Object server, java.lang.Object port)
Returns:
true if there is a socket open on the server/port combination


ls

java.lang.Object ls(java.lang.Object dir, groovy.lang.Closure closure)
Parameters:
dir - starting point for listing ({@see #toResource(Object)} for possible values)
closure - the closure (dsl) containing include(name: '') and exclude(name: '') values
Returns:
an array of Resource


ls

java.lang.Object ls(java.lang.Object dir)
list all the files under the provided directory (or root if not provided) (not recursive)
Parameters:
dir - starting point for listing ({@see #toResource(Object)} for possible values)
Returns:
an array of Resource


ls

java.lang.Object ls()
list all the files under root only (not recursive)
Returns:
an array of Resource


ls

java.lang.Object ls(groovy.lang.Closure closure)
Same as the other ls, but starts at root
Parameters:
closure - the closure (dsl) containing include(name: '') and exclude(name: '') values
Returns:
an array of Resource


mkdirs

Resource mkdirs(java.lang.Object dir)
Create the directory as well as its parents if they don't exist
Parameters:
dir - directory to create ({@see #toResource(Object)} for possible values)
Returns:
the Resource representation of the dir


mv

Resource mv(java.lang.Object from, java.lang.Object to)
Move from to to... (rename if file)
Parameters:
from - ({@see #toResource(Object)} for possible values)
to - ({@see #toResource(Object)} for possible values)
Returns:
the Resource representation of to


noException

java.lang.Object noException(groovy.lang.Closure closure)
Runs the closure in a protected block that will not throw an exception but will return null in the case one happens
Returns:
whatever the closure returns unless there is an exception in which case it will return null (and log the exception as a debug message)


readContent

java.lang.String readContent(java.lang.Object file)
reads the content from the file and return it as a String
Parameters:
file - ({@see #toResource(Object)} for possible values)
Returns:
the content


replaceTokens

java.lang.String replaceTokens(java.lang.String input, java.util.Map tokens)
Replaces the tokens provided in the map in the input. Token replacement is using ant token replacement class so in the input, the tokens are surrounded by the '@' sign. Example:
 input = "abcd @myToken@"
 assert "abcd foo" == replaceTokens(input, [myToken: 'foo'])
 


replaceTokens

Resource replaceTokens(java.lang.Object from, java.lang.Object to, java.util.Map tokens)
Processes from through the replacement token mechanism and writes the result to to
Parameters:
from - ({@see #toResource(Object)} for possible values)
to - ({@see #toResource(Object)} for possible values)}
tokens - a map of token
Returns:
to as a Resource
See Also:
replaceTokens(String, Map)


rm

void rm(java.lang.Object file)
Delete the file
Parameters:
file - ({@see #toResource(Object)} for possible values)


rmEmptyDirs

void rmEmptyDirs(java.lang.Object dir)
Remove all empty directories (that are children (recursively) of the provided directory).
Parameters:
dir - ({@see #toResource(Object)} for possible values)


rmdirs

void rmdirs(java.lang.Object dir)
Delete the directory (recursive)
Parameters:
dir - ({@see #toResource(Object)} for possible values)


safeOverwrite

java.lang.Object safeOverwrite(java.lang.Object file, groovy.lang.Closure closure)
This convenient call takes a file you want to (over)write to and a closure. The closure is called back with another resource in the same folder that you can write to and then rename the file to the one you wanted. The fact that it is in the same folder ensures that the rename should be quick and not really require any copy thus is less likely to fail. If the rename fails it throws an exception, thus ensuring that if there was an original file it won't be in a partial state.
throws:
IOException if cannot rename the file
Parameters:
file - the final file where you want your output to be ({@see #toResource(Object)} for possible values)
closure - takes a Resource as a parameter that you should use
Returns:
whatever the closure returns


saveContent

Resource saveContent(java.lang.Object file, java.lang.String content)
creates a file and populate its content with the provided (String) content
Parameters:
file - ({@see #toResource(Object)} for possible values)
content - the content to store in the file
Returns:
the Resource representation of the file


saveContent

Resource saveContent(java.lang.Object file, java.lang.String content, java.util.Map tokens)
Processes the content to the token replacement method.
See Also:
saveContent(Object, String)


serializeToFile

Resource serializeToFile(java.lang.Object file, java.lang.Object serializable)
Serializes (java serialization!) the serializable provided and store in the file
Parameters:
file - ({@see #toResource(Object)} for possible values)
serializable - the object that needs to be serialized
Returns:
the Resource representation of the file


tail

java.io.InputStream tail(java.lang.Object file, long maxLine)
Tail the file
params:
file the file to tail ({@see #toResource(Object)} for possible values)
params:
maxLine the number of lines maximum to read
Returns:
the input stream to read the content of the tail


tail

java.io.InputStream tail(java.lang.Object args)
Tail the file
params:
args.location the location of the file to tail ({@see #toResource(Object)} for possible values)
params:
args.maxLine the number of lines maximum to read (-1 for the entire file)
params:
args.maxSize the maximum size to read (-1 for the entire file)
Returns:
the input stream to read the content of the tail


tempFile

Resource tempFile(java.lang.Object args)
Creates a temp file:
Parameters:
args.destdir - where the file should be created (optional)
args.prefix - a prefix for the file (optional)
args.suffix - a suffix for the file (optional)
args.deleteonexit - if the temp file should be deleted on exit (default to
args.createParents - if the parent directories should be created (default to true)
Returns:
a file (note that it is just a file object and that the actual file has *not* been created and the parents may have been depending on the args.createParents value)


tempFile

Resource tempFile()
Creates a temp file with all default values


toResource

Resource toResource(java.lang.Object file)
Returns a resource relative to this filesystem.
Parameters:
file - can be of type, java.io.File, org.linkedin.util.io.resource.Resource, java.net.URI, java.lang.String (which can be converted into a URI)


untar

Resource untar(java.lang.Object file)
Untars the provided file in a temporary location. Note that the implementation will try to detect if the file is also gziped and unzip it first (equivalent to tar -zxf)
Parameters:
file - ({@see #toResource(Object)} for possible values)
Returns:
the location of the temporary location (as a Resource)


untar

Resource untar(java.lang.Object file, java.lang.Object toDir)
Untars the provided file in the provided location. Note that the implementation will try to detect if the file is also gziped and unzip it first (equivalent to tar -zxf)
Parameters:
file - ({@see #toResource(Object)} for possible values)
Returns:
toDir (as a Resource)


untarAndDecrypt

Resource untarAndDecrypt(java.lang.Object file, java.lang.Object toDir, java.lang.Object encryptionKeys)
untar + decrypt using the encryption keys (encrytion keys are automatically provided by glu and are available in any glu script with args.encriptionKeys)
Parameters:
file - ({@see #toResource(Object)} for possible values)
toDir - ({@see #toResource(Object)} for possible values)
encryptionKeys
Returns:
toDir (as a Resource)


unzip

Resource unzip(java.lang.Object file)
Unzips the provided file in a temporary location
Parameters:
file - ({@see #toResource(Object)} for possible values)
Returns:
the location of the temporary location (as a Resource)


unzip

Resource unzip(java.lang.Object file, java.lang.Object toDir)
Unzips the provided file in the provided location
Parameters:
file - ({@see #toResource(Object)} for possible values)
toDir - ({@see #toResource(Object)} for possible values)
Returns:
toDir (as a Resource)


waitFor

boolean waitFor(java.lang.Object args, groovy.lang.Closure condition)
Waits for the condition to be true no longer than the timeout. true is returned if the condition was satisfied, false otherwise (if you specify noException)
Parameters:
args.timeout - how long max to wait (any value convertible to a Timespan)
args.heartbeat - how long to wait between calling the condition (any value convertible to a Timespan)
args.noException - to get false instead of an exception
condition - the closure should return true if the condition is satisfied, false otherwise
Returns:
true if condition was satisfied within the timeout, false otherwise (if args.noException is provided otherwise an exception will be raised)


waitFor

boolean waitFor(groovy.lang.Closure condition)
Shortcut when no args
See Also:
waitFor(Object, Closure)


withInputStream

java.lang.Object withInputStream(java.lang.Object file, java.lang.Object closure)
Safe pattern to read from a file: you provide the file and the closure gets called back with an java.io.InputStream object as an argument so you don't have to worry about closing it.
Parameters:
file - ({@see #toResource(Object)} for possible values)
closure - the callback (takes an java.io.InputStream as argument)
Returns:
whatever the closure returns


withMBeanServerConnection

java.lang.Object withMBeanServerConnection(java.lang.Object pid, groovy.lang.Closure closure)
Invokes the closure with an MBeanServerConnection to the jmx control running on the vm started with the provided pid. The closure will be invoked with null if cannot determine the process.
Parameters:
pid - the pid of the process you want to get an mbean connection
closure - will be called back with a MBeanServerConnection (which will be null if cannot connect)
Returns:
whatever the closure returns


withObjectInputStream

java.lang.Object withObjectInputStream(java.lang.Object file, java.lang.Object closure)
Safe pattern to read from a file: you provide the file and the closure gets called back with an java.io.ObjectInputStream object as an argument so you don't have to worry about closing it.
Parameters:
file - ({@see #toResource(Object)} for possible values)
closure - the callback (takes an java.io.ObjectInputStream as argument)
Returns:
whatever the closure returns


withObjectOutputStream

java.lang.Object withObjectOutputStream(java.lang.Object file, java.lang.Object closure)
Safe pattern to write to a file: you provide the file and the closure gets called back with an java.io.ObjectOutputStream object as an argument so you don't have to worry about closing it. Note that the implementation use safeOverwrite(Object, Closure) under the cover making it safe to overwrite previous content.
Parameters:
file - ({@see #toResource(Object)} for possible values)
closure - the callback (takes an java.io.ObjectOutputStream as argument)
Returns:
whatever the closure returns


withOutputStream

java.lang.Object withOutputStream(java.lang.Object file, java.lang.Object closure)
Safe pattern to write to a file: you provide the file and the closure gets called back with an java.io.OutputStream object as an argument so you don't have to worry about closing it. Note that the implementation use safeOverwrite(Object, Closure) under the cover making it safe to overwrite previous content.
Parameters:
file - ({@see #toResource(Object)} for possible values)
closure - the callback (takes an java.io.OutputStream as argument)
Returns:
whatever the closure returns


withReader

java.lang.Object withReader(java.lang.Object file, groovy.lang.Closure closure)
Same as withInputStream but wraps in a reader using a configured charset (defaults to UTF-8).
Parameters:
file - ({@see #toResource(Object)} for possible values)
Returns:
whatever the closure returns


withWriter

java.lang.Object withWriter(java.lang.Object file, groovy.lang.Closure closure)
Same as withOutputStream but wraps in a writer using a configured charset (defaults to UTF-8).
Parameters:
file - ({@see #toResource(Object)} for possible values)
Returns:
whatever the closure returns


 

Groovy Documentation