Filesystem { public Completable writeFile(final String content, String filePath) { return Completable.create(s -> { AsynchronousFileChannel channel = AsynchronousFileChannel.open(Paths.get(filePath), StandardOpenOption.WRITE, StandardOpenOption.CREATE); ByteBuffer contentBuffer = ByteBuffer.wrap(content.getBytes()); channel.write(contentBuffer, 0, null, new CompletionHandler<Integer, ByteBuffer>() { @Override public void completed(Integer result, final ByteBuffer attachment) { s.onComplete(); } @Override public void failed(final Throwable exc, final ByteBuffer attachment) { s.onError(exc); } }); }); }  Flowable<String> readTextFile(String pathToFile); Flowable<String> readTextFileFromClasspath(String resourcePath); Single<String> readTextFileFully(String pathToFile); Single<String> readTextFileFullyFromClasspath(String resourcePath); Completable writeFile(final String content, String filePath); Completable writeFileSync(String content, String filePath, boolean append); Completable writeFileSync(String content, Charset encoding, String filePath, boolean append);  }
@Test void testWriteFileAsyncWithUnknownPathCreatesFile() { try { TestObserver<Void> observer = filesystem.writeFile("content", "isntThere.txt").test(); await().atMost(2, SECONDS).until(observer::isTerminated); assertTrue(new File("isntThere.txt").exists()); } finally { File file = new File("isntThere.txt"); if (file.exists()) { file.delete(); } } }