Skip to content

Commit

Permalink
Merge pull request #59 from pagopa/fix_zip_blob
Browse files Browse the repository at this point in the history
feat: NOD-642 fix conversion
  • Loading branch information
mscattarella authored Feb 2, 2024
2 parents 58b8dda + 2d9e74c commit 3bc789b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/it/gov/pagopa/fdr/service/re/ReService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -115,16 +114,14 @@ public <T extends ReAbstract> 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);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/it/gov/pagopa/fdr/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 3bc789b

Please sign in to comment.