Scans the given token global token stream for a list of sub-token
streams representing those portions of the global stream that
may contain date time information

@param stream
@return
347271
private List<TokenStream> collectTokenStreams(TokenStream stream) {
    
    // walk through the token stream and build a collection 
    // of sub token streams that represent possible date locations
    List<Token> currentGroup = null;
    List<List<Token>> groups = new ArrayList<List<Token>>();
    Token currentToken;
    int currentTokenType;
    StringBuilder tokenString = new StringBuilder();
    while((currentToken = stream.getTokenSource().nextToken()).getType() != DateLexer.EOF) {
      currentTokenType = currentToken.getType();
      tokenString.append(DateParser.tokenNames[currentTokenType]).append(" ");

      // we're currently NOT collecting for a possible date group
      if(currentGroup == null) {
        // skip over white space and known tokens that cannot be the start of a date
        if(currentTokenType != DateLexer.WHITE_SPACE &&
            DateParser.FOLLOW_empty_in_parse186.member(currentTokenType)) {

          currentGroup = new ArrayList<Token>();
          currentGroup.add(currentToken);
        }
      }

      // we're currently collecting
      else {
        // preserve white space
        if(currentTokenType == DateLexer.WHITE_SPACE) {
          currentGroup.add(currentToken);
        }

        else {
          // if this is an unknown token, we'll close out the current group
          if(currentTokenType == DateLexer.UNKNOWN) {
            addGroup(currentGroup, groups);
            currentGroup = null;
          }
          // otherwise, the token is known and we're currently collecting for
          // a group, so we'll add it to the current group
          else {
            currentGroup.add(currentToken);
          }
        }
      }
    }

    if(currentGroup != null) {
      addGroup(currentGroup, groups);
    }
    
    _logger.info("STREAM: " + tokenString.toString());
    List<TokenStream> streams = new ArrayList<TokenStream>();
    for(List<Token> group:groups) {
      if(!group.isEmpty()) {
        StringBuilder builder = new StringBuilder();
        builder.append("GROUP: ");
        for (Token token : group) {
          builder.append(DateParser.tokenNames[token.getType()]).append(" ");
        }
        _logger.info(builder.toString());

        streams.add(new CommonTokenStream(new NattyTokenSource(group)));
      }
    }

    return streams;
  }
130278
public static QueryParser parser(CommonTokenStream tokens) {
        QueryParser parser = new QueryParser(tokens);
        parser.setErrorHandler(new BailErrorStrategy());
        return parser;
    }
418240
Map<String,Long> getContext(String... tokens) throws IOException {
    Objects.requireNonNull(tokens);
    TermsEnum iterator = getIterator();
    Map<String,Long> result = new HashMap<>();
    BytesRef byteRef;
    int i = 0;
    while ((byteRef = iterator.next()) != null) {
      String term = new String(byteRef.bytes, byteRef.offset, byteRef.length);
      for (String token : tokens) {
        if (term.contains(" " + token + " ")) {
          String[] split = term.split(" ");
          if (split.length == 3) {
            long count = getCount(Arrays.asList(split[0], split[1], split[2]));
            result.put(term, count);
          }
        }
      }
      /*if (i++ > 1_000_000) { // comment in for faster testing with subsets of the data
        break;
      }*/
    }
    return result;
  }
860177
public static List<FastaSequence> readFasta(final InputStream inStream)
		throws IOException {
	final List<FastaSequence> seqs = new ArrayList<FastaSequence>();

	final BufferedReader infasta = new BufferedReader(
		new InputStreamReader(inStream, "UTF8"), 16000);
	final Pattern pattern = Pattern.compile("//s+");

	String line;
	String sname = "", seqstr = null;
	do {
		line = infasta.readLine();
		if ((line == null) || line.startsWith(">")) {
		if (seqstr != null) {
			seqs.add(new FastaSequence(sname.substring(1), seqstr));
		}
		sname = line; // remove >
		seqstr = "";
		} else {
		final String subseq = pattern.matcher(line).replaceAll("");
		seqstr += subseq;
		}
	} while (line != null);

	infasta.close();
	return seqs;
	}
512437
public void print(PrintStream stream) {
    if (mSeries.isEmpty()) {
      return;
    }
    long start = mSeries.firstKey();
    stream.printf("Time series starts at %d with width %d.%n", start, mWidthNano);
    int bucketIndex = 0;
    Iterator<Map.Entry<Long, Integer>> it = mSeries.entrySet().iterator();

    Map.Entry<Long, Integer> current = it.next();
    while (current != null) {
      int numEvents = 0;
      if (bucketIndex * mWidthNano + start == current.getKey()) {
        numEvents = current.getValue();
        current = null;
        if (it.hasNext()) {
          current = it.next();
        }
      }
      stream.printf("%d %d%n", bucketIndex, numEvents);
      bucketIndex++;
    }
  }
