/*
The constructor of MARC ISO2709 reader.
346855
function MarcIsoReader(options) {
  if (!(this instanceof MarcIsoReader)) {
    return new MarcIsoReader(options);
  }

  // File with records in ISO2709 format.
  this.recordsFile = null;
  // Buffer for the record (maximum size of the ISO2709 record is 99999 bytes).
  this.recordBuffer = new Buffer(100000);
  // Flag is true when next() can be performed.
  this.readyToRead = false;

  // File options.
  options = options || {};
  this.options = {
    // MARC format variation (MARC21, UNIMARC).
    format: (options.format || 'UNIMARC').toUpperCase(),
    // Input data encoding.
    encoding: options.encoding || null,
    // Permissive mode (ignore minor errors).
    permissive: options.permissive || false,
    // Template of the control field tag.
    controlFieldRegexp: options.controlFieldRegexp || /^00[1-9]$/
  }
}
757440
private static Map<String, String> readPrefixDeclaration(BufferedReader reader) throws IOException {
        Map<String, String> prefixes = new HashMap<>();
        String line;
        while (!(line = reader.readLine()).isEmpty()) {
            String[] tokens = line.split("[\t| ]+");
            prefixes.put(tokens[0], tokens[1]);
        }
        return prefixes;
    }
530704
public void init(Reader reader, Record record, SaxHtmlHandler handler)
    {
        m_handler = null;
        m_handler = handler;
        super.init(reader, record);
    }
1098469
public static Builder from(Reader swaggerReader) {
        Validate.notNull(swaggerReader, "swaggerReader must not be null");
        Swagger swagger;
        try {
            swagger = new SwaggerParser().parse(IOUtils.toString(swaggerReader));
        } catch (IOException e) {
            throw new RuntimeException("Swagger source can not be parsed", e);
        }
        if (swagger == null)
            throw new IllegalArgumentException("Swagger source is in a wrong format");

        return new Builder(swagger);
    }
1060630
@Override
    public synchronized void registerReader(ReadMarker readMarker, MessageReader... reader) {
        Preconditions.checkArgument(reader!=null && reader.length>0,"Must specify at least one reader");
        registerReaders(readMarker,Arrays.asList(reader));
    }
1112794
private void scanOperator() {
        while (true) {
            reader.putChar(false);
            Name newname = reader.name();
            TokenKind tk1 = tokens.lookupKind(newname);
            if (tk1 == TokenKind.IDENTIFIER) {
                reader.sp--;
                break;
            }
            tk = tk1;
            reader.scanChar();
            if (!isSpecial(reader.ch)) break;
        }
    }
620723
function(first) {
        var reader  = this._reader,
            url     = first || "",
            c;

        for (c = reader.peek(); c; c = reader.peek()) {
            // Note that the grammar at
            // https://www.w3.org/TR/CSS2/grammar.html#scanner
            // incorrectly includes the backslash character in the
            // `url` production, although it is correctly omitted in
            // the `baduri1` production.
            if (nonascii.test(c) || /^[\-!#$%&*-\[\]-~]$/.test(c)) {
                url += c;
                reader.read();
            } else if (c === "\\") {
                if (/^[^\r\n\f]$/.test(reader.peek(2))) {
                    url += this.readEscape(reader.read(), true);
                } else {
                    break; // bad escape sequence.
                }
            } else {
                break; // bad character
            }
        }

        return url;
    }
96246
public static void generateSource(Reader reader, File sourceOutputPath) throws IOException {
        ProtoFile protoFile = ProtoSchemaParser.parse(DEFAULT_FILE_NAME, reader);
        List<CodeDependent> cds = new ArrayList<CodeDependent>();
        doCreate(protoFile, true, false, null, true, sourceOutputPath, cds, new HashMap<String, String>(), false);
    }
237344
@Override
  public MtasTokenCollection createTokenCollection(Reader reader)
      throws MtasParserException, MtasConfigException {
    AtomicInteger position = new AtomicInteger(0);
    MtasCRMAncestors unknownAncestors = new MtasCRMAncestors();

    Map<String, Set<Integer>> idPositions = new HashMap<>();
    Map<String, Integer[]> idOffsets = new HashMap<>();

    Map<String, Map<Integer, Set<String>>> updateList = createUpdateList();
    Map<String, List<MtasParserObject>> currentList = createCurrentList();

    tokenCollection = new MtasTokenCollection();
    MtasTokenIdFactory mtasTokenIdFactory = new MtasTokenIdFactory();
    try (MtasBufferedReader br = new MtasBufferedReader(reader)) {
      String line;
      int currentOffset;
      int previousOffset = br.getPosition();
      MtasParserObject currentObject;
      Pattern headerPattern = Pattern.compile("^@ @ @(.*)$");
      Pattern regularPattern = Pattern.compile(
          "^([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+)$");
      Matcher matcherHeader;
      Matcher matcherRegular = null;
      Set<MtasParserObject> newPreviousSentence = new HashSet<>();
      Set<MtasParserObject> previousSentence = new HashSet<>();
      Set<MtasParserObject> newPreviousClause = new HashSet<>();
      Set<MtasParserObject> previousClause = new HashSet<>(); 
      String[] matcherList = new String[8];
      while ((line = br.readLine()) != null) {
        currentOffset = br.getPosition();
        matcherHeader = headerPattern.matcher(line.trim());
        matcherRegular = regularPattern.matcher(line.trim());
        if (matcherRegular.matches()) {
          newPreviousSentence.clear();
          matcherList = createMatcherList(matcherRegular); 
          for (int i = 4; i < 8; i++) {
            List<MtasCRMParserFunctionOutput> functionOutputList = new ArrayList<>();
            Set<MtasParserObject> tmpList = processCRMSentence(
                mtasTokenIdFactory, String.valueOf(i),
                matcherList[i], currentOffset,
                functionOutputList, unknownAncestors, currentList, updateList,
                idPositions, idOffsets, previousSentence, previousClause);
            if (tmpList != null) {
              newPreviousSentence.addAll(tmpList);
            }
            for (MtasCRMParserFunctionOutput functionOutput : functionOutputList) {
              tmpList = processCRMSentence(mtasTokenIdFactory,
                  functionOutput.name, functionOutput.value, currentOffset,
                  functionOutputList, unknownAncestors, currentList, updateList,
                  idPositions, idOffsets, previousSentence, previousClause);
              if (tmpList != null) {
                newPreviousSentence.addAll(tmpList);
              }
            }
          }
          if (!newPreviousSentence.isEmpty()) {
            previousSentence.clear();
            previousSentence.addAll(newPreviousSentence);
          }
          newPreviousClause.clear();
          for (int i = 4; i < 8; i++) {
            ArrayList<MtasCRMParserFunctionOutput> functionOutputList = new ArrayList<>();
            Set<MtasParserObject> tmpList = processCRMClause(mtasTokenIdFactory,
                String.valueOf(i), matcherList[i], currentOffset,
                functionOutputList, unknownAncestors, currentList, updateList,
                idPositions, idOffsets, previousClause);
            if (tmpList != null) {
              newPreviousClause.addAll(tmpList);
            }
            for (MtasCRMParserFunctionOutput functionOutput : functionOutputList) {
              tmpList = processCRMClause(mtasTokenIdFactory,
                  functionOutput.name, functionOutput.value, currentOffset,
                  functionOutputList, unknownAncestors, currentList, updateList,
                  idPositions, idOffsets, previousClause);
              if (tmpList != null) {
                newPreviousClause.addAll(tmpList);
              }
            }
          }
          if (!newPreviousClause.isEmpty()) {
            previousClause.clear();
            previousClause.addAll(newPreviousClause);
          }
        }

        if (matcherRegular.matches() && !matcherHeader.matches()) {
          matcherRegular = regularPattern.matcher(line.trim());
          if (matcherRegular.matches()) {
            // regular line - start word
            currentObject = new MtasParserObject(wordType);
            currentObject.setOffsetStart(previousOffset);
            currentObject.setRealOffsetStart(previousOffset);
            currentObject.setUnknownAncestorNumber(unknownAncestors.unknown);
            if (!prevalidateObject(currentObject, currentList)) {
              unknownAncestors.unknown++;
            } else {
              int p = position.getAndIncrement();
              currentObject.addPosition(p);
              currentObject.objectId = "word_" + p;
              currentList.get(MAPPING_TYPE_WORD).add(currentObject);
              unknownAncestors.unknown = 0;
              // check for crmPair
              for (int i = 0; i < 8; i++) {
                List<MtasCRMParserFunctionOutput> functionOutputList = new ArrayList<>();
                processCRMPair(mtasTokenIdFactory, p, String.valueOf(i),
                    matcherList[i], currentOffset,
                    functionOutputList, unknownAncestors, currentList,
                    updateList, idPositions, idOffsets);
                for (MtasCRMParserFunctionOutput functionOutput : functionOutputList) {
                  processCRMPair(mtasTokenIdFactory, p, functionOutput.name,
                      functionOutput.value, currentOffset, functionOutputList,
                      unknownAncestors, currentList, updateList, idPositions,
                      idOffsets);
                }
              }
              // compute word annotations
              for (int i = 0; i < 8; i++) {
                ArrayList<MtasCRMParserFunctionOutput> functionOutputList = new ArrayList<>();
                functionOutputList
                    .addAll(processWordAnnotation(mtasTokenIdFactory,
                        String.valueOf(i), matcherList[i],
                        previousOffset, currentOffset, unknownAncestors,
                        currentList, updateList, idPositions, idOffsets));
                for (MtasCRMParserFunctionOutput functionOutput : functionOutputList) {
                  processWordAnnotation(mtasTokenIdFactory, functionOutput.name,
                      functionOutput.value, previousOffset, currentOffset,
                      unknownAncestors, currentList, updateList, idPositions,
                      idOffsets);
                }
              }
            }
            // finish word
            if (unknownAncestors.unknown > 0) {
              unknownAncestors.unknown--;
            } else {
              currentObject = currentList.get(MAPPING_TYPE_WORD)
                  .remove(currentList.get(MAPPING_TYPE_WORD).size() - 1);
              assert unknownAncestors.unknown == 0 : "error in administration "
                  + currentObject.getType().getName();
              currentObject.setText(null);
              currentObject.setOffsetEnd(currentOffset - 1);
              currentObject.setRealOffsetEnd(currentOffset - 1);
              // update ancestor groups with position and offset
              for (MtasParserObject currentGroup : currentList
                  .get(MAPPING_TYPE_GROUP)) {
                currentGroup.addPositions(currentObject.getPositions());
                currentGroup.addOffsetStart(currentObject.getOffsetStart());
                currentGroup.addOffsetEnd(currentObject.getOffsetEnd());
              }
              idPositions.put(currentObject.getId(),
                  currentObject.getPositions());
              idOffsets.put(currentObject.getId(), currentObject.getOffset());
              currentObject.updateMappings(idPositions, idOffsets);
              unknownAncestors.unknown = currentObject
                  .getUnknownAncestorNumber();
              computeMappingsFromObject(mtasTokenIdFactory, currentObject,
                  currentList, updateList);
            }

          } else {
            // System.out.println("PROBLEM: " + line);
          }
        }
        previousOffset = br.getPosition();
      }
      closePrevious(mtasTokenIdFactory, previousSentence, previousOffset,
          unknownAncestors, currentList, updateList, idPositions, idOffsets);
      closePrevious(mtasTokenIdFactory, previousClause, previousOffset,
          unknownAncestors, currentList, updateList, idPositions, idOffsets);
    } catch (IOException e) {
      log.debug(e);
      throw new MtasParserException(e.getMessage());
    }
    // final check
    tokenCollection.check(autorepair, makeunique);
    return tokenCollection;

  }
425576
public Reader createReader(byte[] cachedBytes) throws IOException {
	if (cachedBytes != null) {
	    return new InputStreamReader(new ByteArrayInputStream(cachedBytes));
	}
        if (inputStream != null) {
            return new InputStreamReader(inputStream, charset);
        }
        if (reader != null) {
            return reader;
        }
        return new InputStreamReader(new FileInputStream(file), charset);
    }
1065310
public ISimpleChemObjectReader createReader(Reader input) throws IOException {
        if (!(input instanceof BufferedReader)) {
            input = new BufferedReader(input);
        }
        IChemFormat chemFormat = formatFactory.guessFormat((BufferedReader) input);
        ISimpleChemObjectReader coReader = createReader(chemFormat);
        try {
            coReader.setReader(input);
        } catch (Exception exception) {
            logger.error("Could not set the Reader source: ", exception.getMessage());
            logger.debug(exception);
        }
        return coReader;
    }
1002299
function() {

        var c,
            reader = this._reader,
            token   = null,
            startLine   = reader.getLine(),
            startCol    = reader.getCol(),
            start       = reader.getCursor(); //ORION AST Generation

        c = reader.read();


        while (c) {
            switch (c) {

                /*
                 * Potential tokens:
                 * - COMMENT
                 * - SLASH
                 * - CHAR
                 */
                case "/":

                    if (reader.peek() === "*") {
                        token = this.commentToken(c, startLine, startCol);
                    } else {
                        token = this.charToken(c, startLine, startCol);
                    }
                    break;

                /*
                 * Potential tokens:
                 * - DASHMATCH
                 * - INCLUDES
                 * - PREFIXMATCH
                 * - SUFFIXMATCH
                 * - SUBSTRINGMATCH
                 * - CHAR
                 */
                case "|":
                case "~":
                case "^":
                case "$":
                case "*":
                    if (reader.peek() === "=") {
                        token = this.comparisonToken(c, startLine, startCol);
                    } else {
                        token = this.charToken(c, startLine, startCol);
                    }
                    break;

                /*
                 * Potential tokens:
                 * - STRING
                 * - INVALID
                 */
                case "\"":
                case "'":
                    token = this.stringToken(c, startLine, startCol);
                    break;

                /*
                 * Potential tokens:
                 * - HASH
                 * - CHAR
                 */
                case "#":
                    if (isNameChar(reader.peek())) {
                        token = this.hashToken(c, startLine, startCol);
                    } else {
                        token = this.charToken(c, startLine, startCol);
                    }
                    break;

                /*
                 * Potential tokens:
                 * - DOT
                 * - NUMBER
                 * - DIMENSION
                 * - PERCENTAGE
                 */
                case ".":
                    if (isDigit(reader.peek())) {
                        token = this.numberToken(c, startLine, startCol);
                    } else {
                        token = this.charToken(c, startLine, startCol);
                    }
                    break;

                /*
                 * Potential tokens:
                 * - CDC
                 * - MINUS
                 * - NUMBER
                 * - DIMENSION
                 * - PERCENTAGE
                 */
                case "-":
                    if (reader.peek() === "-") {  //could be closing HTML-style comment
                        token = this.htmlCommentEndToken(c, startLine, startCol);
                    } else if (isNameStart(reader.peek())) {
                        token = this.identOrFunctionToken(c, startLine, startCol);
                    } else {
                        token = this.charToken(c, startLine, startCol);
                    }
                    break;

                /*
                 * Potential tokens:
                 * - IMPORTANT_SYM
                 * - CHAR
                 */
                case "!":
                    token = this.importantToken(c, startLine, startCol);
                    break;

                /*
                 * Any at-keyword or CHAR
                 */
                case "@":
                    token = this.atRuleToken(c, startLine, startCol);
                    break;

                /*
                 * Potential tokens:
                 * - NOT
                 * - CHAR
                 */
                case ":":
                    token = this.notToken(c, startLine, startCol);
                    break;

                /*
                 * Potential tokens:
                 * - CDO
                 * - CHAR
                 */
                case "<":
                    token = this.htmlCommentStartToken(c, startLine, startCol);
                    break;

                /*
                 * Potential tokens:
                 * - IDENT
                 * - CHAR
                 */
                case "\\":
                    if (/[^\r\n\f]/.test(reader.peek())) {
                        token = this.identOrFunctionToken(this.readEscape(c, true), startLine, startCol);
                    } else {
                        token = this.charToken(c, startLine, startCol);
                    }
                    break;

                /*
                 * Potential tokens:
                 * - UNICODE_RANGE
                 * - URL
                 * - CHAR
                 */
                case "U":
                case "u":
                    if (reader.peek() === "+") {
                        token = this.unicodeRangeToken(c, startLine, startCol);
                        break;
                    }
                    /* falls through */
                default:

                    /*
                     * Potential tokens:
                     * - NUMBER
                     * - DIMENSION
                     * - LENGTH
                     * - FREQ
                     * - TIME
                     * - EMS
                     * - EXS
                     * - ANGLE
                     */
                    if (isDigit(c)) {
                        token = this.numberToken(c, startLine, startCol);
                    } else

                    /*
                     * Potential tokens:
                     * - S
                     */
                    if (isWhitespace(c)) {
                        token = this.whitespaceToken(c, startLine, startCol);
                    } else

                    /*
                     * Potential tokens:
                     * - IDENT
                     */
                    if (isIdentStart(c)) {
                        token = this.identOrFunctionToken(c, startLine, startCol);
                    } else {
                       /*
                        * Potential tokens:
                        * - CHAR
                        * - PLUS
                        */
                        token = this.charToken(c, startLine, startCol);
                    }

            }

            //make sure this token is wanted
            //TODO: check channel
            break;
        }

        if (!token && c === null) {
            token = this.createToken(Tokens.EOF, null, startLine, startCol);
        }
        
        // ORION Append list of tokens
        if(token.type !== Tokens.S) {
            var smalltoken = Object.create(null);
            smalltoken.type = Tokens.name(token.type);
            smalltoken.value = token.value;
            smalltoken.range = [start, reader.getCursor()];
            this.tokens.push(smalltoken);
        }

        return token;
    }
