Here you can find the source of read(Reader reader)
public static char[] read(Reader reader) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; public class Main { public static byte[] read(InputStream in) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(in.available()); transfer(in, out);// w w w .j a va 2 s.c o m return out.toByteArray(); } public static char[] read(Reader reader) throws IOException { CharArrayWriter writer = new CharArrayWriter(); transfer(reader, writer); return writer.toCharArray(); } public static void transfer(InputStream in, OutputStream out) throws IOException { transfer(in, out, -1L); } public static void transfer(InputStream in, OutputStream out, long limit) throws IOException { byte buf[] = new byte[1024]; long total = 0L; do { int readcount; if ((readcount = in.read(buf)) == -1) break; if (limit != -1L && total + (long) readcount > limit) readcount = (int) (limit - total); if (readcount > 0) out.write(buf, 0, readcount); total += readcount; } while (limit == -1L || total < limit); out.flush(); } public static void transfer(InputStream in, SocketChannel out) throws IOException { byte buf[] = new byte[1024]; ByteBuffer bbuf = ByteBuffer.allocate(1024); int len; while ((len = in.read(buf)) != -1) { bbuf.put(buf, 0, len); bbuf.flip(); for (; bbuf.remaining() > 0; out.write(bbuf)) ; bbuf.clear(); } } public static void transfer(Reader reader, Writer writer) throws IOException { transfer(reader, writer, -1L); } public static void transfer(Reader reader, Writer writer, long limit) throws IOException { char buf[] = new char[1024]; long total = 0L; do { int readcount; if ((readcount = reader.read(buf)) == -1) break; if (limit != -1L && total + (long) readcount > limit) readcount = (int) (limit - total); if (readcount > 0) writer.write(buf, 0, readcount); total += readcount; } while (limit == -1L || total < limit); writer.flush(); } }