当前位置: 首页>>代码示例>>Java>>正文


Java IOUtils类代码示例

本文整理汇总了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;
}
 
开发者ID:jenkinsci,项目名称:influxdb-plugin,代码行数:20,代码来源:SonarQubePointGenerator.java

示例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();
    }
}
 
开发者ID:awslabs,项目名称:aws-codepipeline-plugin-for-jenkins,代码行数:26,代码来源:CompressionTools.java

示例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());
}
 
开发者ID:jenkinsci,项目名称:google-storage-plugin,代码行数:25,代码来源:DownloadStepTest.java

示例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());
}
 
开发者ID:jenkinsci,项目名称:google-storage-plugin,代码行数:26,代码来源:DownloadStepTest.java

示例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());
}
 
开发者ID:jenkinsci,项目名称:google-storage-plugin,代码行数:27,代码来源:DownloadStepTest.java

示例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));
    }
}
 
开发者ID:jenkinsci,项目名称:metrics-plugin,代码行数:29,代码来源:MetricsRootAction.java

示例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;
}
 
开发者ID:ederst,项目名称:ccr-parameter-plugin,代码行数:30,代码来源:CacheManager.java

示例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);
    }
}
 
开发者ID:jenkinsci,项目名称:support-core-plugin,代码行数:20,代码来源:SupportLogHandler.java

示例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);
    }
}
 
开发者ID:jenkinsci,项目名称:support-core-plugin,代码行数:23,代码来源:AboutJenkins.java

示例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);
    }
}
 
开发者ID:jenkinsci,项目名称:git-client-plugin,代码行数:27,代码来源:JGitAPIImpl.java

示例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;
}
 
开发者ID:Argelbargel,项目名称:gitlab-branch-source-plugin,代码行数:11,代码来源:HookHandler.java

示例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();
}
 
开发者ID:jenkinsci,项目名称:checkmarx-plugin,代码行数:12,代码来源:CxScanResult.java

示例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();
    }
 
开发者ID:jenkinsci,项目名称:checkmarx-plugin,代码行数:13,代码来源:CxScanResult.java

示例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();
}
 
开发者ID:jenkinsci,项目名称:checkmarx-plugin,代码行数:12,代码来源:CxScanResult.java

示例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);
    }
}
 
开发者ID:Affirm,项目名称:jenkins-plugins,代码行数:15,代码来源:TagCause.java


注:本文中的hudson.util.IOUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。