136714
function ( reader, version ) {

			var node = {};

			// The first three data sizes depends on version.
			var endOffset = ( version >= 7500 ) ? reader.getUint64() : reader.getUint32();
			var numProperties = ( version >= 7500 ) ? reader.getUint64() : reader.getUint32();

			// note: do not remove this even if you get a linter warning as it moves the buffer forward
			var propertyListLen = ( version >= 7500 ) ? reader.getUint64() : reader.getUint32();

			var nameLen = reader.getUint8();
			var name = reader.getString( nameLen );

			// Regards this node as NULL-record if endOffset is zero
			if ( endOffset === 0 ) return null;

			var propertyList = [];

			for ( var i = 0; i < numProperties; i ++ ) {

				propertyList.push( this.parseProperty( reader ) );

			}

			// Regards the first three elements in propertyList as id, attrName, and attrType
			var id = propertyList.length > 0 ? propertyList[ 0 ] : '';
			var attrName = propertyList.length > 1 ? propertyList[ 1 ] : '';
			var attrType = propertyList.length > 2 ? propertyList[ 2 ] : '';

			// check if this node represents just a single property
			// like (name, 0) set or (name2, [0, 1, 2]) set of {name: 0, name2: [0, 1, 2]}
			node.singleProperty = ( numProperties === 1 && reader.getOffset() === endOffset ) ? true : false;

			while ( endOffset > reader.getOffset() ) {

				var subNode = this.parseNode( reader, version );

				if ( subNode !== null ) this.parseSubNode( name, node, subNode );

			}

			node.propertyList = propertyList; // raw property list used by parent

			if ( typeof id === 'number' ) node.id = id;
			if ( attrName !== '' ) node.attrName = attrName;
			if ( attrType !== '' ) node.attrType = attrType;
			if ( name !== '' ) node.name = name;

			return node;

		}
