Assumes the given reader has only tsurgeon operations (not a tregex pattern), and parses
these out, collecting them into one operation.  Stops on a whitespace line.

@throws IOException
551371
public static TsurgeonPattern getTsurgeonOperationsFromReader(BufferedReader reader) throws IOException {
    List<TsurgeonPattern> operations = new ArrayList<TsurgeonPattern>();
    for (String thisLine; (thisLine = reader.readLine()) != null; ) {
      if (emptyLinePattern.matcher(thisLine).matches()) {
        break;
      }
      thisLine = removeComments(thisLine);
      if (emptyLinePattern.matcher(thisLine).matches()) {
        continue;
      }
      // System.err.println("Read tsurgeon op: " + thisLine);
      operations.add(parseOperation(thisLine));
    }
    return collectOperations(operations);
  }
222955
void readFrom(InputStream in) throws IOException {
		//TODO could optimize for aligned instances
		final int size = finish - start;
		final int length = (size + 7) >> 3;
		if (length == 0) return;
		int p = size & 7;
		final int q = finish - p;
		if (p != 0) performAdj(SET, q, (long) in.read(), p);
		p = q;
		while (p > start) {
			p -= 8;
			performAdj(SET, p, (long) in.read(), 8);
		}
	}
288595
protected static String read(Reader file) throws IOException {
		final StringBuilder content = new StringBuilder();
		try (BufferedReader reader = new BufferedReader(file)) {
			String line = reader.readLine();
			boolean first = true;
			while (line != null) {
				if (first) {
					first = false;
				} else {
					content.append("\n"); //$NON-NLS-1$
				}
				content.append(line);
				line = reader.readLine();
			}
		}
		return content.toString();
	}
285491
@Override
    public void read(final Reader reader) throws ConfigurationException, IOException {
        Preconditions.checkNotNull(reader);

        final HashMap<String, Object> settings = this.mapper.readValue(reader, HASH_MAP_TYPE_REFERENCE);
        final ImmutableNode rootNode = toNode(new Builder(), settings);
        this.getSubConfigurationParentModel().mergeRoot(rootNode, null, null, null, this);
    }
90791
public static String getReaderContentAsString(Reader reader) throws IOException {

        int count;
        final char[] buffer = new char[2048];
        final StringBuilder out = new StringBuilder();
        while ((count = reader.read(buffer, 0, buffer.length)) >= 0) {
            out.append(buffer, 0, count);
        }

        return (out.toString());
    }
520933
public static void readFully(Reader reader, char[] buffer, int offset) throws IOException {
    int originalOffset = offset;
    int expected = buffer.length - offset;
    while (offset < buffer.length) {
      int numRead = reader.read(buffer, offset, buffer.length - offset);
      if (numRead < 0) {
        throw new IOException(
                String.format("Reached end of stream earlier than expected. Expected to read %d bytes. Actual: %d",
                expected, offset - originalOffset));
      }
      offset += numRead;
    }
  }
14361
public static Object[] parse(Reader reader, Class<?>[] types,
                                 Converter<Object, Map<String, Object>> mc) throws IOException,
            ParseException {
        return (Object[]) parse(reader, new JSONVisitor(types,
                new JSONValue(mc)), JSONToken.LSQUARE);
    }
674337
@SuppressWarnings("unchecked")
    public static <T> T parse(Reader reader, Class<T> type,
                              Converter<Object, Map<String, Object>> mc) throws IOException,
            ParseException {
        return (T) parse(reader, new JSONVisitor(type, new JSONValue(mc), mc),
                JSONToken.ANY);
    }
598077
@Override
	public Reader getReader() throws IOException {
		// Return an Aggregation reader for all the resources in this
		// aggregated resource
		List<Reader> readers = new ArrayList<Reader>(resources.size());
		for (IResource resource : resources) {
			readers.add(resource.getReader());
		}
		return new AggregationReader(readers);
	}
414585
public <T extends Collection<String>> T readLines(T collection) throws IORuntimeException {
		BufferedReader reader = null;
		try {
			reader = FileUtil.getReader(file, charset);
			String line;
			while (true) {
				line = reader.readLine();
				if (line == null) {
					break;
				}
				collection.add(line);
			}
			return collection;
		} catch (IOException e) {
			throw new IORuntimeException(e);
		} finally {
			IoUtil.close(reader);
		}
	}
480279
@Override
    public void readExternal(PofReader reader) throws IOException {
        nodeName = reader.readString(0);
        namespace = reader.readString(1);
    }
