void fillBuffer() throws IOException {
            // Only fill the buffer if we haven't reached the end of the file.
            if (!eof) {
                int len = 0;

                // Only fill the buffer if the length of remaining characters is
                // less than half the capacity.
                if (length <= halfCapacity) {
                    // If we processed more than half of the capacity then we need
                    // to shift the buffer up so that the offset becomes 0. This
                    // will give us
                    // room to fill more of the buffer.
                    if (offset >= halfCapacity) {
                        System.arraycopy(buffer, offset, buffer, 0, length);
                        offset = 0;
                    }

                    // Now fill any remaining capacity.
                    int maxLength = capacity - offset;
                    final char[] cb = new char[1];
                    while (maxLength > length && (len = reader.read(cb, 0, 1)) != -1) {
                        if (len > 0) {
                            // If we have filled the buffer then double the size of
                            // it up to the maximum capacity.
                            if (buffer.length == offset + length) {
                                int newLen = buffer.length * 2;
                                if (newLen == 0) {
                                    newLen = initialSize;
                                } else if (newLen > capacity) {
                                    newLen = capacity;
                                }
                                final char[] tmp = new char[newLen];
                                System.arraycopy(buffer, offset, tmp, 0, length);
                                offset = 0;
                                buffer = tmp;

                                // Now the offset has been reset to 0 we should set
                                // the max length to be the maximum capacity.
                                maxLength = capacity;
                            }

                            buffer[offset + length] = cb[0];
                            length++;
                        }
                    }
                }

                // Determine if we reached the end of the file.
                eof = len == -1;
            }
        }
Reads characters into an array.  This method will block until some input
is available, an I/O error occurs, or the end of the stream is reached.

@param cbuf Destination buffer
@return The number of characters read, or -1
if the end of the stream
has been reached
@throws IOException If an I/O error occurs
stroom-pipeline/src/main/java/stroom/pipeline/reader/FindReplaceFilter.java