|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.linkedin.util.io.IOUtils
org.linkedin.groovy.util.io.GroovyIOUtils
class GroovyIOUtils extends IOUtils
IO related utilities
Constructor Summary | |
protected GroovyIOUtils()
|
Method Summary | |
---|---|
static java.lang.String
|
cat(java.lang.Object location)
Returns the content of the location as a |
static Resource
|
eachChildRecurse(Resource resource, groovy.lang.Closure closure)
The closure will be called for every child (recursively) of the provided resource |
static void
|
eachLine(java.io.Reader reader, groovy.lang.Closure closure)
The difference between |
static void
|
eachLine(java.net.URL url, groovy.lang.Closure closure)
Convenient call which calls {@link #eachLine(Reader, Closure). |
static java.io.File
|
fetchContent(java.lang.Object location, java.io.File destination)
Fetches the file pointed to by the location. |
static java.lang.Object
|
findAll(Resource resource, groovy.lang.Closure closure)
Every child resource of this resource (recursively) is being passed to the closure. |
static boolean
|
isChild(java.io.File parent, java.io.File child)
|
static java.io.File
|
makeRelativeToParent(java.io.File parent, java.io.File child)
Ex: parent=/a/b/c child='/a/b/c/d/e'... would return d/e |
static java.io.File
|
mkdirs(java.io.File dir)
Creates the directory and parents of the provided directory. |
static java.lang.Object
|
safeOverwrite(java.io.File toFile, groovy.lang.Closure closure)
This convenient call takes a file you want to (over)write to and a closure. |
static java.lang.Object
|
safeOverwrite(java.io.File toFile, groovy.lang.Closure tempFileFactory, groovy.lang.Closure closure)
This variant takes a |
static java.io.File
|
toFile(java.lang.Object s)
returns a file... handles |
static java.io.File
|
toFile(java.lang.Object s, java.io.File tempFolder)
returns a file... handles |
static java.util.Map
|
toFileWithTempStatus(java.lang.Object s, java.io.File tempFolder)
handles |
static java.lang.Object
|
withFile(java.lang.Object s, groovy.lang.Closure closure)
Will convert |
Constructor Detail |
---|
protected GroovyIOUtils()
Method Detail |
---|
static java.lang.String cat(java.lang.Object location)
String
static Resource eachChildRecurse(Resource resource, groovy.lang.Closure closure)
static void eachLine(java.io.Reader reader, groovy.lang.Closure closure)
reader.eachLine()
and this method is that
as soon as the closure returns false
then the iteration is stopped. There is no
way to stop the iteration with reader.eachLine()
.
static void eachLine(java.net.URL url, groovy.lang.Closure closure)
static java.io.File fetchContent(java.lang.Object location, java.io.File destination)
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
.
location
- where is the content you want to retrieve locallydestination
- where to store the content locallydestination
static java.lang.Object findAll(Resource resource, groovy.lang.Closure closure)
true
then it will be part of the result.
static boolean isChild(java.io.File parent, java.io.File child)
true
if child is really a child of parent or in other words if child
is located in a subpath of parent (handle canonical path properly)
static java.io.File makeRelativeToParent(java.io.File parent, java.io.File child)
null
if child is not a child of parent! If child is relative the return child
static java.io.File mkdirs(java.io.File dir)
static java.lang.Object safeOverwrite(java.io.File toFile, groovy.lang.Closure closure)
toFile
- the final file where you want your output to beclosure
- takes a File
as a parameter that you should use
static java.lang.Object safeOverwrite(java.io.File toFile, groovy.lang.Closure tempFileFactory, groovy.lang.Closure closure)
tempFileFactory
if you want to control precisely where
and how the temporary file is created (note that if the tempoary file is not created in the
same folder as toFile
then the rename operation may actually be a copy/delete
instead of just a rename thus defeating the purpose of this method!)
toFile
- the final file where you want your output to betempFileFactory
- closure which takes toFile
as an argument and returns
a temporary fileclosure
- takes a File
as a parameter that you should use
static java.io.File toFile(java.lang.Object s)
File
, URI, URL, string, null
static java.io.File toFile(java.lang.Object s, java.io.File tempFolder)
File
, URI, URL, string, null
tempFolder
- if the file is not local, where to store it temporarilly (null
means standard java vm temp folder)
static java.util.Map toFileWithTempStatus(java.lang.Object s, java.io.File tempFolder)
File
, URI, URL, string, null
returns a map with file
and tempStatus
(boolean
)
tempFolder
- if the file is not local, where to store it temporarilly (null
means standard java vm temp folder)
static java.lang.Object withFile(java.lang.Object s, groovy.lang.Closure closure)
s
into a File
object (if possible) and call
the closure with it. Once the closure is over, if the file was not local (and as a result was
copied locally for the duration of the closure) it will be deleted. As a result the closure
should *not* store the File
object around for later use or assume that the
underlying file will still exist at a later point. Use toFile(Object) instead if
this is what you want to do.
s
- handles File
, URI, URL, string, null
closure
- will be called back with a File
object (or null
)
Groovy Documentation