885874
public Reader getReader() throws IOException {
       // we want to remove the BOM windows adds from a file if the encoding is UTF-8
       // in other cases we depend on the charsets 
       Charset cs = Charset.forName(configuration.getSourceEncoding());
       InputStream in = new BufferedInputStream(new FileInputStream(file));
       if (UTF8.name().equalsIgnoreCase(cs.name())) {
           in.mark(3);
           boolean hasBOM = true;
           try {
               int i = in.read();
               hasBOM &= i == 0xEF;
               i = in.read();
               hasBOM &= i == 0xBB;
               i = in.read();
               hasBOM &= i == 0xFF;
           } catch (IOException ioe) {
               hasBOM= false;
           }
           if (!hasBOM) in.reset();
       }
       return new InputStreamReader( in, cs );
    }
166202
private String getContents(Reader reader, String terminator) throws IOException
    {
        String line = null;
        StringBuffer buff = new StringBuffer();
        BufferedReader in = new BufferedReader(reader);
        while((line = in.readLine()) != null)
        {
            buff.append(line);
            if(terminator != null)
                buff.append(terminator);
        }
        reader.close();
        return buff.toString();
    }
406343
public static String readFully(Reader reader) throws IOException {
        try {
            StringWriter writer = new StringWriter();
            char[] buffer = new char[1024];
            int count;
            while ((count = reader.read(buffer)) != -1) {
                writer.write(buffer, 0, count);
            }
            return writer.toString();
        } finally {
            reader.close();
        }
    }
179777
public T parse(Reader reader) throws IOException {
    T bean = createBean();
    populate(bean, reader);
    return bean;
  }
877959
public static HostsFileEntries parse(Reader reader) throws IOException {
        checkNotNull(reader, "reader");
        BufferedReader buff = new BufferedReader(reader);
        try {
            Map<String, Inet4Address> ipv4Entries = new HashMap<String, Inet4Address>();
            Map<String, Inet6Address> ipv6Entries = new HashMap<String, Inet6Address>();
            String line;
            while ((line = buff.readLine()) != null) {
                // remove comment
                int commentPosition = line.indexOf('#');
                if (commentPosition != -1) {
                    line = line.substring(0, commentPosition);
                }
                // skip empty lines
                line = line.trim();
                if (line.isEmpty()) {
                    continue;
                }

                // split
                List<String> lineParts = new ArrayList<String>();
                for (String s: WHITESPACES.split(line)) {
                    if (!s.isEmpty()) {
                        lineParts.add(s);
                    }
                }

                // a valid line should be [IP, hostname, alias*]
                if (lineParts.size() < 2) {
                    // skip invalid line
                    continue;
                }

                byte[] ipBytes = NetUtil.createByteArrayFromIpAddressString(lineParts.get(0));

                if (ipBytes == null) {
                    // skip invalid IP
                    continue;
                }

                // loop over hostname and aliases
                for (int i = 1; i < lineParts.size(); i ++) {
                    String hostname = lineParts.get(i);
                    String hostnameLower = hostname.toLowerCase(Locale.ENGLISH);
                    InetAddress address = InetAddress.getByAddress(hostname, ipBytes);
                    if (address instanceof Inet4Address) {
                        Inet4Address previous = ipv4Entries.put(hostnameLower, (Inet4Address) address);
                        if (previous != null) {
                            // restore, we want to keep the first entry
                            ipv4Entries.put(hostnameLower, previous);
                        }
                    } else {
                        Inet6Address previous = ipv6Entries.put(hostnameLower, (Inet6Address) address);
                        if (previous != null) {
                            // restore, we want to keep the first entry
                            ipv6Entries.put(hostnameLower, previous);
                        }
                    }
                }
            }
            return ipv4Entries.isEmpty() && ipv6Entries.isEmpty() ?
                    HostsFileEntries.EMPTY :
                    new HostsFileEntries(ipv4Entries, ipv6Entries);
        } finally {
            try {
                buff.close();
            } catch (IOException e) {
                logger.warn("Failed to close a reader", e);
            }
        }
    }
1148482
private void fillReadBuffer() throws IOException {
		// special case for compressed files.
		if(splitLength == FileInputFormat.READ_WHOLE_SPLIT_FLAG) {
			int read = this.stream.read(this.readBuffer, 0, this.readBufferSize);
			if (read == -1) {
				exhausted = true;
			} else {
				this.streamPos += read;
				this.readBufferPos = 0;
				this.readBufferLimit = read;
			}
			return;
		}
		
		int toRead = (int) Math.min(this.streamEnd - this.streamPos, this.readBufferSize);
		if (toRead <= 0) {
			this.exhausted = true;
			return;
		}
		
		// fill read buffer
		int read = this.stream.read(this.readBuffer, 0, toRead);
		
		if (read <= 0) {
			this.exhausted = true;
		} else {
			this.streamPos += read;
			this.readBufferPos = 0;
			this.readBufferLimit = read;
		}
	}