+ private BufferedReader extract(final ZipInputStream zis, final AtomicInteger totalSizeEntry,
+ final long compressedSize) throws PerformanceManagementException, IOException {
+ final var out = new ByteArrayOutputStream();
+ final var buffer = new byte[READ_BUFFER_SIZE];
+ int len;
+
+ while (zis.available() > 0) {
+ len = zis.read(buffer);
+ final int currentSize = totalSizeEntry.addAndGet(len);
+
+ if (currentSize > THRESHOLD_SIZE) {
+ throw new PerformanceManagementException("ZIP file too big.");
+ }
+
+ final double compressionRatio = (double) currentSize / compressedSize;
+ if (compressionRatio > THRESHOLD_RATIO) {
+ throw new PerformanceManagementException("Wrong file type, threshold to high " + compressionRatio);
+ }
+
+ if (len > 0) {
+ out.write(buffer, 0, len);
+ }
+ }
+
+ return new BufferedReader(
+ new InputStreamReader(new ByteArrayInputStream(out.toByteArray()), StandardCharsets.UTF_8));
+ }
+