title: Unable to download an mp4 file
body: <p>I'm trying to download an mp4 file, but failing to do so. A file that is 25 MB in size shows up as a file of ~20 KB in the destination folder. Here's my code:</p>
  
  <pre><code>public class DownloadStream {
  
      private final String VIDEO_FOLDER = "StackoverflowQuestion";
      private String URL;
      private String title;
      Context context;
      File rootDirectory;
  
      public DownloadStream(String URL, String title, Context context) {
          this.URL = URL;
          this.title = title;
          this.context = context;
          File filepath = Environment.getExternalStorageDirectory();
          rootDirectory = new File(filepath, VIDEO_FOLDER);
          if (!rootDirectory.exists()) {
              rootDirectory.mkdir();
          }
          DownloadObservable()
                  .observeOn(AndroidSchedulers.mainThread())
                  .subscribeOn(Schedulers.io())
                  .subscribe(new Subscriber&lt;String&gt;() {
                      @Override
                      public void onCompleted() {
                      }
  
                      @Override
                      public void onError(Throwable e) {
  
                      }
  
                      @Override
                      public void onNext(String s) {
  
                      }
                  });
      }
  
  
      Observable&lt;String&gt; DownloadObservable(){
          return Observable.create(new Observable.OnSubscribe&lt;String&gt;() {
              @Override
              public void call(Subscriber&lt;? super String&gt; subscriber) {
                  java.net.URL url;
                  int contentLength;
                  int counter = 0;
                  int percentage;
                  try {
                      url = new URL(URL);
                      HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                      contentLength = connection.getContentLength();
                      connection.setRequestMethod("GET");
                      connection.connect();
                      File file = new File(rootDirectory, title + ".mp4");
                      InputStream inputStream = connection.getInputStream();
                      FileOutputStream fileOutputStream = new FileOutputStream(file);
  
                      byte buffer[] = new byte[1024];
                      int byteCount = 0;
                      while (inputStream.read(buffer) &gt; 0) {
                          byteCount = inputStream.read(buffer);
                          fileOutputStream.write(buffer, 0, byteCount);
                          counter = byteCount + counter;
                          percentage = byteCount / contentLength;
                      }
  
                      fileOutputStream.close();
                      subscriber.onCompleted();
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
          });
      }
  
  
  }
  </code></pre>
  
  <p>What am I doing wrong? Is there a better way to do what I'm trying to do?</p>