List of usage examples for java.nio.file Files newBufferedReader
public static BufferedReader newBufferedReader(Path path, Charset cs) throws IOException
From source file:com.wealdtech.configuration.ConfigurationSource.java
private static BufferedReader getReader(final String filename) { final URL fileurl = ResourceLoader.getResource(filename); if (fileurl == null) { return null; }/*w ww . j av a 2 s. c o m*/ try { return Files.newBufferedReader(Paths.get(fileurl.toURI()), Charset.defaultCharset()); } catch (IOException ioe) { LOGGER.warn("IO exception with {}: {}", fileurl, ioe); throw new DataError("Failed to access configuration file \"" + filename + "\"", ioe); } catch (URISyntaxException use) { LOGGER.warn("URI issue with {}: {}", fileurl, use); throw new DataError("Failed to access configuration file \"" + filename + "\"", use); } }
From source file:br.com.riselabs.cotonet.util.IOHandler.java
public List<String> readFile(Path filePath) { Charset charset = Charset.forName("US-ASCII"); List<String> urls = null; try (BufferedReader reader = Files.newBufferedReader(filePath, charset)) { String line = null;//from w w w .ja v a2 s . c om urls = new ArrayList<String>(); while ((line = reader.readLine()) != null) { urls.add(line); } } catch (IOException x) { System.err.format("IOException: %s%n", x); } return urls; }
From source file:org.zaproxy.VerifyScripts.java
@ParameterizedTest(name = "{1}") @MethodSource("allScripts") void shouldParseScript(Consumer<Reader> parser, @SuppressWarnings("unused") String script, Path path) throws Exception { try (Reader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) { parser.accept(reader);//from w w w .ja v a 2s .co m } }
From source file:de.tudarmstadt.informatik.lt.sogaardparser.MWEData.java
/** * Reads in a file in DRUID data format, discards any unigrams, and stores multi word expressions together with * their druid score.// w w w.j ava2s . c om * * @param file the MWE file * @param minScore the minimum druid score to load a MWE */ public MWEData(Path file, double minScore) throws IOException { entries = new HashMap<>(); try (BufferedReader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) { String line = null; while ((line = reader.readLine()) != null) { String[] parts = line.split("\t"); if (Integer.valueOf(parts[0]) > 1 && Double.valueOf(parts[2]) >= minScore) { entries.put(parts[1], Double.valueOf(parts[2])); } } } if (entries.isEmpty()) { Logger.getLogger(this.getClass().getName()) .warning("Found no multiword expressions in file " + file.toString()); } }
From source file:org.jboss.as.test.integration.logging.perdeploy.JBossLog4jXmlTestCase.java
@Test public void logsTest() throws IOException { final String msg = "logTest: jboss-log4j message"; final int statusCode = getResponse(msg, Collections.singletonMap("includeLevel", "true")); assertTrue("Invalid response statusCode: " + statusCode, statusCode == HttpStatus.SC_OK); boolean trace = false; boolean fatal = false; String traceLine = msg + " - trace"; String fatalLine = msg + " - fatal"; try (final BufferedReader reader = Files.newBufferedReader(logFile, StandardCharsets.UTF_8)) { String line;/*from w ww . j av a 2 s. com*/ while ((line = reader.readLine()) != null) { if (line.contains(traceLine)) { trace = true; } if (line.contains(fatalLine)) { fatal = true; } } } Assert.assertTrue("Log file should contain line: " + traceLine, trace); Assert.assertTrue("Log file should contain line: " + fatalLine, fatal); }
From source file:org.jboss.as.test.integration.logging.perdeploy.LoggingPropertiesTestCase.java
@Test public void logsTest() throws IOException { final String msg = "logTest: logging.properties message"; final int statusCode = getResponse(msg, Collections.singletonMap("includeLevel", "true")); assertTrue("Invalid response statusCode: " + statusCode, statusCode == HttpStatus.SC_OK); boolean trace = false; boolean fatal = false; String traceLine = msg + " - trace"; String fatalLine = msg + " - fatal"; try (final BufferedReader reader = Files.newBufferedReader(logFile, StandardCharsets.UTF_8)) { String line;// w w w . j av a 2 s . c o m while ((line = reader.readLine()) != null) { if (line.contains(traceLine)) { trace = true; } if (line.contains(fatalLine)) { fatal = true; } } } Assert.assertTrue("Log file should contain line: " + traceLine, trace); Assert.assertTrue("Log file should contain line: " + fatalLine, fatal); }
From source file:com.spotify.docker.client.DockerCertificates.java
private DockerCertificates(final Builder builder) throws DockerCertificateException { try {//from w w w . j a v a 2 s .c o m final CertificateFactory cf = CertificateFactory.getInstance("X.509"); final Certificate caCert = cf.generateCertificate(Files.newInputStream(builder.caCertPath)); final Certificate clientCert = cf.generateCertificate(Files.newInputStream(builder.clientCertPath)); final PEMKeyPair clientKeyPair = (PEMKeyPair) new PEMParser( Files.newBufferedReader(builder.clientKeyPath, Charset.defaultCharset())).readObject(); final PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec( clientKeyPair.getPrivateKeyInfo().getEncoded()); final KeyFactory kf = KeyFactory.getInstance("RSA"); final PrivateKey clientKey = kf.generatePrivate(spec); final KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); trustStore.setEntry("ca", new KeyStore.TrustedCertificateEntry(caCert), null); final KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(null, null); keyStore.setCertificateEntry("client", clientCert); keyStore.setKeyEntry("key", clientKey, KEY_STORE_PASSWORD, new Certificate[] { clientCert }); this.sslContext = SSLContexts.custom().loadTrustMaterial(trustStore) .loadKeyMaterial(keyStore, KEY_STORE_PASSWORD).useTLS().build(); } catch (CertificateException | IOException | NoSuchAlgorithmException | InvalidKeySpecException | KeyStoreException | UnrecoverableKeyException | KeyManagementException e) { throw new DockerCertificateException(e); } }
From source file:org.jboss.as.test.integration.logging.perdeploy.JBossLoggingPropertiesTestCase.java
@Test public void logsTest() throws IOException { final String msg = "logTest: jboss-logging.properties message"; final int statusCode = getResponse(msg, Collections.singletonMap("includeLevel", "true")); assertTrue("Invalid response statusCode: " + statusCode, statusCode == HttpStatus.SC_OK); boolean trace = false; boolean fatal = false; String traceLine = msg + " - trace"; String fatalLine = msg + " - fatal"; try (final BufferedReader reader = Files.newBufferedReader(logFile, StandardCharsets.UTF_8)) { String line;/* w w w . j av a 2s. co m*/ while ((line = reader.readLine()) != null) { if (line.contains(traceLine)) { trace = true; } if (line.contains(fatalLine)) { fatal = true; } } } Assert.assertTrue("Log file should contain line: " + traceLine, trace); Assert.assertTrue("Log file should contain line: " + fatalLine, fatal); }
From source file:org.opennms.opennms.pris.plugins.script.util.ScriptManager.java
public static Object execute(final InstanceConfiguration config, final Map<String, Object> bindings) throws IOException, ScriptException { Requisition requisition = null;//from w w w. ja va 2s . c o m // Get the path to the script final List<Path> scripts = config.getPaths("file"); // Get the script engine by language defined in config or by extension if it // is not defined in the config final ScriptEngineManager SCRIPT_ENGINE_MANAGER = new ScriptEngineManager( ScriptManager.class.getClassLoader()); for (Path script : scripts) { final ScriptEngine scriptEngine = config.containsKey("lang") ? SCRIPT_ENGINE_MANAGER.getEngineByName(config.getString("lang")) : SCRIPT_ENGINE_MANAGER.getEngineByExtension(FilenameUtils.getExtension(script.toString())); if (scriptEngine == null) { throw new RuntimeException("Script engine implementation not found"); } // Create some bindings for values available in the script final Bindings scriptBindings = scriptEngine.createBindings(); scriptBindings.put("script", script); scriptBindings.put("logger", LoggerFactory.getLogger(script.toString())); scriptBindings.put("config", config); scriptBindings.put("instance", config.getInstanceIdentifier()); scriptBindings.put("interfaceUtils", new InterfaceUtils(config)); scriptBindings.putAll(bindings); // Overwrite initial requisition with the requisition from the previous script, if there was any. if (requisition != null) { scriptBindings.put("requisition", requisition); } // Evaluate the script and return the requisition created in the script try (final Reader scriptReader = Files.newBufferedReader(script, StandardCharsets.UTF_8)) { LOGGER.debug("Start Script {}", script); requisition = (Requisition) scriptEngine.eval(scriptReader, scriptBindings); LOGGER.debug("Done Script {}", script); } } return requisition; }
From source file:org.jboss.as.test.integration.logging.perdeploy.Log4jXmlTestCase.java
@Test public void logsTest() throws IOException { final String msg = "logTest: log4j.xml message"; final int statusCode = getResponse(msg, Collections.singletonMap("includeLevel", "true")); assertTrue("Invalid response statusCode: " + statusCode, statusCode == HttpStatus.SC_OK); boolean trace = false; boolean fatal = false; String traceLine = msg + " - trace"; String fatalLine = msg + " - fatal"; try (final BufferedReader reader = Files.newBufferedReader(logFile, StandardCharsets.UTF_8)) { String line;//from ww w .j a v a 2 s . c om while ((line = reader.readLine()) != null) { if (line.contains(traceLine)) { trace = true; } if (line.contains(fatalLine)) { fatal = true; } } } Assert.assertTrue("Log file should contain line: " + traceLine, trace); Assert.assertTrue("Log file should contain line: " + fatalLine, fatal); }