Search in sources :

Example 26 with Reader

use of java.io.Reader in project checkstyle by checkstyle.

the class AbstractHeaderCheck method setHeader.

/**
     * Set the header to check against. Individual lines in the header
     * must be separated by '\n' characters.
     * @param header header content to check against.
     * @throws IllegalArgumentException if the header cannot be interpreted
     */
public void setHeader(String header) {
    if (!CommonUtils.isBlank(header)) {
        checkHeaderNotInitialized();
        final String headerExpandedNewLines = ESCAPED_LINE_FEED_PATTERN.matcher(header).replaceAll("\n");
        final Reader headerReader = new StringReader(headerExpandedNewLines);
        try {
            loadHeader(headerReader);
        } catch (final IOException ex) {
            throw new IllegalArgumentException("unable to load header", ex);
        } finally {
            Closeables.closeQuietly(headerReader);
        }
    }
}
Also used : StringReader(java.io.StringReader) LineNumberReader(java.io.LineNumberReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) IOException(java.io.IOException)

Example 27 with Reader

use of java.io.Reader in project cucumber-jvm by cucumber.

the class RuntimeOptions method loadUsageTextIfNeeded.

static void loadUsageTextIfNeeded() {
    if (usageText == null) {
        try {
            Reader reader = new InputStreamReader(FixJava.class.getResourceAsStream(USAGE_RESOURCE), "UTF-8");
            usageText = FixJava.readReader(reader);
        } catch (Exception e) {
            usageText = "Could not load usage text: " + e.toString();
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) FixJava(gherkin.util.FixJava) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader)

Example 28 with Reader

use of java.io.Reader in project cogtool by cogtool.

the class BalsamiqButtonAPIConverter method parseBalsamiqFile.

/** Helper function used by importDesign.
	 * This method is used to parse the tags of each .bmml file in the 
	 * directory. The file represents a {@link File} in the directory.
     * 
     * @param  inputFile the specified directory or file
     * @see              the new design in the project window.
     */
public void parseBalsamiqFile(File inputFile) throws IOException {
    String fileName = inputFile.getName();
    int lastIndex = fileName.lastIndexOf(".");
    fileName = (lastIndex == -1) ? fileName : fileName.substring(0, lastIndex);
    /* Check to make sure that this frame has not been created yet. Cycles 
		 * by transitions may exist in the design and these files do not need 
		 * to be parsed more than once. */
    if (!visitedFramesNames.contains(fileName)) {
        visitedFramesNames.add(fileName);
        // Create a Xerces DOM Parser. A DOM Parser can parse an XML file
        // and create a tree representation of it. This same parser method
        // is used in ImportCogTool.java to import from CogTool XML.
        DOMParser parser = new DOMParser();
        InputStream fis = new FileInputStream(inputFile);
        Reader input = new InputStreamReader(fis, "UTF-8");
        // Parse the Document and traverse the DOM
        try {
            parser.parse(new InputSource(input));
        } catch (SAXException e) {
            throw new RcvrImportException("Not a valid XML file to parse.");
        }
        //Traverse the xml tags in the tree beginning at the root, the document
        Document document = parser.getDocument();
        parseFrame(document, fileName);
    }
}
Also used : InputSource(org.xml.sax.InputSource) InputStreamReader(java.io.InputStreamReader) RcvrImportException(edu.cmu.cs.hcii.cogtool.util.RcvrImportException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) DOMParser(com.sun.org.apache.xerces.internal.parsers.DOMParser) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException)

Example 29 with Reader

use of java.io.Reader in project cryptomator by cryptomator.

the class WelcomeController method checkForUpdates.

