diff --git a/src/main/java/it/gov/pagopa/fdr/service/history/HistoryService.java b/src/main/java/it/gov/pagopa/fdr/service/history/HistoryService.java index e28e020f..941086a3 100644 --- a/src/main/java/it/gov/pagopa/fdr/service/history/HistoryService.java +++ b/src/main/java/it/gov/pagopa/fdr/service/history/HistoryService.java @@ -123,8 +123,8 @@ public HistoryBlobBody saveJsonFile( objMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); String fdrHistoryEntityJson = objMapper.writeValueAsString(fdrHistoryEntity); isJsonValid(fdrHistoryEntityJson, jsonSchema); - String compressedFdrHistoryEntityJson = StringUtil.zip(fdrHistoryEntityJson); - BinaryData jsonFile = BinaryData.fromString(compressedFdrHistoryEntityJson); + byte[] compressedFdrHistoryEntityJson = StringUtil.zip(fdrHistoryEntityJson); + BinaryData jsonFile = BinaryData.fromBytes(compressedFdrHistoryEntityJson); uploadBlob(fileName, jsonFile); return HistoryBlobBody.builder() diff --git a/src/main/java/it/gov/pagopa/fdr/service/re/ReService.java b/src/main/java/it/gov/pagopa/fdr/service/re/ReService.java index c7c7c75b..f9c688b2 100644 --- a/src/main/java/it/gov/pagopa/fdr/service/re/ReService.java +++ b/src/main/java/it/gov/pagopa/fdr/service/re/ReService.java @@ -21,7 +21,6 @@ import jakarta.enterprise.context.ApplicationScoped; import java.io.ByteArrayInputStream; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.Arrays; @@ -115,16 +114,14 @@ public void writeBlobIfExist(T re) { "%s_%s_%s.json.zip", re.getSessionId(), re.getFdrAction(), reInterface.getHttpType().name()); - String compressedBody = null; + byte[] compressedBody = null; try { compressedBody = StringUtil.zip(bodyStr); } catch (IOException e) { log.errorf("Compress json error", e); throw new AppException(AppErrorCodeMessageEnum.COMPRESS_JSON); } - BinaryData body = - BinaryData.fromStream( - new ByteArrayInputStream(compressedBody.getBytes(StandardCharsets.UTF_8))); + BinaryData body = BinaryData.fromStream(new ByteArrayInputStream(compressedBody)); BlobClient blobClient = blobContainerClient.getBlobClient(fileName); blobClient.upload(body); diff --git a/src/main/java/it/gov/pagopa/fdr/util/StringUtil.java b/src/main/java/it/gov/pagopa/fdr/util/StringUtil.java index 2c521e41..519e64c0 100644 --- a/src/main/java/it/gov/pagopa/fdr/util/StringUtil.java +++ b/src/main/java/it/gov/pagopa/fdr/util/StringUtil.java @@ -7,13 +7,13 @@ public class StringUtil { - public static String zip(String str) throws IOException { + public static byte[] zip(String str) throws IOException { byte[] strBytes = str.getBytes(StandardCharsets.UTF_8); ByteArrayOutputStream bais = new ByteArrayOutputStream(strBytes.length); GZIPOutputStream gzipOut = new GZIPOutputStream(bais); gzipOut.write(strBytes); gzipOut.close(); - String compressed = bais.toString(StandardCharsets.UTF_8); + byte[] compressed = bais.toByteArray(); bais.close(); return compressed; }