/* default */ static CharStream getCharStreamFromSourceCode(final SourceCode sourceCode) { StringBuilder buffer = sourceCode.getCodeBuffer(); return CharStreams.fromString(buffer.toString()); } }
/** {@inheritDoc} */ @Override public XGModelComposition parse(byte[] mdl) { try (ByteArrayInputStream bais = new ByteArrayInputStream(mdl)) { CharStream cStream = CharStreams.fromStream(bais); XGBoostModelLexer lexer = new XGBoostModelLexer(cStream); CommonTokenStream tokens = new CommonTokenStream(lexer); XGBoostModelParser parser = new XGBoostModelParser(tokens); XGModelVisitor visitor = new XGModelVisitor(); return visitor.visit(parser.xgModel()); } catch (IOException e) { throw new RuntimeException(e); } } }
/** * Creates a {@link CharStream} given a {@link Reader}. Closes * the reader before returning. */ public static CodePointCharStream fromReader(Reader r) throws IOException { return fromReader(r, IntStream.UNKNOWN_SOURCE_NAME); }
if (this.override == null) { try { stream = CharStreams.fromFileName(getFilename()); } catch (InvalidPathException e) { throw new IOException(e); stream = CharStreams.fromString(this.override, getFilename());
CharStream charStream = CharStreams.fromStream(System.in, charset); process(lexer, parserClass, parser, charStream); return; CharStream charStream = CharStreams.fromPath(Paths.get(inputFile), charset); if ( inputFiles.size()>1 ) { System.err.println(inputFile);
CharStream charStream = CharStreams.fromStream(System.in, charset); process(lexer, parserClass, parser, charStream); return; CharStream charStream = CharStreams.fromFile(new File(inputFile), charset); if ( inputFiles.size()>1 ) { System.err.println(inputFile);
public List<DocItem> collect(Path file) throws IOException { this.file = file; doc = new ArrayList<>(); CharStream input = CharStreams.fromPath(file, StandardCharsets.UTF_8); FuzzyDocLexer lexer = new FuzzyDocLexer(input); ANTLRErrorListener error = errorListener(LoggerFactory.getLogger(DocCollector.class), file); lexer.removeErrorListeners(); lexer.addErrorListener(error); TokenStream tokens = new CommonTokenStream(lexer); FuzzyDocParser parser = new FuzzyDocParser(tokens); parser.removeErrorListeners(); parser.addErrorListener(error); ParseTreeWalker.DEFAULT.walk(this, parser.source()); return doc; }
/** * Creates a {@link CharStream} given a string containing a * path to a UTF-8 file on disk. * * Reads the entire contents of the file into the result before returning. */ public static CharStream fromFileName(String fileName) throws IOException { return fromFileName(fileName, Charset.forName("UTF-8")); }
CharStream charStream = CharStreams.fromStream(System.in, charset); process(lexer, parserClass, parser, charStream); return; CharStream charStream = CharStreams.fromPath(Paths.get(inputFile), charset); if ( inputFiles.size()>1 ) { System.err.println(inputFile);
/** * Creates a {@link CharStream} given a path to a UTF-8 * encoded file on disk. * * Reads the entire contents of the file into the result before returning. */ public static CharStream fromPath(Path path) throws IOException { return fromPath(path, StandardCharsets.UTF_8); }
/** * parse the given input File with the given encoding * * @param inputFile * @param encoding * @return - the parse Tree * @throws IOException */ public ParseTree parse(File inputFile, String encoding) throws Exception { this.setSourceFileName(inputFile.getPath()); in = CharStreams.fromFileName(sourceFileName); inputText = FileUtils.readFileToString(inputFile, encoding); ParseTree result = parse(in, inputText); return result; }
private static Lexer createLexer(final DatabaseType databaseType, final String sql) { CharStream sqlCharStream = CharStreams.fromString(sql); switch (databaseType) { case H2: case MySQL: return new MySQLStatementLexer(sqlCharStream); case PostgreSQL: return new PostgreSQLStatementLexer(sqlCharStream); case SQLServer: return new SQLServerStatementLexer(sqlCharStream); case Oracle: return new OracleStatementLexer(sqlCharStream); default: throw new UnsupportedOperationException(String.format("Can not support database type [%s].", databaseType)); } }
/** * Creates a {@link CharStream} given an opened {@link InputStream} * containing UTF-8 bytes. * * Reads the entire contents of the {@code InputStream} into * the result before returning, then closes the {@code InputStream}. */ public static CharStream fromStream(InputStream is) throws IOException { return fromStream(is, StandardCharsets.UTF_8); }
/** * Creates a {@link CharStream} given a {@link Reader}. Closes * the reader before returning. */ public static CodePointCharStream fromReader(Reader r) throws IOException { return fromReader(r, IntStream.UNKNOWN_SOURCE_NAME); }
/** * Creates a {@link CharStream} given a string containing a * path to a UTF-8 file on disk. * * Reads the entire contents of the file into the result before returning. */ public static CharStream fromFileName(String fileName) throws IOException { return fromPath(Paths.get(fileName), StandardCharsets.UTF_8); }
public static Properties parse(String fileName) throws IOException, ConfigException { Configuration conf = new Configuration(); return conf.runparsing(CharStreams.fromFileName(fileName)); }
return new LinkedHashMap<>(); CharStream input = CharStreams.fromString(text); StatusCodeLexer lexer = new StatusCodeLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer);
/** * Creates a {@link CharStream} given an opened {@link InputStream} and the * charset of the bytes contained in the stream. * * Reads the entire contents of the {@code InputStream} into * the result before returning, then closes the {@code InputStream}. */ public static CharStream fromStream(InputStream is, Charset charset) throws IOException { return fromStream(is, charset, -1); }
/** * Creates a {@link CharStream} given a {@link Reader}. Closes * the reader before returning. */ public static CodePointCharStream fromReader(Reader r) throws IOException { return fromReader(r, IntStream.UNKNOWN_SOURCE_NAME); }
/** * Creates a {@link CharStream} given a string containing a * path to a file on disk and the charset of the bytes * contained in the file. * * Reads the entire contents of the file into the result before returning. */ public static CharStream fromFileName(String fileName, Charset charset) throws IOException { return fromPath(Paths.get(fileName), charset); }