aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2018-04-03 10:51:02 +0200
committerJanos Gyerik <janos.gyerik@sonarsource.com>2018-04-04 14:40:50 +0200
commitbd2717036288c9feea942fdfcefcd096363bc006 (patch)
tree177228e7fe571d487f8d5a40f2c347fc2c86be4b /sonar-scanner-engine
parent340950d96f60bd730962296784c2465da2e3dc23 (diff)
downloadsonarqube-bd2717036288c9feea942fdfcefcd096363bc006.tar.gz
sonarqube-bd2717036288c9feea942fdfcefcd096363bc006.zip
SONAR-10509 Use BufferedOutputStream when writing source in the scanner report
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/profiling/PhasesSumUpTimeProfiler.java13
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/report/SourcePublisher.java7
2 files changed, 14 insertions, 6 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/profiling/PhasesSumUpTimeProfiler.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/profiling/PhasesSumUpTimeProfiler.java
index 829bce0ba0f..4fbddb05f20 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/profiling/PhasesSumUpTimeProfiler.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/profiling/PhasesSumUpTimeProfiler.java
@@ -19,13 +19,19 @@
*/
package org.sonar.scanner.profiling;
-import com.google.common.annotations.VisibleForTesting;
+import static org.sonar.scanner.profiling.AbstractTimeProfiling.sortByDescendingTotalTime;
+import static org.sonar.scanner.profiling.AbstractTimeProfiling.truncate;
+
+import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
+import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
+
import javax.annotation.Nullable;
+
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,8 +50,7 @@ import org.sonar.scanner.bootstrap.GlobalProperties;
import org.sonar.scanner.events.BatchStepHandler;
import org.sonar.scanner.util.ScannerUtils;
-import static org.sonar.scanner.profiling.AbstractTimeProfiling.sortByDescendingTotalTime;
-import static org.sonar.scanner.profiling.AbstractTimeProfiling.truncate;
+import com.google.common.annotations.VisibleForTesting;
public class PhasesSumUpTimeProfiler implements ProjectAnalysisHandler, SensorExecutionHandler, PostJobExecutionHandler,
SensorsPhaseHandler, PostJobsPhaseHandler, InitializersPhaseHandler, InitializerExecutionHandler, BatchStepHandler {
@@ -136,7 +141,7 @@ public class PhasesSumUpTimeProfiler implements ProjectAnalysisHandler, SensorEx
private void dumpToFile(Properties props, String fileName) {
File file = new File(out, fileName);
- try (FileOutputStream fos = new FileOutputStream(file)) {
+ try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(file))) {
props.store(fos, "SonarQube");
println("Profiling data stored in " + file.getAbsolutePath());
} catch (Exception e) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/SourcePublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/SourcePublisher.java
index 2b6b184c42e..acb37b393fa 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/SourcePublisher.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/SourcePublisher.java
@@ -19,13 +19,16 @@
*/
package org.sonar.scanner.report;
+import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
+
import org.apache.commons.io.IOUtils;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.scanner.protocol.output.ScannerReportWriter;
@@ -44,7 +47,7 @@ public class SourcePublisher implements ReportPublisherStep {
for (final DefaultInputFile inputFile : componentCache.allFilesToPublish()) {
File iofile = writer.getSourceFile(inputFile.batchId());
- try (FileOutputStream output = new FileOutputStream(iofile);
+ try (OutputStream output = new BufferedOutputStream(new FileOutputStream(iofile));
InputStream in = inputFile.inputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in, inputFile.charset()))) {
writeSource(reader, output, inputFile.lines());
@@ -54,7 +57,7 @@ public class SourcePublisher implements ReportPublisherStep {
}
}
- private static void writeSource(BufferedReader reader, FileOutputStream output, int lines) throws IOException {
+ private static void writeSource(BufferedReader reader, OutputStream output, int lines) throws IOException {
int line = 0;
String lineStr = reader.readLine();
while (lineStr != null) {