Repository: mercedes-benz/sechub
Issue: Fix problem of failing FileUploadSizeScenario2IntTest on S3 storage

## Situation
In  integration test `FileUploadSizeScenario2IntTest` the test method `when_binaries_tarfile_exceeds_NOT_max_bin_file_size_file_is_uploaded` fails on S3 usage.

The problematic part is here:
```java
assertEquals("Fetched file size not as expected for " + data.fileNameAtServerSide + " !", realFileSizeInBytes, fetchedSize);
```

The problem happens only on S3 usage, not when we use a network share volume.
It happens on build servers and also on local machines.

### Wanted
Find a solution...

Changed files:
sechub-integrationtest/src/main/java/com/mercedesbenz/sechub/integrationtest/api/AsUser.java
sechub-server-core/src/main/java/com/mercedesbenz/sechub/server/core/IntegrationTestServerRestController.java
sechub-integrationtest/src/main/java/com/mercedesbenz/sechub/integrationtest/api/TestAPI.java

diff --git a/sechub-integrationtest/src/main/java/com/mercedesbenz/sechub/integrationtest/api/AsUser.java b/sechub-integrationtest/src/main/java/com/mercedesbenz/sechub/integrationtest/api/AsUser.java
index 28cd47c47..0d638bc56 100644
--- a/sechub-integrationtest/src/main/java/com/mercedesbenz/sechub/integrationtest/api/AsUser.java
+++ b/sechub-integrationtest/src/main/java/com/mercedesbenz/sechub/integrationtest/api/AsUser.java
@@ -740,19 +740,18 @@ public class AsUser {
         }
     }
 
-    public File downloadAsTempFileFromURL(String url, UUID jobUUID) {
-        String fileName = "sechub-file-redownload-" + jobUUID.toString();
-        String fileEnding = ".zip";
-        return downloadAsTempFileFromURL(url, jobUUID, fileName, fileEnding);
+    public File downloadAsTempFileFromURL(String url, UUID jobUUID, String fileName) {
+        String prefix = "sechub-file-redownload-" + jobUUID.toString();
+        return downloadAsTempFileFromURL(url, jobUUID, prefix, fileName);
     }
 
-    public File downloadAsTempFileFromURL(String url, UUID jobUUID, String fileName, String fileEnding) {
+    public File downloadAsTempFileFromURL(String url, UUID jobUUID, String prefix, String fileEnding) {
 
         // Optional Accept header
         RequestCallback requestCallback = request -> request.getHeaders().setAccept(Arrays.asList(MediaType.APPLICATION_OCTET_STREAM, MediaType.ALL));
 
         ResponseExtractor<File> responseExtractor = response -> {
-            Path path = TestUtil.createTempFileInBuildFolder(fileName, fileEnding);
+            Path path = TestUtil.createTempFileInBuildFolder(prefix, fileEnding);
             Files.copy(response.getBody(), path, StandardCopyOption.REPLACE_EXISTING);
             if (TestUtil.isDeletingTempFiles()) {
                 path.toFile().deleteOnExit();
diff --git a/sechub-integrationtest/src/main/java/com/mercedesbenz/sechub/integrationtest/api/TestAPI.java b/sechub-integrationtest/src/main/java/com/mercedesbenz/sechub/integrationtest/api/TestAPI.java
index c7712b235..9c6536aa3 100644
--- a/sechub-integrationtest/src/main/java/com/mercedesbenz/sechub/integrationtest/api/TestAPI.java
+++ b/sechub-integrationtest/src/main/java/com/mercedesbenz/sechub/integrationtest/api/TestAPI.java
@@ -695,7 +695,7 @@ public class TestAPI {
         SecHubTestURLBuilder urlBuilder = IntegrationTestContext.get().getUrlBuilder();
         String url = urlBuilder.buildGetFileUpload(project.getProjectId(), jobUUID.toString(), fileName);
         try {
-            File file = as(ANONYMOUS).downloadAsTempFileFromURL(url, jobUUID);
+            File file = as(ANONYMOUS).downloadAsTempFileFromURL(url, jobUUID, fileName);
             return file;
         } catch (HttpStatusCodeException e) {
             if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) {
diff --git a/sechub-server-core/src/main/java/com/mercedesbenz/sechub/server/core/IntegrationTestServerRestController.java b/sechub-server-core/src/main/java/com/mercedesbenz/sechub/server/core/IntegrationTestServerRestController.java
index a8c2fd5b8..6750eff5b 100644
--- a/sechub-server-core/src/main/java/com/mercedesbenz/sechub/server/core/IntegrationTestServerRestController.java
+++ b/sechub-server-core/src/main/java/com/mercedesbenz/sechub/server/core/IntegrationTestServerRestController.java
@@ -1,7 +1,6 @@
 // SPDX-License-Identifier: MIT
 package com.mercedesbenz.sechub.server.core;
 
-import java.io.DataInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.List;
@@ -14,7 +13,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.context.annotation.Profile;
-import org.springframework.core.io.ByteArrayResource;
+import org.springframework.core.io.InputStreamResource;
 import org.springframework.core.io.Resource;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.MediaType;
@@ -202,6 +201,7 @@ public class IntegrationTestServerRestController {
             return ResponseEntity.notFound().build();
         }
         LOG.info("Integration test server: getJobStorage for {} {}", logSanitizer.sanitize(projectId, 30), jobUUID);
+
         JobStorage storage = storageService.getJobStorage(projectId, jobUUID);
         if (!storage.isExisting(fileName)) {
             throw new NotFoundException("file not uploaded:" + fileName);
@@ -214,13 +214,9 @@ public class IntegrationTestServerRestController {
         headers.add("Expires", "0");
 
         /* @formatter:off */
-		byte[] bytes = new byte[inputStream.available()];
-		new DataInputStream(inputStream).readFully(bytes);
-		ByteArrayResource resource = new ByteArrayResource(bytes);
-
+		InputStreamResource resource = new InputStreamResource(inputStream);
 		return ResponseEntity.ok()
 				.headers(headers)
-				.contentLength(resource.contentLength())
 				.contentType(MediaType.parseMediaType("application/octet-stream"))
 				.body(resource);
 		/* @formatter:on */