List of usage examples for java.nio.file Files readAllLines
public static List<String> readAllLines(Path path, Charset cs) throws IOException
From source file:org.sonar.scanner.scan.filesystem.CharsetValidationTest.java
@Test public void testWithSourceCode() throws IOException, URISyntaxException { Path path = Paths.get(this.getClass().getClassLoader() .getResource("mediumtest/xoo/sample/xources/hello/HelloJava.xoo").toURI()); List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8); String text = lines.stream().collect(StringBuffer::new, StringBuffer::append, StringBuffer::append) .toString();/*from w w w . j ava2 s . co m*/ byte[] utf8 = encode(text, StandardCharsets.UTF_8); byte[] utf16be = encode(text, StandardCharsets.UTF_16BE); byte[] utf16le = encode(text, StandardCharsets.UTF_16LE); assertThat(charsets.isUTF8(utf8, true).charset()).isEqualTo(StandardCharsets.UTF_8); assertThat(charsets.isUTF16(utf16be, true).charset()).isEqualTo(StandardCharsets.UTF_16BE); assertThat(charsets.isUTF16(utf16le, true).charset()).isEqualTo(StandardCharsets.UTF_16LE); assertThat(charsets.isValidUTF16(utf16be, false)).isTrue(); assertThat(charsets.isValidUTF16(utf16le, true)).isTrue(); }
From source file:org.wandora.application.tools.extractors.word.AbstractWordExtractor.java
@Override public boolean _extractTopicsFrom(File f, TopicMap t) throws Exception { List<String> words = Files.readAllLines(f.toPath(), Charset.forName("UTF-8")); return handleWordList(words, t); }
From source file:adalid.util.io.SmallFile.java
public List<String> read() { Charset[] charsets = _charsets == null ? DEFAULT_CHARSETS : _charsets; _charset = null;/*from w w w . j ava2s. com*/ for (Charset cs : charsets) { try { _lines = Files.readAllLines(_path, cs); _charset = cs; return _lines; } catch (IOException ex) { } } return null; }
From source file:org.wandora.application.tools.extractors.twitter.TwitterJSONExtractor.java
@Override public boolean _extractTopicsFrom(File f, TopicMap t) throws Exception { List<String> lines = Files.readAllLines(f.toPath(), Charset.forName("UTF-8")); StringBuilder sb = new StringBuilder(); for (String line : lines) { sb.append(line);//from w w w . j ava2 s . c o m } return handleStatuses(sb.toString(), t); }
From source file:org.abondar.experimental.eventsearch.ServiceBean.java
public String getJSONstr(String path) throws FileNotFoundException, IOException { StringBuilder res = new StringBuilder(); List<String> resList = Files.readAllLines(Paths.get(path), Charset.forName("UTF-8")); for (String line : resList) res.append(line);/* ww w. j a v a 2s . c om*/ return res.toString(); }
From source file:com.ontheserverside.batch.bank.tx.SimpleElixir0Generator.java
private List<String> loadLinesFromFile(final Resource resource) throws IOException { return Files.readAllLines(resource.getFile().toPath(), StandardCharsets.UTF_8); }
From source file:org.kantega.notsoserial.WithDryRunWhitelistIT.java
@Test public void shouldRecordClassesAsDeserialized() throws TransformerConfigurationException, IOException, ClassNotFoundException, AttachNotSupportedException, AgentLoadException, AgentInitializationException { System.setProperty("notsoserial.whitelist", "src/test/resources/whitelist.txt"); System.setProperty("notsoserial.dryrun", "target/is-deserialized.txt"); attachAgent();//from w w w. j a va 2s . c o m byte[] ser = Files.readAllBytes(Paths.get("target").resolve("bytes.ser")); try { System.setProperty("pwned", "false"); // Deserializing should not flip pwned to true deserialize(ser); } catch (ClassCastException e) { // Ignore, happens after exploit effect } assertThat(System.getProperty("pwned"), is("true")); Set<String> deserialized = new TreeSet<String>( Files.readAllLines(Paths.get("target/is-deserialized.txt"), StandardCharsets.UTF_8)); assertThat(deserialized, hasItem("org.apache.commons.collections4.functors.InvokerTransformer")); assertThat(deserialized, hasItem("java.util.PriorityQueue")); }
From source file:org.sonar.xoo.rule.AnalysisErrorSensor.java
private void processFileError(InputFile inputFile, SensorContext context) { Path ioFile = inputFile.file().toPath(); Path errorFile = ioFile.resolveSibling(ioFile.getFileName() + ERROR_EXTENSION).toAbsolutePath(); if (Files.exists(errorFile) && Files.isRegularFile(errorFile)) { LOG.debug("Processing " + errorFile.toString()); try {// w ww. j a v a2 s . c om List<String> lines = Files.readAllLines(errorFile, context.fileSystem().encoding()); for (String line : lines) { if (StringUtils.isBlank(line) || line.startsWith("#")) { continue; } processLine(line, inputFile, context); } } catch (IOException e) { throw new IllegalStateException(e); } } }
From source file:com.twosigma.beaker.core.rest.RecentMenuRest.java
@Inject public RecentMenuRest(BeakerConfig bkConfig, GeneralUtils utils) { this.utils = utils; this.recentDocumentsFile = Paths.get(bkConfig.getRecentNotebooksFileUrl()); this.recentDocuments = new LinkedBlockingDeque<>(); // read from file -> recentDocuments List<String> lines = new ArrayList<>(); if (Files.exists(recentDocumentsFile)) { try {//from w w w. ja v a2 s . co m lines = Files.readAllLines(recentDocumentsFile, StandardCharsets.UTF_8); } catch (IOException ex) { logger.warn("Failed to get recent documents", ex); } } for (String line : lines) { addRecentDocument(line.trim()); } }
From source file:org.kantega.notsoserial.WithDryRunWhitelistAndTraceIT.java
@Test public void shouldRecordClassesAsDeserialized() throws TransformerConfigurationException, IOException, ClassNotFoundException, AttachNotSupportedException, AgentLoadException, AgentInitializationException { System.setProperty("notsoserial.whitelist", "src/test/resources/whitelist.txt"); System.setProperty("notsoserial.dryrun", "target/is-deserialized.txt"); System.setProperty("notsoserial.trace", "target/deserialized-trace.txt"); attachAgent();//w ww. j a v a2 s .c o m byte[] ser = Files.readAllBytes(Paths.get("target").resolve("bytes.ser")); try { System.setProperty("pwned", "false"); // Deserializing should not flip pwned to true deserialize(ser); } catch (ClassCastException e) { // Ignore, happens after exploit effect } assertThat(System.getProperty("pwned"), is("true")); Set<String> deserialized = new TreeSet<String>( Files.readAllLines(Paths.get("target/is-deserialized.txt"), StandardCharsets.UTF_8)); assertThat(deserialized, hasItem("org.apache.commons.collections4.functors.InvokerTransformer")); assertThat(deserialized, hasItem("java.util.PriorityQueue")); }