Use the given read to build a list of aligned read and reference base
information.

@param read The read with the alignment information
@return read and reference information.  For a read without an alignment
or cigar units, null is returned.
340103
public static List<ReadBaseWithReference> extractReadBases(Read read) {

    // Make sure this read has a valid alignment with Cigar Units
    if (!read.hasAlignment() || (read.getAlignment().getCigarCount() == 0)) {
      return null;
    }

    ImmutableList.Builder<ReadBaseWithReference> bases = ImmutableList.builder();

    String readSeq = read.getAlignedSequence();
    List<Integer> readQual = read.getAlignedQualityList();
    String refSeq = UNINITIALIZED_REFERENCE_SEQUENCE;

    int refPosAbsoluteOffset = 0;
    int readOffset = 0;
    for (CigarUnit unit : read.getAlignment().getCigarList()) {
      switch(unit.getOperation()) {
        case ALIGNMENT_MATCH:
        case SEQUENCE_MISMATCH:
        case SEQUENCE_MATCH:
          for (int i = 0; i < unit.getOperationLength(); i++) {
            String refBase = "";
            if (unit.getOperation().equals(CigarUnit.Operation.SEQUENCE_MATCH)) {
              refBase = readSeq.substring(readOffset, readOffset + 1);
            } else if (!unit.getReferenceSequence().isEmpty()) {
              // try to get the ref sequence from the Cigar unit
              refBase = unit.getReferenceSequence().substring(i, i + 1);
            } else {
              // try to get the ref sequence by fully parsing the MD tag if not already cached
              if (refSeq != null && refSeq.equals(UNINITIALIZED_REFERENCE_SEQUENCE)) {
                refSeq = com.google.cloud.genomics.utils.grpc.ReadUtils
                    .inferReferenceSequenceByParsingMdFlag(read);
              }
              if (refSeq != null) {
                refBase = refSeq.substring(readOffset, readOffset + 1);
              }
            }
            String name = read.getAlignment().getPosition().getReferenceName();
            Matcher m = Pattern.compile("^(chr)?(X|Y|([12]?\\d))$").matcher(name);
            if (m.matches()) {
              name = m.group(m.groupCount() - 1);
            }
            Position refPosition = Position.newBuilder()
                .setReferenceName(name)
                .setPosition(read.getAlignment().getPosition().getPosition()
                  + refPosAbsoluteOffset)
                  .build();
            bases.add(new ReadBaseWithReference(new ReadBaseQuality(
                readSeq.substring(readOffset, readOffset + 1),
                readQual.get(readOffset)),
                refBase,
                refPosition));
            refPosAbsoluteOffset++;
            readOffset++;
          }
          break;

        case PAD:        // padding (silent deletion from padded reference)
        case CLIP_HARD:  // hard clipping (clipped sequences NOT present in seq)
          break;

        case CLIP_SOFT:  // soft clipping (clipped sequences present in SEQ)
        case INSERT:     // insertion to the reference
          readOffset += unit.getOperationLength();
          break;

        case DELETE:  // deletion from the reference
        case SKIP:    // intron (mRNA-to-genome alignment only)
          refPosAbsoluteOffset += unit.getOperationLength();
          break;

        default:
          throw new IllegalArgumentException("Illegal cigar code: " + unit.getOperation());
      }
    }

    return bases.build();
  }
734581
public Toml read(Reader reader) {
    BufferedReader bufferedReader = null;
    try {
      bufferedReader = new BufferedReader(reader);

      StringBuilder w = new StringBuilder();
      String line = bufferedReader.readLine();
      while (line != null) {
        w.append(line).append('\n');
        line = bufferedReader.readLine();
      }
      read(w.toString());
    } catch (IOException e) {
      throw new RuntimeException(e);
    } finally {
      try {
        bufferedReader.close();
      } catch (IOException e) {}
    }
    return this;
  }
717093
public Map<Object, String> read(Reader reader) throws IOException {
        Map<Object, String> cvs = new HashMap<>();
        try (CSVReader r = new CSVReader(reader, '\t')) {
            String[] cols;
            int i = 1;
            while ((cols = r.readNext()) != null) {
                switch (cols.length) {
                    case 0:
                        break;
                    case 1:
                        String col0 = cols[0];
                        if (col0.length() > 1) {
                            cvs.put(col0, "");
                        }
                        break;
                    case 2:
                        cvs.put(cols[1], cols[0]);
                        break;
                    default:
                        throw new IOException("Invalid mapping in line " + i + ": mapping has length " + cols.length);
                }
                i++;
            }
        }
        return cvs;
    }
