mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-10-30 04:55:21 +00:00
added more convenience methods
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@18259 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
12eda4f6d4
commit
46b540e5eb
1 file changed
+52
@@ -929,6 +929,22 @@ public final class FilePath implements Serializable {
|
||||
return list((FileFilter)null);
|
||||
}
|
||||
|
||||
/**
|
||||
* List up subdirectories.
|
||||
*
|
||||
* @return can be empty but never null. Doesn't contain "." and ".."
|
||||
*/
|
||||
public List<FilePath> listDirectories() throws IOException, InterruptedException {
|
||||
return list(new DirectoryFilter());
|
||||
}
|
||||
|
||||
private static final class DirectoryFilter implements FileFilter, Serializable {
|
||||
public boolean accept(File f) {
|
||||
return f.isDirectory();
|
||||
}
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
||||
/**
|
||||
* List up files in this directory, just like {@link File#listFiles(FileFilter)}.
|
||||
*
|
||||
@@ -1015,6 +1031,18 @@ public final class FilePath implements Serializable {
|
||||
return p.getIn();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads this file into a string, by using the current system encoding.
|
||||
*/
|
||||
public String readToString() throws IOException {
|
||||
InputStream in = read();
|
||||
try {
|
||||
return IOUtils.toString(in);
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes to this file.
|
||||
* If this file already exists, it will be overwritten.
|
||||
@@ -1087,6 +1115,30 @@ public final class FilePath implements Serializable {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves all the contents of this directory into the specified directory, then delete this directory itself.
|
||||
*
|
||||
* @since 1.308.
|
||||
*/
|
||||
public void moveAllChildrenTo(final FilePath target) throws IOException, InterruptedException {
|
||||
if(this.channel != target.channel) {
|
||||
throw new IOException("pullUpTo target must be on the same host");
|
||||
}
|
||||
act(new FileCallable<Void>() {
|
||||
public Void invoke(File f, VirtualChannel channel) throws IOException {
|
||||
File t = new File(target.getRemote());
|
||||
|
||||
for(File child : f.listFiles()) {
|
||||
File target = new File(t, child.getName());
|
||||
if(!child.renameTo(target))
|
||||
throw new IOException("Failed to rename "+child+" to "+target);
|
||||
}
|
||||
f.delete();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies this file to the specified target.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user