code: public static String compressChunks(String text) throws IOException {
          Path tempFolder = Paths.get(JAVA_TEMP_DIR, ZIP_UTILS);
          File tempFileIn = File.createTempFile(TMP_IN_, ZIP_UTILS_SUFFIX, tempFolder.toFile());
          File tempFileOut = File.createTempFile(TMP_OUT_, ZIP_UTILS_SUFFIX, tempFolder.toFile());
  
          writeChunkBytes(text, tempFileIn);
          String result;
          if (text != null && text.length() > 0) {
              try (InputStream in = new FileInputStream(tempFileIn);
                   FileOutputStream fileOutputStream = new FileOutputStream(tempFileOut);
                   BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
                   OutputStream out = new GZIPOutputStream(bufferedOutputStream);) {
  
                  byte[] bytes = new byte[BYTES_BUFFER_SIZE];
                  int len;
                  while ((len = in.read(bytes)) > 0) {
                      out.write(bytes, 0, len);
                  }
  
                  in.close();
                  out.flush();
                  out.close();
  
                  // result = new BASE64Encoder().encode(Files.readAllBytes(tempFileOut.toPath()));
                  result = Base64.encodeBase64String(Files.readAllBytes(tempFileOut.toPath()));
              }
          } else {
              result = text;
          }
  
          Files.deleteIfExists(tempFileIn.toPath());
          Files.deleteIfExists(tempFileOut.toPath());
  
          return result;
      }
docs: The method compresses the big strings using gzip - low memory via the File system
  
  @param text The string to compress.
  @return The compressed string.
  @throws java.io.IOException