26289
protected UnmappedReads<Read> getUnmappedMatesOfMappedReads(String readsetId) 
      throws GeneralSecurityException, IOException {
    LOG.info("Collecting unmapped mates of mapped reads for injection");
    final Iterable<Read> unmappedReadsIterable = getUnmappedReadsIterator(readsetId); 
    final UnmappedReads<Read> unmappedReads = createUnmappedReads();
    for (Read read : unmappedReadsIterable) {
      unmappedReads.maybeAddRead(read);
    }
    LOG.info("Finished collecting unmapped mates of mapped reads: " + 
        unmappedReads.getReadCount() + " found.");
    return unmappedReads;
  }
898891
public static StringBlock read(IntReader reader) throws IOException {
        ReadUtil.readCheckType(reader,CHUNK_TYPE);
        int chunkSize=reader.readInt();
        int stringCount=reader.readInt();
        int styleOffsetCount=reader.readInt();
        int flags = reader.readInt();
        int stringsOffset=reader.readInt();
        int stylesOffset=reader.readInt();

        StringBlock block=new StringBlock();
        block.m_stringOffsets=reader.readIntArray(stringCount);
        if (styleOffsetCount!=0) {
            block.m_styleOffsets=reader.readIntArray(styleOffsetCount);
        }
        {
            int size=((stylesOffset==0)?chunkSize:stylesOffset)-stringsOffset;
            if ((size%4)!=0) {
                throw new IOException("String data size is not multiple of 4 ("+size+").");
            }
            block.m_stringPool =reader.readByteArray(size);
        }
        if (stylesOffset!=0) {
            int size=(chunkSize-stylesOffset);
            if ((size%4)!=0) {
                throw new IOException("Style data size is not multiple of 4 ("+size+").");
            }
            block.m_styles=reader.readIntArray(size/4);
        }

        // Set field flag to determine if stored in UTF-8 (or false for UTF-16).
        block.m_isUtf8 = (flags & UTF8_FLAG) == UTF8_FLAG;

        block.m_strings =new String[block.getCount()];
        for (int i=0;i!=block.getCount();++i) {
            block.m_strings[i]=block.stringAt(i);
        }

        return block;
    }
695320
public int read(char[] cbuf, int off, int len) throws IOException {
        int startPos = off;
        int currentlyRead;
        while (off - startPos < len && (currentlyRead = read()) != -1) {
            cbuf[off++] = (char) currentlyRead;
        }
        return off == startPos && len != 0 ? -1 : off - startPos;
    }
628561
public static List<String> readToList(Reader r) throws IOException {
		try ( BufferedReader in = new BufferedReader(r) ) {
			List<String> l = new ArrayList<>();
			String line = null;
			while ((line = in.readLine()) != null)
				l.add(line);
			return Collections.unmodifiableList(l);
		}
	}
879980
@Override
    public int read(byte[] b, int off, int len) throws IOException {
        if (b == null) {
            throw new NullPointerException();
        } else if (off < 0 || len < 0 || len > b.length - off) {
            throw new IndexOutOfBoundsException();
        } else if (len == 0) {
            return 0;
        }

        byte[] next = ensureDataAvailable(true);
        if (next == null) {
            return -1;
        }
        int numRead = Math.min(next.length - index, len);
        System.arraycopy(next, index, b, off, numRead);
        index += numRead;
        return numRead;
    }
199644
public static Properties loadProperties(Reader reader) {
        Properties prop = new Properties();
        try {
            prop.load(reader);
        } catch (IOException e) {
            throw E.ioException(e);
        } finally {
            IO.close(reader);
        }
        return prop;
    }
328586
@Override
    public int read(byte[] out, final int off, final int len) throws IOException {
        if (off < 0 || len < 0 || (off + len) > out.length) {
            throw new IllegalArgumentException(String.format(
                    "Illegal arguments for read: byte[%d], off:%d, len:%d",
                    out.length, off, len));
        }

        final int end = off + len;
        int pos = off;
        int i;
        while (pos < end && (i = in.read(out, off, end - off)) >= 0) {
            pos += i;
        }
        return pos - off;
    }