45132
private Links getLinks(InputStream stream) {

		try {
			return this.mapper.readValue(stream, UberDocument.class).getUber().getLinks();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
756870
public static <T> List<T> toList(Stream<T> stream) {
        return stream.collect(Collectors.<T>toList());
    }
944730
public static String readAsString( InputStream stream ) {
		StringBuilder code = new StringBuilder();
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
			String line;
			while ((line = reader.readLine()) != null)
				code.append(line).append(System.lineSeparator());
			reader.close();
		} catch (IOException e) {
			return null;
//			throw new RuntimeException(e);
		}
		String output = code.toString();

		// make windows strings appear the same as linux strings
		String nl = System.getProperty("line.separator");
		if( nl.compareTo("\n") != 0 ) {
			output = output.replaceAll(nl,"\n");
		}

		return output;
	}
761227
function serializeStream(stream) {
      // 1. Let token be the result of reading from stream.
      // (Done in-place on array, rather than as a stream)

      // 2. If encoding is UTF-8, UTF-16BE, or UTF-16LE, and ignore
      // BOM flag and BOM seen flag are unset, run these subsubsteps:
      if (includes(['UTF-8', 'UTF-16LE', 'UTF-16BE'], this._encoding.name) &&
          !this._ignoreBOM && !this._BOMseen) {
        if (stream.length > 0 && stream[0] === 0xFEFF) {
          // 1. If token is U+FEFF, set BOM seen flag.
          this._BOMseen = true;
          stream.shift();
        } else if (stream.length > 0) {
          // 2. Otherwise, if token is not end-of-stream, set BOM seen
          // flag and append token to stream.
          this._BOMseen = true;
        } else {
          // 3. Otherwise, if token is not end-of-stream, append token
          // to output.
          // (no-op)
        }
      }
      // 4. Otherwise, return output.
      return codePointsToString(stream);
    }
167374
public JSON readFromStream( InputStream stream ) {
      try{
         StringBuffer xml = new StringBuffer();
         BufferedReader in = new BufferedReader( new InputStreamReader( stream ) );
         String line = null;
         while( (line = in.readLine()) != null ){
            xml.append( line );
         }
         return read( xml.toString() );
      }catch( IOException ioe ){
         throw new JSONException( ioe );
      }
   }
711024
private static stream_response newTscStream(Stream<TimeSeriesCollection> tsc, int fetch) {
        final BufferedIterator<TimeSeriesCollection> iter = new BufferedIterator(tsc.iterator(), TSC_QUEUE_SIZE);
        final long idx = TSC_ITERS_ALLOC.getAndIncrement();
        final IteratorAndCookie<TimeSeriesCollection> iterAndCookie = new IteratorAndCookie<>(iter);
        TSC_ITERS.put(idx, iterAndCookie);

        final List<TimeSeriesCollection> result = fetchFromIter(iter, fetch, MAX_TSC_FETCH);
        EncDec.NewIterResponse<TimeSeriesCollection> responseObj
                = new EncDec.NewIterResponse<>(idx, result, iter.atEnd(), iterAndCookie.getCookie());
        LOG.log(Level.FINE, "responseObj = {0}", responseObj);
        return EncDec.encodeStreamResponse(responseObj);
    }
1363829
@Override
    public Storingen getModel(InputStream stream) {
        SimpleDateFormat format = new SimpleDateFormat(NsApi.DATETIME_FORMAT);
        try {
            List<Storing> geplandeStoringen = new LinkedList<>();
            List<Storing> ongeplandeStoringen = new LinkedList<>();

            Xml xml = Xml.getXml(stream, "Storingen");
            if (xml.isPresent("Ongepland")) {
                Xml ongeplandeStoringenXml = xml.child("Ongepland");
                for (Xml storingXml : ongeplandeStoringenXml.children("Storing")) {
                    ongeplandeStoringen.add(getStoring(storingXml, format));
                }
            }
            if (xml.isPresent("Gepland")) {
                Xml geplandeStoringenXml = xml.child("Gepland");
                for (Xml storingXml : geplandeStoringenXml.children("Storing")) {
                    geplandeStoringen.add(getStoring(storingXml, format));
                }
            }
            return new Storingen(ongeplandeStoringen, geplandeStoringen);
        }
        catch (ParseException e) {
            logger.error("Error parsing stream to actuele vertrektijden", e);
            throw new NsApiException("Error parsing stream to actuele vertrektijden", e);
        }
    }
878652
public static Map<String, Object> read(InputStream stream)
		throws IOException
	{
		ConfigJsonInput input = new ConfigJsonInput(new InputStreamReader(stream, StandardCharsets.UTF_8));
		return read(input);
	}
326666
public static String[] streamTags(String scope, String stream) {
        return new String[] {TAG_SCOPE, scope, TAG_STREAM, stream};
    }
806045
public static <T> Map<T, Long> countBy(Stream<T> stream) {
        return stream.collect(groupingBy(identity(), counting()));
    }
491510
private void parseCalendarList(final StreamTokenizer tokeniser, Reader in, 
            final ContentHandler handler) throws IOException, ParseException,
            URISyntaxException, ParserException {

        // BEGIN:VCALENDAR
        int ntok = assertToken(tokeniser, in, Calendar.BEGIN, false, true);
        while (ntok != StreamTokenizer.TT_EOF) {
            parseCalendar(tokeniser, in, handler);
            ntok = absorbWhitespace(tokeniser, in, true);
        }
    }
538445
private <T extends URNIdentified> Stream<T> sortStreamLexicographically(Stream<T> inputStream) {
    Spliterator<T> spliterator = inputStream.spliterator();
    if (spliterator.hasCharacteristics(Spliterator.SORTED) && spliterator.getComparator()
        .equals(this.lexicographicalComparator)) {
      return StreamSupport.stream(spliterator, false);
    }
    return StreamSupport.stream(spliterator, false).sorted(this.lexicographicalComparator);
  }