class RxFiles {

  @Nonnull
  public Completable writeBytesToFile(@Nonnull final byte[] data, @Nonnull final File file) {
    checkNotNull(file, "\'file\' must not be null.");
    checkNotNull(data, "\'data\' must not be null.");
    
    return exists(file)
        .flatMapCompletable(exists -> exists ?
            Completable.complete() :
            Completable.error(new IOException("File does not exist.")))
        .andThen(Completable.fromAction(() -> FileUtils.writeByteArrayToFile(file, data)));
  }

}