From: Simon Brandhof Date: Fri, 5 Aug 2016 13:38:16 +0000 (+0200) Subject: SONAR-7903 buffer stream when saving and reading reports X-Git-Tag: 6.1-RC1~444 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=234bad0412ad67e33f056b122e67cf4c77e1dc69;p=sonarqube.git SONAR-7903 buffer stream when saving and reading reports --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/ce/ws/SubmitAction.java b/server/sonar-server/src/main/java/org/sonar/server/ce/ws/SubmitAction.java index f2e264c447c..a623c16c4ac 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ce/ws/SubmitAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ce/ws/SubmitAction.java @@ -19,6 +19,7 @@ */ package org.sonar.server.ce.ws; +import java.io.BufferedInputStream; import java.io.InputStream; import org.apache.commons.lang.StringUtils; import org.sonar.api.server.ws.Request; @@ -81,9 +82,11 @@ public class SubmitAction implements CeWsAction { String projectKey = wsRequest.mandatoryParam(PARAM_PROJECT_KEY); String projectBranch = wsRequest.param(PARAM_PROJECT_BRANCH); String projectName = StringUtils.defaultIfBlank(wsRequest.param(PARAM_PROJECT_NAME), projectKey); - InputStream reportInput = wsRequest.paramAsInputStream(PARAM_REPORT_DATA); - CeTask task = reportSubmitter.submit(projectKey, projectBranch, projectName, reportInput); + CeTask task; + try (InputStream report = new BufferedInputStream(wsRequest.paramAsInputStream(PARAM_REPORT_DATA))) { + task = reportSubmitter.submit(projectKey, projectBranch, projectName, report); + } WsCe.SubmitResponse submitResponse = WsCe.SubmitResponse.newBuilder() .setTaskId(task.getUuid()) diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ExtractReportStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ExtractReportStep.java index 513bc7a2738..7e1f131b1f9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ExtractReportStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ExtractReportStep.java @@ -19,8 +19,10 @@ */ package org.sonar.server.computation.task.projectanalysis.step; +import java.io.BufferedInputStream; import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.util.Optional; import org.sonar.api.utils.MessageException; import org.sonar.api.utils.TempFolder; @@ -57,8 +59,9 @@ public class ExtractReportStep implements ComputationStep { Optional opt = dbClient.ceTaskDataDao().selectData(dbSession, task.getUuid()); if (opt.isPresent()) { File unzippedDir = tempFolder.newDir(); - try (CeTaskDataDao.DataStream reportStream = opt.get()) { - ZipUtils.unzip(reportStream.getInputStream(), unzippedDir); + try (CeTaskDataDao.DataStream reportStream = opt.get(); + InputStream zipStream = new BufferedInputStream(reportStream.getInputStream())) { + ZipUtils.unzip(zipStream, unzippedDir); } catch (IOException e) { throw new IllegalStateException("Fail to extract report " + task.getUuid() + " from database", e); }