本文整理了Java中hudson.util.IOUtils
类的一些代码示例,展示了IOUtils
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils
类的具体详情如下:
包路径:hudson.util.IOUtils
类名称:IOUtils
[英]Adds more to commons-io.
[中]为commons io添加更多内容。
代码示例来源:origin: jenkinsci/jenkins
mkdirs(f);
} else {
File p = f.getParentFile();
if (p != null) {
mkdirs(p);
IOUtils.copy(input, writing(f));
代码示例来源:origin: jenkinsci/jenkins
@Override
public FilePath supplySettings(AbstractBuild<?, ?> build, TaskListener listener) {
if (StringUtils.isEmpty(path)) {
return null;
}
try {
EnvVars env = build.getEnvironment(listener);
String targetPath = Util.replaceMacro(this.path, build.getBuildVariableResolver());
targetPath = env.expand(targetPath);
if (IOUtils.isAbsolute(targetPath)) {
return new FilePath(new File(targetPath));
} else {
FilePath mrSettings = build.getModuleRoot().child(targetPath);
FilePath wsSettings = build.getWorkspace().child(targetPath);
try {
if (!wsSettings.exists() && mrSettings.exists()) {
wsSettings = mrSettings;
}
} catch (Exception e) {
throw new IllegalStateException("failed to find settings.xml at: " + wsSettings.getRemote());
}
return wsSettings;
}
} catch (Exception e) {
throw new IllegalStateException("failed to prepare global settings.xml");
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Skips the encoded console note.
*/
public static void skip(DataInputStream in) throws IOException {
byte[] preamble = new byte[PREAMBLE.length];
in.readFully(preamble);
if (!Arrays.equals(preamble,PREAMBLE))
return; // not a valid preamble
DataInputStream decoded = new DataInputStream(new UnbufferedBase64InputStream(in));
int macSz = - decoded.readInt();
if (macSz > 0) { // new format
IOUtils.skip(decoded, macSz);
int sz = decoded.readInt();
IOUtils.skip(decoded, sz);
} else { // old format
int sz = -macSz;
IOUtils.skip(decoded, sz);
}
byte[] postamble = new byte[POSTAMBLE.length];
in.readFully(postamble);
}
代码示例来源:origin: org.jvnet.hudson.main/maven-plugin
MavenInformation mavenInformation = getModuleRoot().act( new MavenVersionCallable( mvn.getHome() ));
mb.setWorkspace(getModuleRoot().child(m.getRelativePath()));
proxies.put(m.getModuleName(), mb.new ProxyImpl2(MavenModuleSetBuild.this,slistener));
FilePath pom = getModuleRoot().child(rootPOM);
FilePath parentLoc = getWorkspace().child(rootPOM);
if(!pom.exists() && parentLoc.exists())
if (IOUtils.isAbsolute(project.getAlternateSettings())) {
margs.add("-s").add(project.getAlternateSettings());
} else {
代码示例来源:origin: jenkinsci/jenkins
mkdirs(f);
} else {
File parent = f.getParentFile();
if (parent != null) mkdirs(parent);
writing(f);
new FilePath(f).symlinkTo(te.getLinkName(), TaskListener.NULL);
} else {
IOUtils.copy(t, f);
代码示例来源:origin: jenkinsci/artifactory-plugin
public static void persistConfiguration(ArtifactoryClientConfiguration configuration, Map<String, String> env, FilePath ws,
hudson.Launcher launcher) throws IOException, InterruptedException {
FilePath propertiesFile = ws.createTextTempFile("buildInfo", ".properties", "");
ActionableHelper.deleteFilePathOnExit(propertiesFile);
configuration.setPropertiesFile(propertiesFile.getRemote());
env.put("BUILDINFO_PROPFILE", propertiesFile.getRemote());
env.put(BuildInfoConfigProperties.PROP_PROPS_FILE, propertiesFile.getRemote());
// Jenkins prefixes env variables with 'env' but we need it clean..
System.setProperty(BuildInfoConfigProperties.PROP_PROPS_FILE, propertiesFile.getRemote());
if (!(getComputer(launcher) instanceof SlaveComputer)) {
configuration.persistToPropertiesFile();
} else {
try {
Properties properties = new Properties();
properties.putAll(configuration.getAllRootConfig());
properties.putAll(configuration.getAllProperties());
OutputStream os = propertiesFile.write();
try {
properties.store(os, "");
} finally {
IOUtils.closeQuietly(os);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
代码示例来源:origin: hudson/hudson-2.x
/**
* Reads the given InputStream as a tar file and extracts it into this directory.
*
* @param _in
* The stream will be closed by this method after it's fully read.
* @param compression
* The compression method in use.
* @since 1.292
*/
public void untarFrom(InputStream _in, final TarCompression compression) throws IOException, InterruptedException {
try {
final InputStream in = new RemoteInputStream(_in);
act(new FileCallable<Void>() {
public Void invoke(File dir, VirtualChannel channel) throws IOException {
readFromTar("input stream",dir, compression.extract(in));
return null;
}
private static final long serialVersionUID = 1L;
});
} finally {
IOUtils.closeQuietly(_in);
}
}
代码示例来源:origin: org.jvnet.hudson.main/hudson-core
/**
* Replaces the content of this file by the data from the given {@link InputStream}.
*
* @since 1.293
*/
public void copyFrom(InputStream in) throws IOException, InterruptedException {
OutputStream os = write();
try {
IOUtils.copy(in, os);
} finally {
os.close();
}
}
代码示例来源:origin: org.eclipse.hudson/hudson-core
/**
* 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();
}
}
代码示例来源:origin: org.jvnet.hudson.main/hudson-core
public static void copy(File src, OutputStream out) throws IOException {
FileInputStream in = new FileInputStream(src);
try {
copy(in,out);
} finally {
closeQuietly(in);
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Writes {@code config.xml} to the specified output stream.
* The user must have at least {@link #EXTENDED_READ}.
* If he lacks {@link #CONFIGURE}, then any {@link Secret}s detected will be masked out.
*/
@Restricted(NoExternalUse.class)
public void writeConfigDotXml(OutputStream os) throws IOException {
checkPermission(EXTENDED_READ);
XmlFile configFile = getConfigFile();
if (hasPermission(CONFIGURE)) {
IOUtils.copy(configFile.getFile(), os);
} else {
String encoding = configFile.sniffEncoding();
String xml = FileUtils.readFileToString(configFile.getFile(), encoding);
Matcher matcher = SECRET_PATTERN.matcher(xml);
StringBuffer cleanXml = new StringBuffer();
while (matcher.find()) {
if (Secret.decrypt(matcher.group(1)) != null) {
matcher.appendReplacement(cleanXml, ">********<");
}
}
matcher.appendTail(cleanXml);
org.apache.commons.io.IOUtils.write(cleanXml.toString(), os, encoding);
}
}
代码示例来源:origin: jenkinsci/artifactory-plugin
/**
* Converts the http entity to string. If entity is null, returns empty string.
* @param entity
* @return
* @throws IOException
*/
public static String entityToString(HttpEntity entity) throws IOException {
if (entity != null) {
InputStream is = entity.getContent();
return IOUtils.toString(is, "UTF-8");
}
return "";
}
代码示例来源:origin: jenkinsci/jenkins
private void unzip(File dir, InputStream in) throws IOException {
File tmpFile = File.createTempFile("tmpzip", null); // uses java.io.tmpdir
try {
// TODO why does this not simply use ZipInputStream?
IOUtils.copy(in, tmpFile);
unzip(dir,tmpFile);
}
finally {
tmpFile.delete();
}
}
代码示例来源:origin: org.eclipse.hudson/hudson-core
public Void invoke(File f, VirtualChannel channel) throws IOException {
f.getParentFile().mkdirs();
FileOutputStream fos = new FileOutputStream(f);
Writer w;
if (encoding != null) {
w = new OutputStreamWriter(fos, encoding);
} else {
w = new OutputStreamWriter(fos);
}
try {
w.write(content);
} finally {
IOUtils.closeQuietly(w);
}
return null;
}
});
代码示例来源:origin: org.jvnet.hudson.main/hudson-core
private int readSmbFile(SmbFile f) throws IOException {
InputStream in=null;
try {
in = f.getInputStream();
return Integer.parseInt(IOUtils.toString(in));
} finally {
IOUtils.closeQuietly(in);
}
}
代码示例来源:origin: hudson/hudson-2.x
/**
* Reads from a tar stream and stores obtained files to the base dir.
*/
private static void readFromTar(String name, File baseDir, InputStream in) throws IOException {
TarInputStream t = new TarInputStream(in);
try {
TarEntry te;
while ((te = t.getNextEntry()) != null) {
File f = new File(baseDir,te.getName());
if(te.isDirectory()) {
f.mkdirs();
} else {
File parent = f.getParentFile();
if (parent != null) parent.mkdirs();
IOUtils.copy(t,f);
f.setLastModified(te.getModTime().getTime());
int mode = te.getMode()&0777;
if(mode!=0 && !Functions.isWindows()) // be defensive
_chmod(f,mode);
}
}
} catch(IOException e) {
throw new IOException2("Failed to extract "+name,e);
} finally {
t.close();
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Resolves the given path with respect to given base. If the path represents an absolute path, a file representing
* it is returned, otherwise a file representing a path relative to base is returned.
* <p>
* It would be nice if File#File(File, String) were doing this.
* @param base File that represents the parent, may be null if path is absolute
* @param path Path of the file, may not be null
* @return new File(name) if name represents an absolute path, new File(base, name) otherwise
* @see hudson.FilePath#absolutize()
*/
public static File absolutize(File base, String path) {
if (isAbsolute(path))
return new File(path);
return new File(base, path);
}
代码示例来源:origin: org.jenkins-ci.plugins/credentials
/**
* {@inheritDoc}
*/
@NonNull
@Override
public byte[] getKeyStoreBytes() {
try {
InputStream inputStream = new FileInputStream(new File(keyStoreFile));
try {
return IOUtils.toByteArray(inputStream);
} finally {
IOUtils.closeQuietly(inputStream);
}
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Could not read private key file " + keyStoreFile, e);
return new byte[0];
}
}
代码示例来源:origin: org.jenkins-ci.main/jenkins-core
File f = new File(baseDir, te.getName());
if (te.isDirectory()) {
mkdirs(f);
} else {
File parent = f.getParentFile();
if (parent != null) mkdirs(parent);
writing(f);
new FilePath(f).symlinkTo(te.getLinkName(), TaskListener.NULL);
} else {
IOUtils.copy(t, f);
代码示例来源:origin: org.jvnet.hudson.main/hudson-core
/**
* Reads the given InputStream as a tar file and extracts it into this directory.
*
* @param _in
* The stream will be closed by this method after it's fully read.
* @param compression
* The compression method in use.
* @since 1.292
*/
public void untarFrom(InputStream _in, final TarCompression compression) throws IOException, InterruptedException {
try {
final InputStream in = new RemoteInputStream(_in);
act(new FileCallable<Void>() {
public Void invoke(File dir, VirtualChannel channel) throws IOException {
readFromTar("input stream",dir, compression.extract(in));
return null;
}
private static final long serialVersionUID = 1L;
});
} finally {
IOUtils.closeQuietly(_in);
}
}
内容来源于网络,如有侵权,请联系作者删除!