提交 46b540e5 编写于 作者: K kohsuke

added more convenience methods

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@18259 71c3de6d-444a-0410-be80-ed276b4c234a
上级 12eda4f6
...@@ -929,6 +929,22 @@ public final class FilePath implements Serializable { ...@@ -929,6 +929,22 @@ public final class FilePath implements Serializable {
return list((FileFilter)null); 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)}. * List up files in this directory, just like {@link File#listFiles(FileFilter)}.
* *
...@@ -1015,6 +1031,18 @@ public final class FilePath implements Serializable { ...@@ -1015,6 +1031,18 @@ public final class FilePath implements Serializable {
return p.getIn(); 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. * Writes to this file.
* If this file already exists, it will be overwritten. * If this file already exists, it will be overwritten.
...@@ -1087,6 +1115,30 @@ public final class FilePath implements Serializable { ...@@ -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. * Copies this file to the specified target.
*/ */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册