public static void saveStreamToFile()

in react-native-pytorch-core/android/src/main/java/org/pytorch/rn/core/utils/FileUtils.java [45:71]


  public static void saveStreamToFile(InputStream inputStream, File destFile) throws IOException {
    BufferedInputStream in = null;
    FileOutputStream fileOutputStream = null;
    try {
      in = new BufferedInputStream(inputStream);
      fileOutputStream = new FileOutputStream(destFile);
      byte[] dataBuffer = new byte[1024];
      int bytesRead;
      while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
        fileOutputStream.write(dataBuffer, 0, bytesRead);
      }
    } catch (IOException e) {
      if (in != null) {
        in.close();
      }
      if (fileOutputStream != null) {
        fileOutputStream.close();
      }
    } finally {
      if (in != null) {
        in.close();
      }
      if (fileOutputStream != null) {
        fileOutputStream.close();
      }
    }
  }