Parse a TXT dataset from an input stream.
@param name the name of dataset.
@param stream the input stream of data.
@throws java.io.IOException
342351
public AttributeDataset parse(String name, InputStream stream) throws IOException, ParseException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(stream));

        String line = reader.readLine();
        if (line == null) {
            throw new IOException("Empty data source.");
        }

        String[] tokens = line.split("\t", -1);
        int start = 1;
        int p = tokens.length - 1;
        if (tokens[1].equalsIgnoreCase("description")) {
            start = 2;
            p = tokens.length - 2;
        }

        Attribute[] attributes = new Attribute[p];
        for (int i = 0; i < p; i++) {
            attributes[i] = new NumericAttribute(tokens[i+start]);
        }
        
        AttributeDataset data = new AttributeDataset(name, attributes);
        
        for (int i = 2; (line = reader.readLine()) != null; i++) {
            tokens = line.split("\t", -1);
            if (tokens.length != p+start) {
                throw new IOException(String.format("Invalid number of elements of line %d: %d", i, tokens.length));
            }

            double[] x = new double[p];
            for (int j = 0; j < p; j++) {
                if (tokens[j+start].isEmpty()) {
                    x[j] = Double.NaN;
                } else {
                    x[j] = Double.valueOf(tokens[j+start]);
                }
            }

            AttributeDataset.Row datum = data.add(x);
            datum.name = tokens[0];
            if (start == 2) {
                datum.description = tokens[1];
            }
        }
        
        reader.close();
        return data;
    }
187526
protected function parseProperty(TokenStream $stream, $visibility, $name)
    {
        switch ($visibility->getValue()) {
            case '+':
                $this->nodes[] = new Node(self::NODE_PUBLIC_PROPERTY, $name->getValue());
                break;
            case '#':
                $this->nodes[] = new Node(self::NODE_PROTECTED_PROPERTY, $name->getValue());
                break;
            case '-':
                $this->nodes[] = new Node(self::NODE_PRIVATE_PROPERTY, $name->getValue());
                break;
        }
        if ($this->skip($stream)->is(Lexer::TOKEN_TYPE)) {
            $stream->next();
            $token = $this->skip($stream)->expect(Lexer::TOKEN_NODE);
            $this->nodes[] = new Node(self::NODE_PROPERTY_TYPE, $token->getValue());
        }

        if ($this->skip($stream)->is(Lexer::TOKEN_BRCO)) {
            $stream->next();
            while (!$this->skip($stream)->is(Lexer::TOKEN_BRCC)) {
                if ($this->skip($stream)->is(array(Lexer::TOKEN_PUBL, Lexer::TOKEN_PROT, Lexer::TOKEN_PRIV))) {
                    throw new \Exception('Unexpected token: ' . $stream->current()->getType());
                }

                $token = $stream->skipType(array(Lexer::TOKEN_EOL, Lexer::TOKEN_WTSP))->expect(Lexer::TOKEN_NODE);
                $this->nodes[] = new Node(self::NODE_ACCESSOR, $token->getValue());
            }
            $stream->next();
        }

        $this->parseComment($stream, self::NODE_PROPERTY_COMMENT);
    }
479105
private void parse(TokenStream tokenStream) throws ParserException {
	try {
	    Parser parser = new SLR1Parser(uhuraGrammar);
	    parserTree = parser.parse(tokenStream);
	} catch (GrammarException e) {
	    logger.error(e.getMessage(), e);
	    throw new RuntimeException("UhuraGrammar is broken!!!");
	}
    }
1120853
public static String parseString(InputStream inputStream, final int size) throws IOException {
        if (0 == size) {
            return "";
        }

        byte[] buffer = new byte[size];
        int numberOfReadsBytes = inputStream.read(buffer, 0, size);
        assert numberOfReadsBytes == size;

        return new String(buffer, "UTF-8");
    }
73522
private void parse(String fileName) throws IOException, SAXException {
        FileInputStream fileInputStream = new FileInputStream(new File(fileName));
        parse(fileName, fileInputStream);
    }
439780
public static InputStream readResource(String name) {
        String classpath = System.getProperty("java.class.path");
        LOGGER.trace("Reading {} from classpath={}", name, classpath);
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        if (classLoader == null) {
            throw new IllegalStateException("Can not obtain classloader instance from current thread");
        }
        return classLoader.getResourceAsStream(name);
    }
