code: File writeTempCacheFile(InputStream stream, FileExtension extension) throws IOException {
      String fileName = filenameForUrl(url, extension, true);
      File file = new File(appContext.getCacheDir(), fileName);
      try {
        OutputStream output = new FileOutputStream(file);
        //noinspection TryFinallyCanBeTryWithResources
        try {
          byte[] buffer = new byte[1024];
          int read;
  
          while ((read = stream.read(buffer)) != -1) {
            output.write(buffer, 0, read);
          }
  
          output.flush();
        } finally {
          output.close();
        }
      } finally {
        stream.close();
      }
      return file;
    }
docs: Writes an InputStream from a network response to a temporary file. If the file successfully parses
  to an composition, {@link #renameTempFile(FileExtension)} should be called to move the file
  to its final location for future cache hits.