StreamUtil { public static void writeText(CharSequence chars, OutputStream out, String charset, boolean closeOut) throws IOException { Writer writer = charset == null ? new OutputStreamWriter(out) : new OutputStreamWriter(out, charset); writeText(chars, writer, closeOut); }  static void io(InputStream in, OutputStream out); static void io(InputStream in, OutputStream out, int bufferSize); static void io(Reader in, Writer out); static void io(Reader in, Writer out, int bufferSize); static void io(InputStream in, OutputStream out, boolean closeIn, boolean closeOut); static void io(Reader in, Writer out, boolean closeIn, boolean closeOut); static void io(InputStream in, File dest); static void io(InputStream in, File dest, boolean closeIn, boolean closeOut); static void io(InputStream in, String dest); static void io(InputStream in, String dest, boolean closeIn, boolean closeOut); static void io(Reader in, File dest); static void io(Reader in, File dest, boolean closeIn, boolean closeOut); static void io(Reader in, String dest); static void io(Reader in, String dest, boolean closeIn, boolean closeOut); static OutputStream synchronizedOutputStream(OutputStream out); static OutputStream synchronizedOutputStream(OutputStream out, Object lock); static String readText(InputStream in); static String readText(InputStream in, String encoding); static String readText(InputStream in, String charset, int bufferSize); static String readText(InputStream in, String charset, boolean closeIn); static String readText(Reader in, boolean closeIn); static String readText(Reader reader); static String readText(Reader reader, int bufferSize); static ByteArray readBytes(InputStream in); static ByteArray readBytes(InputStream in, boolean closeIn); static ByteArray readBytes(File file); static ByteArray readBytes(File file, boolean closeIn); static byte[] readBytesByFast(InputStream in); static byte[] readBytesByFast(InputStream in, boolean closeIn); static void writeText(CharSequence chars, OutputStream out, String charset, boolean closeOut); static void writeText(CharSequence chars, Writer out, boolean closeOut); static void writeBytes(byte[] bytes, String filePath, boolean closeOut); static void writeBytes(byte[] bytes, File file, boolean closeOut); static void writeBytes(byte[] bytes, OutputStream out, boolean closeOut); static void writeBytes(ByteArray bytes, OutputStream out, boolean closeOut); static void close(Closeable closed);  }
@Test public void writeText() throws IOException { test(new CB() { public void run(boolean close) throws IOException { SW writer = new SW(); StreamUtil.writeText(chars, writer, close); assertEquals(chars, writer.toString()); writer.assertClosed(close); BAOS stream = new BAOS(); StreamUtil.writeText(chars, stream, "GBK", close); assertArrayEquals(bytes, stream.toByteArray()); stream.assertClosed(close); } }); }