991395
private void readObject(ObjectInputStream stream)
        throws IOException, ClassNotFoundException {
        stream.defaultReadObject();
        int capitalizationSettingValue = (serialVersionOnStream > 1)? stream.readInt(): -1;
        ///CLOVER:OFF
        // don't have old serial data to test with
        if (serialVersionOnStream < 1) {
            // didn't have defaultCenturyStart field
            defaultCenturyBase = System.currentTimeMillis();
        }
        ///CLOVER:ON
        else {
            // fill in dependent transient field
            parseAmbiguousDatesAsAfter(defaultCenturyStart);
        }
        serialVersionOnStream = currentSerialVersion;
        locale = getLocale(ULocale.VALID_LOCALE);
        if (locale == null) {
            // ICU4J 3.6 or older versions did not have UFormat locales
            // in the serialized data. This is just for preventing the
            // worst case scenario...
            locale = ULocale.getDefault(Category.FORMAT);
        }

        initLocalZeroPaddingNumberFormat();

        setContext(DisplayContext.CAPITALIZATION_NONE);
        if (capitalizationSettingValue >= 0) {
            for (DisplayContext context: DisplayContext.values()) {
                if (context.value() == capitalizationSettingValue) {
                    setContext(context);
                    break;
                }
            }
        }

        // if serialized pre-56 update & turned off partial match switch to new enum value
        if(getBooleanAttribute(DateFormat.BooleanAttribute.PARSE_PARTIAL_MATCH) == false) {
            setBooleanAttribute(DateFormat.BooleanAttribute.PARSE_PARTIAL_LITERAL_MATCH, false);
        }

        parsePattern();
    }
638733
public void readObject(@NonNull ObjectInputStream stream) throws IOException, ClassNotFoundException {
        id = (String)stream.readObject();
        createdTime = stream.readLong();
        lastAccessedTime = stream.readLong();
        maxInactiveInterval = stream.readInt();
        isNew = stream.readBoolean();
        isValid = stream.readBoolean();

        // Deserialize the attribute count and attribute values
        int size = stream.readInt();
        for (int i = 0; i < size; i++) {
            String name = (String)stream.readObject();
            Object value = stream.readObject();
            mAttributes.put(name, value);
        }
    }
1370490
public static InputStream decode(DataBinder binder, InputStream stream) throws ParserConfigurationException, SAXException, IOException {
        XML.newSAXParser().parse(stream, new XDBHandler(binder));
        return stream;
    }
130768
public static String readFile( String name ) throws IOException {
        StringBuilder b = new StringBuilder();
        BufferedReader r = new BufferedReader(new FileReader(name));
        String line;
        while( (line = r.readLine()) != null ) {
            b.append(line).append('\n');
        }
        r.close();
        return b.toString();
    }
1166668
public BinarySparseDataset parse(String name, URI uri) throws IOException, ParseException {
        return parse(name, new File(uri));
    }
644617
public BinarySparseDataset parse(String name, String path) throws IOException, ParseException {
        return parse(name, new File(path));
    }
1231412
public static ResourceRecordSet<TXTData> txt(String name, Collection<String> txtdata) {
    return new TXTBuilder().name(name).addAll(txtdata).build();
  }
