title: Invalidate java.util.zip.ZipOutputStream
body: <p>i am trying to invalidate a Zip file I am streaming to the browser, to make it impossible for the user to open it.</p>
  <pre><code>@GetMapping(&quot;/downloads/${downloadId}&quot;)
  fun downloadZip(@PathVariable(&quot;downloadId&quot;) downloadId: String, response: HttpServletResponse): StreamingResponseBody {
      response.addHeader(HttpHeaders.CONTENT_DISPOSITION, &quot;attachement;filename=\&quot;${download.filename}\&quot;&quot;)
      response.status = HttpServletResponse.SC_OK
      response.contentType = MediaType.APPLICATION_OCTET_STREAM_VALUE
      return StreamingResponseBody { out -&gt;
          ZipOutputStream(out).use { zos -&gt; 
              URL(fileUrl).openStream().use { stream -&gt;
                  zos.putNextEntry(ZipEntry(&quot;target.file&quot;)) 
                  val bytes: ByteArray
                  do {
                      bytes = stream.readNBytes(100000000)
                      val hash = md5(bytes)
                      if (hash != expectedHash) {
                          // What i am looking for
                          zos.invalidate()
                      } 
                      bytes.inputStream().transferTo(zos)
                  } while(bytes.size &gt; 0)
                  zos.closeEntry()
              }
          }
      }
  }
  </code></pre>
  <p>In the server i am checking md5 checksums of chunks and if they are not equal the user shouldn't be able to use the data in the zip.</p>
  <p>Do you have a idea how to achieve that?</p>