Java Code Examples for hudson.util.IOUtils

The following examples show how to use hudson.util.IOUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
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();
    }
}
 
Example 2
@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;
}
 
Example 3
private void createAllDocsPage(File allDocsPath) {
    if (!allDocsPath.exists()) {
        try (InputStream is = getClass().getResourceAsStream("/" + CukedoctorBaseAction.BUILD_ACTION_ALL_DOCUMENTATION)) {
            IOUtils.copy(is, allDocsPath);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
 
Example 4
private void createAllDocsPage(File allDocsPath) {
    if (!allDocsPath.exists()) {
        try (InputStream is = getClass().getResourceAsStream("/" + CukedoctorBaseAction.ALL_DOCUMENTATION)) {
            IOUtils.copy(is, allDocsPath);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
 
Example 5
Source Project: jenkins-test-harness   Source File: JavaNetReverseProxy.java    License: MIT License 5 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String path = req.getServletPath();
    String d = Util.getDigestOf(path);

    File cache = new File(cacheFolder, d);
    if(!cache.exists()) {
        URL url = new URL("http://updates.jenkins-ci.org/" + path);
        FileUtils.copyURLToFile(url,cache);
    }

    resp.setContentType(getMimeType(path));
    IOUtils.copy(cache,resp.getOutputStream());
}
 
Example 6
Source Project: phabricator-jenkins-plugin   Source File: JUnitTestProviderTest.java    License: MIT License 5 votes vote down vote up
private TestResult getTestResult() throws IOException {
    File temp = File.createTempFile("anything", "xml");
    temp.deleteOnExit();
    InputStream junit = getClass().getResourceAsStream("go-torch-junit.xml");

    IOUtils.copy(junit, temp);
    TestResult result = new TestResult();
    result.parse(temp);
    return result;
}
 
Example 7
public void visit(File file, String relativePath) throws IOException {
    if (recursiveMatch(dockerIgnore, file.toPath())) {
         return;
    }

    if (relativePath.contains("/")) {
        relativePath = relativePath.substring(relativePath.indexOf("/") + 1);
    } else {
        relativePath = ".";
    }

    if(Functions.isWindows()) {
        relativePath = relativePath.replace('\\', '/');
    }

    if(file.isDirectory()) {
        relativePath += '/';
    }

    TarArchiveEntry te = new TarArchiveEntry(file);
    te.setName(relativePath);

    int mode = IOUtils.mode(file);
    if (mode!=-1) {
        te.setMode(mode);
    }
    te.setModTime(file.lastModified());

    if(!file.isDirectory()) {
        te.setSize(file.length());
    }

    tar.putArchiveEntry(te);

    if (!file.isDirectory()) {
        FileInputStream in = new FileInputStream(file);
        try {
            int len;
            while((len=in.read(buf))>=0)
                tar.write(buf,0,len);
        } finally {
            in.close();
        }
    }

    tar.closeArchiveEntry();
    entriesWritten++;
}