1262956
public List<String[]> parse(InputStream stream) throws IOException
    {
        int columnCount = -1;
        List<String[]> lines = new ArrayList<String[]>();
        rows.clear();

        // Excel spreadsheet
        if(CommonFiles.isExcelFile(name))
        {
            if(worksheet != null && worksheet.length() > 0)
            {
                SimpleDateFormat df = new SimpleDateFormat(Formats.DATETIME_FORMAT);
                df.setTimeZone(TimeZone.getTimeZone("GMT"));

                Workbook workbook = Workbook.getWorkbook(name, stream);
                Worksheet sheet = workbook.getSheet(worksheet);
                if(sheet != null)
                {
                    columnCount = sheet.getColumns();
                    for(int i = 0; i < sheet.getRows(); i++)
                    {
                        String[] values = sheet.getRow(i, df);
                        if(values != null)
                            lines.add(values);
                    }
                }
                else
                {
                    throw new IllegalStateException("Worksheet '"+worksheet+"' not found");
                }

                workbook.close();
            }
            else
            {
                throw new IllegalArgumentException("Worksheet not specified");
            }
        }
        else if(CommonFiles.isCsvFile(name))
        {
            Reader reader = new InputStreamReader(stream);
            CSVReader csv = new CSVReader(reader, delimiter.separator().charAt(0));
            String [] line;
            while ((line = csv.readNext()) != null) 
            {
                if(columnCount == -1)
                    columnCount = line.length;
                lines.add(line);
            }
            reader.close();
        }

        int lineCount = lines.size();

        logger.fine("InputFileReader.parse: lines="+lineCount+" columns="+columnCount);

        // Error if the file is empty
        if(lineCount <= 0 || columnCount == 0)
            throw new IllegalStateException("input file does not contain any data");

        // Parse the file headers and rows
        int count = 0;
        for(String[] line : lines)
        {
            // Ignore the line if there is no data
            if(isBlankRow(line))
                continue;

            String[] row = new String[columnCount];  // the row of data

            for(int column = 0; column < columnCount; column++)
            {

                // Check that the row column count matches the header column count
                if(column >= line.length)
                {
                    if(line.length > 0 && isCompleteLine(line))
                        break;
                    else
                        throw new IllegalStateException("Row "+count+" has more columns than the header row");
                }

                // The first row gives the column headers
                if(count == 0)
                {
                    try
                    {
                        row[column] = line[column].trim();
                    }
                    catch(NoSuchElementException e)
                    {
                        row[column] = "";
                    }
                }
                else // The subsequent rows give the actual data
                {
                    try
                    {
                        String token = line[column];

                        // Remove quotes
                        if(removeQuotes && token.startsWith("\""))
                        {
                            token = token.substring(1);
                            if(token.endsWith("\""))
                                token = token.substring(0,token.length()-1);

                            // Replace all other double quotes with a single quote
                            token = token.replaceAll("\"\"", "\"");
                        }

                        // Trim the value (if required)
                        if(trim)
                            token.trim();

                        // Put the processed token in the array
                        row[column] = token;
                        logger.fine("InputFileReader.parse: row["+count+","+headers[column]+"]="+token);
                    }
                    catch(NoSuchElementException e)
                    {
                        row[column] = "";
                    }
                }
            }

            if(count == 0)
                headers = row;
            else
                rows.add(row);
            ++count;
        }

        return rows;
    }
1296657
private static List<Map<String, String>> loadWords(InputStream stream) {
    List<Map<String, String>> list = new ArrayList<>();
    try (
      InputStreamReader isr = new InputStreamReader(stream, FILE_ENCODING);
      BufferedReader br = new BufferedReader(isr);
    ) {
      String line;

      Tokenizer wordTokenizer = new Breton().getWordTokenizer();
      while ((line = br.readLine()) != null) {
        line = line.trim();
        if (line.isEmpty() || line.charAt(0) == '#') { // ignore comments
          continue;
        }
        String[] parts = line.split("=");
        if (parts.length != 2) {
          throw new IOException("Format error in file "
                  + JLanguageTool.getDataBroker().getFromRulesDirAsUrl(FILE_NAME)
                  + ", line: " + line);
        }
        String[] wrongForms = parts[0].split("\\|"); // multiple incorrect forms
        for (String wrongForm : wrongForms) {
          int wordCount = 0;
          List<String> tokens = wordTokenizer.tokenize(wrongForm);
          for (String token : tokens) {
            if (!StringTools.isWhitespace(token)) {
              wordCount++;
            }
          }
          // grow if necessary
          for (int i = list.size(); i < wordCount; i++) {
            list.add(new HashMap<>());
          }
          list.get(wordCount - 1).put(wrongForm, parts[1]);
        }
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    // seal the result (prevent modification from outside this class)
    List<Map<String,String>> result = new ArrayList<>();
    for (Map<String, String> map : list) {
      result.add(Collections.unmodifiableMap(map));
    }
    return Collections.unmodifiableList(result);
  }
171803
public <T> T parse(InputStream in, Class<T> mapTo) throws ParseException, UnsupportedEncodingException {
		return getPBinStream().parse(in, JSONValue.defaultReader.getMapper(mapTo));
	}
1060943
private void copyToStream(String txt, OutputStream stream) throws IOException {
        if (txt != null) {
            stream.write(txt.getBytes());
        }
    }