title: Write continuous stream to file flutter/dart
body: <p>I have a radio live streaming link which I need to record when the user clicks the start button. Then once the user clicks stop I need to save the stream into a file.</p>
  <p>I was able to successfully do this using java by reading the data as a byte array and writing a simple while loop stating as long as the data is not null write the byte into an array and when it is null then write the byte array to a file. Below I can provide a snippet of the code I have used in Java.</p>
  <pre><code>URL url = new URL(radioStream);
  inputStreamRecording = url.openStream();
  
  fileOutputStreamRecording = new FileOutputStream(OutputSourceStream + &quot;/temp.mp3&quot;);
  recordingBuffer = inputStreamRecording.read();
  
  while (recordingBuffer &gt; -1) {
     fileOutputStreamRecording.write(recordingBuffer);
     recordingBuffer = inputStreamRecording.read();
  }
  </code></pre>
  <p>However, I am at a loss on how to do it in dart/flutter and cannot find any sort of example on this. So my question is how would I convert the Java code I have above into something I could use in Flutter. I am assuming I would use Future but how would you stop a future during the recording on a click event? Any help would be appreciated. Thank you in advance!</p>