class RxFiles {

  @Nonnull
  public Completable writeStringToFile(
      @Nonnull final String data,
      @Nonnull final File file,
      @Nonnull final Charset charset) {
    
    checkNotNull(file, "\'file\' must not be null.");
    checkNotNull(data, "\'data\' must not be null.");
    checkNotNull(charset, "\'charset\' must not be null.");
    
    return exists(file)
        .flatMapCompletable(exists -> exists ?
            Completable.complete() :
            Completable.error(new IOException("File does not exist.")))
        .andThen(writeBytesToFile(data.getBytes(charset), file));
  }

}