private void closeStreams(Process process) { if (process != null) { IOUtils.closeQuietly(process.getInputStream()); IOUtils.closeQuietly(process.getInputStream()); IOUtils.closeQuietly(process.getOutputStream()); IOUtils.closeQuietly(process.getErrorStream()); } }
/** * Download file, without any caching mechanism. * * @param urlPath path starting with slash, for instance {@code "/batch/index"} * @param toFile the target file * @throws IOException if connectivity problem or timeout (network) or IO error (when writing to file) * @throws IllegalStateException if HTTP response code is different than 2xx */ public void downloadFile(String urlPath, File toFile) throws IOException { if (!urlPath.startsWith("/")) { throw new IllegalArgumentException(format("URL path must start with slash: %s", urlPath)); } String url = baseUrlWithoutTrailingSlash + urlPath; logger.debug(format("Download %s to %s", url, toFile.getAbsolutePath())); ResponseBody responseBody = callUrl(url); try (OutputStream fileOutput = new FileOutputStream(toFile)) { IOUtils.copyLarge(responseBody.byteStream(), fileOutput); } catch (IOException | RuntimeException e) { FileUtils.deleteQuietly(toFile); throw e; } }
private Properties loadProperties(String arg) throws IOException { Properties props = new Properties(); FileInputStream input = new FileInputStream(arg); try { props.load(input); // just to be clean, do not forward properties that do not make sense in fork mode props.remove(InternalProperties.RUNNER_MASK_RULES); } finally { IOUtils.closeQuietly(input); } return props; }
private File writeProperties() { OutputStream output = null; try { File file = File.createTempFile("sonar-project", ".properties"); output = new FileOutputStream(file); properties().store(output, "Generated by sonar-runner"); return file; } catch (Exception e) { throw new IllegalStateException("Fail to export sonar-runner properties", e); } finally { IOUtils.closeQuietly(output); } }
@Override public void run() { InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); try { String line; while ((line = br.readLine()) != null) { consumeLine(line); } } catch (IOException ioe) { exception = ioe; } finally { IOUtils.closeQuietly(br); IOUtils.closeQuietly(isr); } }
private void writeProperties(File outputFile) { OutputStream output = null; try { output = new FileOutputStream(outputFile); properties().store(output, "Generated by sonar-runner"); } catch (Exception e) { throw new IllegalStateException("Fail to export sonar-runner properties", e); } finally { IOUtils.closeQuietly(output); } }