Java Code Examples for org.apache.commons.io.IOUtils#readLines()
The following examples show how to use
org.apache.commons.io.IOUtils#readLines() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: gameserver File: CDKeyManager.java License: Apache License 2.0 | 6 votes |
/** * Import the already generated cdkey into system. * * @param fileName * @return */ public int importCDKey(String fileName) throws IOException { int count = 0; File file = new File(fileName); HashMap<String, String> cdkeyMap = new HashMap<String, String>(); if ( file.exists() && file.isFile() ) { List<String> lines = IOUtils.readLines(new FileReader(file)); for ( String line : lines ) { String[] cdkeys = line.split(Constant.COMMA); if ( cdkeys.length == 2 ) { String cdkey = cdkeys[0]; String pojoId = cdkeys[1]; cdkeyMap.put(cdkey, pojoId); count++; logger.info("Import cdKey:"+cdkey+", pojoId:"+pojoId); } } if ( cdkeyMap.size() > 0 ) { Jedis jedis = JedisFactory.getJedisDB(); jedis.hmset(REDIS_CDKEY, cdkeyMap); } } else { logger.warn("CDKey File cannot be read:{}", file.getAbsolutePath()); } return count; }
Example 2
Source Project: swift-explorer File: PlainTextPanel.java License: Apache License 2.0 | 6 votes |
/** * {@inheritDoc}. */ @Override public void displayPreview(String contentType, ByteArrayInputStream in) { try { try { StringBuilder sb = new StringBuilder(); for (String line : IOUtils.readLines(in)) { sb.append(line); sb.append(System.getProperty("line.separator")); } area.setText(sb.toString()); } finally { in.close(); } } catch (IOException e) { area.setText(""); logger.error("Error occurred while previewing text", e); } }
Example 3
Source Project: org.openhab.ui.habot File: NotificationService.java License: Eclipse Public License 1.0 | 6 votes |
/** * Loads the VAPID keypair from the file, or generate them if they don't exist. */ private void loadVAPIDKeys() { try { List<String> encodedKeys = IOUtils.readLines( new FileInputStream(ConfigConstants.getUserDataFolder() + File.separator + VAPID_KEYS_FILE_NAME)); this.publicVAPIDKey = encodedKeys.get(0); this.privateVAPIDKey = encodedKeys.get(1); } catch (IOException e) { try { generateVAPIDKeyPair(); } catch (InvalidAlgorithmParameterException | NoSuchProviderException | NoSuchAlgorithmException | IOException e1) { RuntimeException ex = new RuntimeException("Cannot get the VAPID keypair for push notifications"); ex.initCause(e1); throw ex; } } }
Example 4
Source Project: owltools File: EcoMapperFactory.java License: BSD 3-Clause "New" or "Revised" License | 6 votes |
private static EcoMappings<OWLClass> loadEcoMappings(Reader mappingsReader, OWLGraphWrapper eco) throws IOException { EcoMappings<OWLClass> mappings = new EcoMappings<OWLClass>(); List<String> lines = IOUtils.readLines(mappingsReader); for (String line : lines) { line = StringUtils.trimToNull(line); if (line != null) { char c = line.charAt(0); if ('#' != c) { String[] split = StringUtils.split(line, '\t'); if (split.length == 3) { String code = split[0]; String ref = split[1]; String ecoId = split[2]; OWLClass cls = eco.getOWLClassByIdentifier(ecoId); if (cls != null) { mappings.add(code, ref, cls); } } } } } return mappings; }
Example 5
Source Project: streams File: ExamplesSerDeIT.java License: Apache License 2.0 | 6 votes |
/** * Tests that activities matching core-ex* can be parsed by apache streams. * * @throws Exception test exception */ @Test public void testCoreSerDe() throws Exception { InputStream testActivityFolderStream = ExamplesSerDeIT.class.getClassLoader() .getResourceAsStream("w3c/activitystreams-master/test"); List<String> files = IOUtils.readLines(testActivityFolderStream, StandardCharsets.UTF_8); for (String file : files) { if ( !file.startsWith(".") && file.contains("core-ex") ) { LOGGER.info("File: activitystreams-master/test/" + file); String testFileString = new String(Files.readAllBytes(Paths.get("target/test-classes/w3c/activitystreams-master/test/" + file))); LOGGER.info("Content: " + testFileString); ObjectNode testFileObjectNode = MAPPER.readValue(testFileString, ObjectNode.class); LOGGER.info("Object:" + testFileObjectNode); } } }
Example 6
Source Project: support-diagnostics File: CollectLogs.java License: Apache License 2.0 | 6 votes |
protected List<String> extractFilesFromList(String output, List<String> fileList, int entries) { // Just in case, since NPE"s are a drag output = ObjectUtils.defaultIfNull(output, ""); // If there's content add it to the file list if (StringUtils.isNotEmpty(output.trim())) { try { List<String> lines = IOUtils.readLines(new StringReader(output)); int sz = lines.size(); for (int i = 0; i < sz; i++) { fileList.add(lines.get(i)); if(i == entries){ break; } } } catch (Exception e) { logger.error( "Error getting directory listing.", e); } } return fileList; }
Example 7
Source Project: NNAnalytics File: TestNNAnalyticsBase.java License: Apache License 2.0 | 5 votes |
@Test public void testHasQuotaList() throws IOException { HttpGet get = new HttpGet("http://localhost:4567/filter?set=dirs&filters=hasQuota:eq:true"); HttpResponse res = client.execute(hostPort, get); List<String> result = IOUtils.readLines(res.getEntity().getContent()); System.out.println(result); assertThat(result.size(), is(not(0))); assertThat(res.getStatusLine().getStatusCode(), is(200)); }
Example 8
Source Project: OpenEstate-IO File: CsvRecord.java License: Apache License 2.0 | 5 votes |
/** * Write content of the record in a human readable form. * * @param writer where the data is written to * @param lineSeparator line separator for multi line values * @throws IOException if the record can't be written */ public void dump(Writer writer, String lineSeparator) throws IOException { for (int i = 0; i < this.getRecordLenth(); i++) { StringBuilder txt = new StringBuilder(); try (StringReader reader = new StringReader(StringUtils.trimToEmpty(this.get(i)))) { for (String line : IOUtils.readLines(reader)) { if (txt.length() > 0) txt.append(lineSeparator); txt.append(line); } } writer.write(i + ":" + txt.toString()); writer.write(System.lineSeparator()); } }
Example 9
Source Project: NNAnalytics File: TestNNAnalyticsBase.java License: Apache License 2.0 | 5 votes |
@Test public void testAverageSpacePerBlock() throws IOException { HttpGet get = new HttpGet( "http://localhost:4567/divide?set1=files&sum1=fileSize&set2=files&sum2=numBlocks"); HttpResponse res = client.execute(hostPort, get); List<String> strings = IOUtils.readLines(res.getEntity().getContent()); assertThat(strings.size(), is(1)); String average = strings.get(0); System.out.println(average); long v = Long.parseLong(average); assertThat(v, is(not(0L))); assertThat(res.getStatusLine().getStatusCode(), is(200)); }
Example 10
Source Project: tensorboot File: MobilenetV2Classifier.java License: Apache License 2.0 | 5 votes |
@PostConstruct public void setup() { try { byte[] graphBytes = FileUtils.readFileToByteArray(new File(modelConfig.getModelPath())); init(graphBytes, modelConfig.getInputLayerName(), modelConfig.getOutputLayerName()); List<String> labelsList = IOUtils.readLines(modelConfig.getLabelsResource().getInputStream(), "UTF-8"); labels = new ArrayList<>(labelsList); log.info("Initialized Tensorflow model ({}MB)", graphBytes.length / BYTES_IN_MB); } catch (IOException e) { log.error("Error during classifier initialization:", e); } }
Example 11
Source Project: kylin-on-parquet-v2 File: ControllerSplitter.java License: Apache License 2.0 | 5 votes |
private static void chopOff(File f, String annoPtn) throws IOException { System.out.println("Processing " + f); FileInputStream is = new FileInputStream(f); List<String> lines = IOUtils.readLines(is, "UTF-8"); is.close(); List<String> outLines = new ArrayList<>(lines.size()); boolean del = false; for (String l : lines) { if (l.startsWith(" @") && l.contains(annoPtn)) del = true; if (del) System.out.println("x " + l); else outLines.add(l); if (del && l.startsWith(" }")) del = false; } if (!dryRun && outLines.size() < lines.size()) { FileOutputStream os = new FileOutputStream(f); IOUtils.writeLines(outLines, "\n", os, "UTF-8"); os.close(); System.out.println("UPDATED " + f); } else { System.out.println("skipped"); } System.out.println("============================================================================"); }
Example 12
Source Project: C2-Github-commit-count File: CommitFeedListener.java License: MIT License | 5 votes |
@Override public void open(Map map, TopologyContext context, SpoutOutputCollector outputCollector) { this.outputCollector = outputCollector; try { commits = IOUtils.readLines(ClassLoader.getSystemResourceAsStream("changelog.txt"), Charset.defaultCharset().name()); } catch (IOException e) { throw new RuntimeException(e); } }
Example 13
Source Project: rdf4j File: RDFXMLPrettyWriterBackgroundTest.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Extract lines that start an rdf element so basic assertions can be made. */ private static List<String> rdfOpenTags(String s) throws IOException { String withoutSpaces = Pattern.compile("^\\s+", Pattern.MULTILINE).matcher(s).replaceAll(""); List<String> rdfLines = new ArrayList<>(); for (String l : IOUtils.readLines(new StringReader(withoutSpaces))) { if (l.startsWith("<rdf:")) { rdfLines.add(l.replaceAll(" .*", "")); } } return rdfLines; }
Example 14
Source Project: NNAnalytics File: TestNNAnalyticsBase.java License: Apache License 2.0 | 5 votes |
@Test public void testFindAvgFileSizeUserHistogramCSV() throws IOException { HttpGet get = new HttpGet( "http://localhost:4567/histogram?set=files&type=user&find=max:fileSize&histogramOutput=csv"); HttpResponse res = client.execute(hostPort, get); List<String> text = IOUtils.readLines(res.getEntity().getContent()); assertThat(text.size(), is(1)); assertThat(text.get(0).split(",").length, is(2)); assertThat(res.getStatusLine().getStatusCode(), is(200)); }
Example 15
Source Project: NNAnalytics File: TestNNAnalyticsBase.java License: Apache License 2.0 | 5 votes |
@Test public void testStorageTypeHistogram() throws IOException { HttpGet get = new HttpGet("http://localhost:4567/histogram?set=files&type=storageType"); HttpResponse res = client.execute(hostPort, get); List<String> strings = IOUtils.readLines(res.getEntity().getContent()); if (!String.join(" ", strings).contains("not supported")) { strings.clear(); assertThat(res.getStatusLine().getStatusCode(), is(200)); } }
Example 16
Source Project: Canova File: StopWords.java License: Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public static List<String> getStopWords() { try { if(stopWords == null) stopWords = IOUtils.readLines(new ClassPathResource("/stopwords").getInputStream()); } catch (IOException e) { throw new RuntimeException(e); } return stopWords; }
Example 17
Source Project: gerbil File: WhiteListBasedUriKBClassifier.java License: GNU Affero General Public License v3.0 | 5 votes |
public static WhiteListBasedUriKBClassifier create(InputStream stream) { try { return new WhiteListBasedUriKBClassifier(IOUtils.readLines(stream)); } catch (IOException e) { LOGGER.error("Exception while trying to read knowledge base namespaces.", e); return null; } }
Example 18
Source Project: wenku File: LinuxProcessManager.java License: MIT License | 5 votes |
private List<String> execute(String... args) throws IOException { String[] command; if (runAsArgs != null) { command = new String[runAsArgs.length + args.length]; System.arraycopy(runAsArgs, 0, command, 0, runAsArgs.length); System.arraycopy(args, 0, command, runAsArgs.length, args.length); } else { command = args; } Process process = new ProcessBuilder(command).start(); return IOUtils.readLines(process.getInputStream(), Charset.defaultCharset()); }
Example 19
Source Project: matrix-appservice-email File: AEmailClientFormatter.java License: GNU Affero General Public License v3.0 | 4 votes |
protected String formatPlain(String content) { // TODO do a proper algorithm try { int maxLine = 0; List<String> linesIn = IOUtils.readLines(new StringReader(content)); for (int i = 0; i < linesIn.size(); i++) { if (linesIn.get(i).startsWith(">")) { maxLine = i - (StringUtils.isBlank(linesIn.get(i - 1)) ? 2 : 1); break; } } List<String> linesOut = new ArrayList<>(); boolean prevLineBlank = false; for (int i = 0; i < maxLine; i++) { String line = StringUtils.trimToEmpty(linesIn.get(i)); if (StringUtils.isBlank(line)) { if (prevLineBlank) { continue; } prevLineBlank = true; } else { prevLineBlank = false; } linesOut.add(line); } if (prevLineBlank) { linesOut.remove(linesOut.size() - 1); } return StringUtils.join(linesOut, System.lineSeparator()); } catch (IOException e) { // This should never happen, we can't deal with it here throw new RuntimeException(e); } }
Example 20
Source Project: yarg File: LinuxProcessManager.java License: Apache License 2.0 | 4 votes |
protected List<String> execute(String... args) throws IOException { Process process = new ProcessBuilder(args).start(); @SuppressWarnings("unchecked") List<String> lines = IOUtils.readLines(process.getInputStream()); return lines; }