private void checkForUpdates() {
    checkForUpdatesStatus.setText(localization.getString("welcome.checkForUpdates.label.currentlyChecking"));
    checkForUpdatesIndicator.setVisible(true);
    asyncTaskService.asyncTaskOf(() -> {
        RequestConfig requestConfig = //
        RequestConfig.custom().setConnectTimeout(//
        5000).setConnectionRequestTimeout(//
        5000).setSocketTimeout(//
        5000).build();
        HttpClientBuilder httpClientBuilder = //
        HttpClients.custom().disableCookieManagement().setDefaultRequestConfig(//
        requestConfig).setUserAgent("Cryptomator VersionChecker/" + ApplicationVersion.orElse("SNAPSHOT"));
        LOG.debug("Checking for updates...");
        try (CloseableHttpClient client = httpClientBuilder.build()) {
            HttpGet request = new HttpGet("https://cryptomator.org/downloads/latestVersion.json");
            try (CloseableHttpResponse response = client.execute(request)) {
                if (response.getStatusLine().getStatusCode() == 200 && response.getEntity() != null) {
                    try (InputStream in = response.getEntity().getContent()) {
                        Gson gson = new GsonBuilder().setLenient().create();
                        Reader utf8Reader = new InputStreamReader(in, StandardCharsets.UTF_8);
                        Map<String, String> map = gson.fromJson(utf8Reader, new TypeToken<Map<String, String>>() {
                        }.getType());
                        if (map != null) {
                            this.compareVersions(map);
                        }
                    }
                }
            }
        }
    }).andFinally(() -> {
        checkForUpdatesStatus.setText("");
        checkForUpdatesIndicator.setVisible(false);
    }).run();
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) InputStreamReader(java.io.InputStreamReader) GsonBuilder(com.google.gson.GsonBuilder) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) Gson(com.google.gson.Gson) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) TypeToken(com.google.gson.reflect.TypeToken) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 30 with Reader

use of java.io.Reader in project checkstyle by checkstyle.

the class TreeWalker method parse.

/**
     * Static helper method to parses a Java source file.
     *
     * @param contents
     *                contains the contents of the file
     * @return the root of the AST
     * @throws TokenStreamException
     *                 if lexing failed
     * @throws RecognitionException
     *                 if parsing failed
     */
public static DetailAST parse(FileContents contents) throws RecognitionException, TokenStreamException {
    final String fullText = contents.getText().getFullText().toString();
    final Reader reader = new StringReader(fullText);
    final GeneratedJavaLexer lexer = new GeneratedJavaLexer(reader);
    lexer.setFilename(contents.getFileName());
    lexer.setCommentListener(contents);
    lexer.setTreatAssertAsKeyword(true);
    lexer.setTreatEnumAsKeyword(true);
    lexer.setTokenObjectClass("antlr.CommonHiddenStreamToken");
    final TokenStreamHiddenTokenFilter filter = new TokenStreamHiddenTokenFilter(lexer);
    filter.hide(TokenTypes.SINGLE_LINE_COMMENT);
    filter.hide(TokenTypes.BLOCK_COMMENT_BEGIN);
    final GeneratedJavaRecognizer parser = new GeneratedJavaRecognizer(filter);
    parser.setFilename(contents.getFileName());
    parser.setASTNodeClass(DetailAST.class.getName());
    parser.compilationUnit();
    return (DetailAST) parser.getAST();
}
Also used : GeneratedJavaRecognizer(com.puppycrawl.tools.checkstyle.grammars.GeneratedJavaRecognizer) GeneratedJavaLexer(com.puppycrawl.tools.checkstyle.grammars.GeneratedJavaLexer) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) TokenStreamHiddenTokenFilter(antlr.TokenStreamHiddenTokenFilter)

Aggregations

Reader (java.io.Reader)1498 InputStreamReader (java.io.InputStreamReader)526 StringReader (java.io.StringReader)498 IOException (java.io.IOException)348 BufferedReader (java.io.BufferedReader)242 InputStream (java.io.InputStream)219 TokenStream (org.apache.lucene.analysis.TokenStream)171 Test (org.junit.Test)170 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)159 Connection (java.sql.Connection)137 ScriptRunner (org.apache.ibatis.jdbc.ScriptRunner)126 FileReader (java.io.FileReader)108 FileInputStream (java.io.FileInputStream)107 File (java.io.File)105 BeforeClass (org.junit.BeforeClass)99 Tokenizer (org.apache.lucene.analysis.Tokenizer)91 SqlSession (org.apache.ibatis.session.SqlSession)83 StringWriter (java.io.StringWriter)81 ArrayList (java.util.ArrayList)77 Writer (java.io.Writer)63