public int read(char[] buf, int n) {
        int r = 0;
        while (!queue.isEmpty() && r < n) {
            buf[r++] = queue.poll();
        }

        if (r == n) {
            return r;
        }
        int index = 0;
        int readSize = 0;
        char[] input = null;
        do {
            input = new char[4];
            readSize = read4(input);
            index = 0;
            while(r < n && index < readSize) {
                buf[r++] = input[index++];
            }
        } while (readSize == 4 && r < n);

        while (index < readSize) {
            queue.offer(input[index++]);
        }
        return r;
    }
Date 03/26/2016
@author Tushar Roy

Given a reader which only reads 4 bytes implement a Reader which can read bytes of give size.

Reference
Read N Characters Given Read4 II
https://leetcode.com/problems/read-n-characters-given-read4-ii-call-multiple-times/
src/com/interview/misc/Read4Function.java