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);
}
}
}
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();
}
}
}
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);
}
}
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();
}
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();
}
Aggregations