diff --git a/vulnz/build.gradle b/vulnz/build.gradle index d229c47a..996d696f 100644 --- a/vulnz/build.gradle +++ b/vulnz/build.gradle @@ -16,6 +16,7 @@ dependencies { implementation project(':open-vulnerability-store') implementation 'info.picocli:picocli-spring-boot-starter:4.7.4' implementation 'com.diogonunes:JColor:5.5.1' + implementation 'commons-io:commons-io:2.15.0' implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.2' implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.15.2' implementation 'jakarta.persistence:jakarta.persistence-api:3.1.0' diff --git a/vulnz/src/main/java/io/github/jeremylong/vulnz/cli/commands/CveCommand.java b/vulnz/src/main/java/io/github/jeremylong/vulnz/cli/commands/CveCommand.java index 7a5384f6..3cf91527 100644 --- a/vulnz/src/main/java/io/github/jeremylong/vulnz/cli/commands/CveCommand.java +++ b/vulnz/src/main/java/io/github/jeremylong/vulnz/cli/commands/CveCommand.java @@ -32,6 +32,7 @@ import io.github.jeremylong.vulnz.cli.cache.CacheException; import io.github.jeremylong.vulnz.cli.cache.CacheProperties; import io.github.jeremylong.vulnz.cli.model.BasicOutput; +import org.apache.commons.io.output.CountingOutputStream; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -307,10 +308,13 @@ private Integer processRequest(NvdCveClientBuilder builder, CacheProperties prop } catch (NoSuchAlgorithmException e) { throw new CacheException("Unable to calculate sha256 checksum", e); } + long byteCount = 0; try (FileOutputStream fileOutputStream = new FileOutputStream(file); GZIPOutputStream gzipOutputStream = new GZIPOutputStream(fileOutputStream); - DigestOutputStream digestOutputStream = new DigestOutputStream(gzipOutputStream, md);) { - objectMapper.writeValue(digestOutputStream, data); + DigestOutputStream digestOutputStream = new DigestOutputStream(gzipOutputStream, md); + CountingOutputStream countingOutputStream = new CountingOutputStream(digestOutputStream)) { + objectMapper.writeValue(countingOutputStream, data); + byteCount = countingOutputStream.getByteCount(); } catch (IOException ex) { throw new CacheException("Unable to write cached data: " + file, ex); } @@ -320,6 +324,7 @@ private Integer processRequest(NvdCveClientBuilder builder, CacheProperties prop PrintWriter writer = new PrintWriter(osw)) { final String lmd = DateTimeFormatter.ISO_DATE_TIME.format(timestamp); writer.println("lastModifiedDate:" + lmd); + writer.println("size: " + byteCount); writer.println("gzSize:" + file.length()); writer.println("sha256:" + checksum); } catch (IOException ex) {