555758
function Reader(data, ctors) {
        if (!_.isObject(data)) {
            console.error("Reader constructor: 'data' parameter should be JSON object");
            return;
        }
        this.data = data;
        this.ctors = ctors;
        this.current = this.data;
        this.idMap = {};
    }
75401
protected function initializeReader()
    {
        $this->reader = phpiredis_reader_create();

        phpiredis_reader_set_status_handler($this->reader, $this->getStatusHandler());
        phpiredis_reader_set_error_handler($this->reader, $this->getErrorHandler());
    }
334190
function initializeParser(document, debug) {
    const chars = new antlr.InputStream(document);
    const lexer = new grammar.DocumentLexer(chars);
    const listener = new CustomErrorListener(debug);
    lexer.removeErrorListeners();
    lexer.addErrorListener(listener);
    const tokens = new antlr.CommonTokenStream(lexer);
    const parser = new grammar.DocumentParser(tokens);
    parser.buildParseTrees = true;
    parser.removeErrorListeners();
    parser.addErrorListener(listener);
    parser._errHandler = new CustomErrorStrategy();
    return parser;
}
1013521
public static BufferedReader getReader(Reader reader) {
		if (null == reader) {
			return null;
		}

		return (reader instanceof BufferedReader) ? (BufferedReader) reader : new BufferedReader(reader);
	}