本文整理汇总了Java中hudson.util.IOUtils类的典型用法代码示例。如果您正苦于以下问题:Java IOUtils类的具体用法?Java IOUtils怎么用?Java IOUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IOUtils类属于hudson.util包,在下文中一共展示了IOUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSonarProjectURLFromBuildLogs
import hudson.util.IOUtils; //导入依赖的package包/类
@SuppressWarnings("deprecation")
private String getSonarProjectURLFromBuildLogs(Run<?, ?> build) throws IOException {
BufferedReader br = null;
String url = null;
try {
br = new BufferedReader(build.getLogReader());
String strLine;
Pattern p = Pattern.compile(URL_PATTERN_IN_LOGS);
while ((strLine = br.readLine()) != null) {
Matcher match = p.matcher(strLine);
if (match.matches()) {
url = match.group(1);
}
}
} finally {
IOUtils.closeQuietly(br);
}
return url;
}
示例2: compressArchive
import hudson.util.IOUtils; //导入依赖的package包/类
private static void compressArchive(
final Path pathToCompress,
final ArchiveOutputStream archiveOutputStream,
final ArchiveEntryFactory archiveEntryFactory,
final CompressionType compressionType,
final BuildListener listener)
throws IOException {
final List<File> files = addFilesToCompress(pathToCompress, listener);
LoggingHelper.log(listener, "Compressing directory '%s' as a '%s' archive",
pathToCompress.toString(),
compressionType.name());
for (final File file : files) {
final String newTarFileName = pathToCompress.relativize(file.toPath()).toString();
final ArchiveEntry archiveEntry = archiveEntryFactory.create(file, newTarFileName);
archiveOutputStream.putArchiveEntry(archiveEntry);
try (final FileInputStream fileInputStream = new FileInputStream(file)) {
IOUtils.copy(fileInputStream, archiveOutputStream);
}
archiveOutputStream.closeArchiveEntry();
}
}
示例3: testBuild
import hudson.util.IOUtils; //导入依赖的package包/类
@Test
public void testBuild() throws Exception {
MockUploadModule module = new MockUploadModule(executor);
DownloadStep step = new DownloadStep(CREDENTIALS_ID,
"gs://bucket/path/to/object.txt",
"", module);
FreeStyleProject project = jenkins.createFreeStyleProject("testBuild");
// Set up mock to retrieve the object
StorageObject objToGet = new StorageObject();
objToGet.setBucket("bucket");
objToGet.setName("path/to/obj.txt");
executor.when(Storage.Objects.Get.class, objToGet,
MockUploadModule.checkGetObject("path/to/object.txt"));
module.addNextMedia(IOUtils.toInputStream("test", "UTF-8"));
project.getBuildersList().add(step);
FreeStyleBuild build = jenkins.buildAndAssertSuccess(project);
FilePath result = build.getWorkspace().withSuffix("/path/to/obj.txt");
assertTrue(result.exists());
assertEquals("test", result.readToString());
}
示例4: testBuildPrefix
import hudson.util.IOUtils; //导入依赖的package包/类
@Test
public void testBuildPrefix() throws Exception {
MockUploadModule module = new MockUploadModule(executor);
DownloadStep step = new DownloadStep(CREDENTIALS_ID,
"gs://bucket/path/to/object.txt",
"subPath", module);
step.setPathPrefix("path/to/");
FreeStyleProject project = jenkins.createFreeStyleProject("testBuild");
// Set up mock to retrieve the object
StorageObject objToGet = new StorageObject();
objToGet.setBucket("bucket");
objToGet.setName("path/to/obj.txt");
executor.when(Storage.Objects.Get.class, objToGet,
MockUploadModule.checkGetObject("path/to/object.txt"));
module.addNextMedia(IOUtils.toInputStream("test", "UTF-8"));
project.getBuildersList().add(step);
FreeStyleBuild build = jenkins.buildAndAssertSuccess(project);
FilePath result = build.getWorkspace().withSuffix("/subPath/obj.txt");
assertTrue(result.exists());
assertEquals("test", result.readToString());
}
示例5: testBuildMoreComplex
import hudson.util.IOUtils; //导入依赖的package包/类
@Test
public void testBuildMoreComplex() throws Exception {
MockUploadModule module = new MockUploadModule(executor);
DownloadStep step = new DownloadStep(CREDENTIALS_ID,
"gs://bucket/download/$BUILD_ID/path/$BUILD_ID/test_$BUILD_ID.txt",
"output", module);
step.setPathPrefix("download/$BUILD_ID/");
FreeStyleProject project = jenkins.createFreeStyleProject("testBuild");
// Set up mock to retrieve the object
StorageObject objToGet = new StorageObject();
objToGet.setBucket("bucket");
objToGet.setName("download/1/path/1/test_1.txt");
executor.when(Storage.Objects.Get.class, objToGet,
MockUploadModule.checkGetObject("download/1/path/1/test_1.txt"));
module.addNextMedia(IOUtils.toInputStream("contents 1", "UTF-8"));
project.getBuildersList().add(step);
FreeStyleBuild build = jenkins.buildAndAssertSuccess(project);
FilePath result = build.getWorkspace()
.withSuffix("/output/path/1/test_1.txt");
assertTrue(result.exists());
assertEquals("contents 1", result.readToString());
}
示例6: doRun
import hudson.util.IOUtils; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected void doRun() throws Exception {
if (isEnabled()) {
ObjectWriter writer = mapper.writer();
// always allocate 1kb more that the average compressed size
ByteArrayOutputStream baos = new ByteArrayOutputStream(averageSize + 1024);
try {
GZIPOutputStream gzos = null;
try {
gzos = new GZIPOutputStream(baos);
writer.writeValue(gzos, Metrics.metricRegistry());
} finally {
IOUtils.closeQuietly(gzos);
}
} finally {
baos.close();
}
byte[] compressedBytes = baos.toByteArray();
// the compressed size should be an average of the recent values, this will give us
// a computationally quick exponential move towards the average... we do not need a strict
// exponential average
averageSize = Math.max(8192, (7 * averageSize + compressedBytes.length) / 8);
bucket.add(new Sample(System.currentTimeMillis(), compressedBytes));
}
}
示例7: downloadAndSaveToCache
import hudson.util.IOUtils; //导入依赖的package包/类
/**
* Downloads and saves JSON files to local cache.
*
* @param pathToJSON Relative path to JSON file.
* @return Returns content of JSON file.
* @throws IOException When file operations failed.
*/
private String downloadAndSaveToCache(String pathToJSON) throws IOException {
String fsPath = FilenameUtils.concat(localCachePath, pathToJSON);
String httpPath = ccrUrl + pathToJSON;
LOG.info("Local Path " + fsPath);
// make directory
IOUtils.mkdirs(new File(FilenameUtils.getFullPath(fsPath)));
// get content
String data = IOUtils.toString(new URL(httpPath).openStream());
// save to cache
FileWriter writer = null;
try {
writer = new FileWriter(fsPath);
IOUtils.write(data, writer);
writer.flush();
} finally {
IOUtils.closeQuietly(writer);
}
return data;
}
示例8: setWriter
import hudson.util.IOUtils; //导入依赖的package包/类
private void setWriter(Writer writer) {
Writer oldWriter = null;
boolean success = false;
outputLock.lock();
try {
oldWriter = this.writer;
if (oldWriter != null) {
try {
this.writer.flush();
} catch (IOException e) {
// ignore
}
}
this.writer = writer;
} finally {
outputLock.unlock();
IOUtils.closeQuietly(oldWriter);
}
}
示例9: call
import hudson.util.IOUtils; //导入依赖的package包/类
@edu.umd.cs.findbugs.annotations.SuppressWarnings(
value = {"NP_LOAD_OF_KNOWN_NULL_VALUE"},
justification = "Findbugs mis-diagnosing closeQuietly's built-in null check"
)
public String call() throws RuntimeException {
InputStream is = null;
try {
is = hudson.remoting.Channel.class.getResourceAsStream("/jenkins/remoting/jenkins-version.properties");
if (is == null) {
return "N/A";
}
Properties properties = new Properties();
try {
properties.load(is);
return properties.getProperty("version", "N/A");
} catch (IOException e) {
return "N/A";
}
} finally {
IOUtils.closeQuietly(is);
}
}
示例10: appendNote
import hudson.util.IOUtils; //导入依赖的package包/类
/** {@inheritDoc} */
public void appendNote(String note, String namespace) throws GitException {
try (Repository repo = getRepository()) {
ObjectId head = repo.resolve(HEAD); // commit to put a note on
ShowNoteCommand cmd = git(repo).notesShow();
cmd.setNotesRef(qualifyNotesNamespace(namespace));
try (ObjectReader or = repo.newObjectReader();
RevWalk walk = new RevWalk(or)) {
cmd.setObjectId(walk.parseAny(head));
Note n = cmd.call();
if (n==null) {
addNote(note,namespace);
} else {
ObjectLoader ol = or.open(n.getData());
StringWriter sw = new StringWriter();
IOUtils.copy(new InputStreamReader(ol.openStream(),CHARSET),sw);
sw.write("\n");
addNote(sw.toString() + normalizeNote(note), namespace);
}
}
} catch (GitAPIException | IOException e) {
throw new GitException(e);
}
}
示例11: getRequestBody
import hudson.util.IOUtils; //导入依赖的package包/类
@SuppressWarnings("deprecation")
private String getRequestBody(HttpServletRequest request) throws IOException {
String charset = request.getCharacterEncoding() == null ? CHARSET_UTF_8 : request.getCharacterEncoding();
String requestBody = IOUtils.toString(request.getInputStream(), charset);
if (StringUtils.isBlank(requestBody)) {
throw new IllegalArgumentException("request-body is empty");
}
return requestBody;
}
示例12: doPdfReport
import hudson.util.IOUtils; //导入依赖的package包/类
public void doPdfReport(StaplerRequest req, StaplerResponse rsp) throws IOException {
rsp.setContentType("application/pdf");
ServletOutputStream outputStream = rsp.getOutputStream();
File buildDirectory = owner.getRootDir();
File a = new File(buildDirectory, "/checkmarx/" + PDF_REPORT_NAME);
IOUtils.copy(a, outputStream);
outputStream.flush();
outputStream.close();
}
示例13: doOsaPdfReport
import hudson.util.IOUtils; //导入依赖的package包/类
public void doOsaPdfReport(StaplerRequest req, StaplerResponse rsp) throws IOException {
rsp.setContentType("application/pdf");
ServletOutputStream outputStream = rsp.getOutputStream();
File buildDirectory = owner.getRootDir();
File a = new File(buildDirectory, "/checkmarx/" + OSA_PDF_REPORT_NAME);
IOUtils.copy(a, outputStream);
outputStream.flush();
outputStream.close();
}
示例14: doOsaHtmlReport
import hudson.util.IOUtils; //导入依赖的package包/类
public void doOsaHtmlReport(StaplerRequest req, StaplerResponse rsp) throws IOException {
rsp.setContentType("text/html");
ServletOutputStream outputStream = rsp.getOutputStream();
File buildDirectory = owner.getRootDir();
File a = new File(buildDirectory, "/checkmarx/" + "OSAReport.html");
IOUtils.copy(a, outputStream);
outputStream.flush();
outputStream.close();
}
示例15: doIndex
import hudson.util.IOUtils; //导入依赖的package包/类
/**
* Displays the JSON payload from GitHub. Stapler API.
*
* @param req request
* @param rsp response
* @throws IOException
*/
public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException {
rsp.setContentType("application/json;charset=UTF-8");
// Prevent jelly from flushing stream so Content-Length header can be added afterwards
try (FlushProofOutputStream out = new FlushProofOutputStream(rsp.getCompressedOutputStream(req))) {
IOUtils.copy(getPayloadFile(), out);
}
}