426389
public Properties readProperties() throws IOException {
        Properties p;

        try (Reader src = newReader()) {
            p = new Properties();
            p.load(src);
        }
        return p;
    }
1032386
public ReadStream openRead()
    throws IOException
  {
    if (_isDone)
      return null;
    else if (_readStream == null)
      _readStream = new ReadStream(this);
    else if (!_isPartDone) {
      int len;
      while ((len = read(_dummyBuffer, 0, _dummyBuffer.length)) >= 0) {
      }

      if (_isDone)
        return null;
    }

    _readStream.init(this);

    _isPartDone = false;

    if (scanHeaders()) {
      String contentType = (String) getAttribute("content-type");

      String charset = getAttributePart(contentType, "charset");

      // FIXME: 2016-05-14 
/*
      if (charset != null)
        _readStream.setEncoding(charset);
      else if (_defaultEncoding != null)
        _readStream.setEncoding(_defaultEncoding);
*/

      return _readStream;
    }
    else {
      _isDone = true;
      _readStream.close();
      return null;
    }
  }
190218
private String read(final BufferedReader reader) throws IOException {
		StringBuilder sqlBuilder = new StringBuilder();
		try {
			for (String line : reader.lines().toArray(String[]::new)) {
				sqlBuilder.append(line).append(System.lineSeparator());
			}
		} finally {
			if (reader != null) {
				reader.close();
			}
		}

		return sqlBuilder.toString();
	}
1321346
public int read(final Reader reader) throws IOException {
        final int c = reader.read(cbuf);
        if (c > 0) {
            addData(cbuf, 0, c);
        }
        return c;
    }
521952
public static Set<String> readStopwords(BufferedReader reader) throws IOException {
    HashSet<String> words = new HashSet<String>();
    String nextLine;
    while (((nextLine = reader.readLine()) != null)) {
      words.add(nextLine.trim().toLowerCase());
    }
    return words;
  }
707106
public static MtasConfiguration readConfiguration(InputStream reader)
      throws IOException {
    MtasConfiguration currentConfig = null;
    // parse xml
    XMLInputFactory factory = XMLInputFactory.newInstance();
    try {
      XMLStreamReader streamReader = factory.createXMLStreamReader(reader);
      QName qname;
      try {
        int event = streamReader.getEventType();
        while (true) {
          switch (event) {
          case XMLStreamConstants.START_DOCUMENT:
            if (!streamReader.getCharacterEncodingScheme().equals("UTF-8")) {
              throw new IOException("XML not UTF-8 encoded");
            }
            break;
          case XMLStreamConstants.END_DOCUMENT:
          case XMLStreamConstants.SPACE:
            break;
          case XMLStreamConstants.START_ELEMENT:
            // get data
            qname = streamReader.getName();
            if (currentConfig == null) {
              if (qname.getLocalPart().equals("mtas")) {
                currentConfig = new MtasConfiguration();
              } else {
                throw new IOException("no Mtas Configuration");
              }
            } else {
              MtasConfiguration parentConfig = currentConfig;
              currentConfig = new MtasConfiguration();
              parentConfig.children.add(currentConfig);
              currentConfig.parent = parentConfig;
              currentConfig.name = qname.getLocalPart();
              for (int i = 0; i < streamReader.getAttributeCount(); i++) {
                currentConfig.attributes.put(
                    streamReader.getAttributeLocalName(i),
                    streamReader.getAttributeValue(i));
              }
            }
            break;
          case XMLStreamConstants.END_ELEMENT:
            if (currentConfig.parent == null) {
              return currentConfig;
            } else {
              currentConfig = currentConfig.parent;
            }
            break;
          case XMLStreamConstants.CHARACTERS:
            break;
          }
          if (!streamReader.hasNext()) {
            break;
          }
          event = streamReader.next();
        }
      } finally {
        streamReader.close();
      }
    } catch (XMLStreamException e) {
      log.debug(e);
    }
    return null;
  }
1087743
private static List<Object> readerToList(JsonReader reader) throws IOException {
    // todo: try to infer the type of the List?
    List<Object> list = new ArrayList<Object>();
    reader.beginArray();
    while (reader.hasNext()) {
      list.add(readValue(reader));
    }
    reader.endArray();
    return list;
  }