SimpleTextWriter implements Closeable { public SimpleTextWriter write(String s) throws IOException { try { if (s == null || s.length() == 0) return this; writer.write(s); return this; } finally { if (!keepOpen) close(); } } private  SimpleTextWriter(
            BufferedWriter writer,
            OutputStream os,
            String encoding,
            boolean keepOpen);  SimpleTextWriter(String fileName);  SimpleTextWriter(String fileName, String encoding);  SimpleTextWriter(File file, String encoding);  SimpleTextWriter(File file); static SimpleTextWriter oneShotUTF8Writer(File file); static SimpleTextWriter keepOpenUTF8Writer(File file); static SimpleTextWriter keepOpenWriter(OutputStream os, String encoding); static SimpleTextWriter oneShotWriter(OutputStream os, String encoding); static SimpleTextWriter keepOpenWriter(OutputStream os); String getEncoding(); boolean isKeepOpen(); SimpleTextWriter writeLines(Collection<String> lines); SimpleTextWriter writeLines(String... lines); SimpleTextWriter writeToStringLines(Collection<?> objects); SimpleTextWriter write(String s); SimpleTextWriter writeLine(String s); SimpleTextWriter writeLine(); SimpleTextWriter writeLine(Object obj); SimpleTextWriter copyFromStream(InputStream is); SimpleTextWriter copyFromURL(String urlStr); void close();  }
@Test public void WriteStringTest() throws IOException { new SimpleTextWriter(tmpFile).write("Hello World!"); Assert.assertEquals(new SimpleTextReader(tmpFile).asString(), "Hello World!"); new SimpleTextWriter(tmpFile).write(null); Assert.assertEquals(new SimpleTextReader(tmpFile).asString(), ""); new SimpleTextWriter(tmpFile).write(""); Assert.assertEquals(new SimpleTextReader(tmpFile).asString(), ""); }
@Test public void WriteStringKeepOpenTest() throws IOException { SimpleTextWriter sfw = new SimpleTextWriter .Builder(tmpFile) .keepOpen() .build(); sfw.write("Hello"); sfw.write("Merhaba"); sfw.write(""); sfw.write(null); IOs.closeSilently(sfw); Assert.assertEquals("HelloMerhaba", new SimpleTextReader(tmpFile).asString()); }
@Test(expected = IOException.class) public void keepOpenExcepionTest() throws IOException { SimpleTextWriter sfw = new SimpleTextWriter .Builder(tmpFile) .build(); sfw.write("Hello"); sfw.write("Now it will throw an exception.."); }