private boolean isSearchTextPresentInLinesOfFile(File f) { LineIterator it = null; try { it = FileUtils.lineIterator(f, "UTF-8"); while (it.hasNext()) { String line = it.nextLine(); if (line.contains(searchText)) { return true; } } return false; } catch (IOException e) { throw new RuntimeException(e); } finally { LineIterator.closeQuietly(it); } }
public void realizarCargaArquivo() { ClassLoader classLoader = getClass().getClassLoader(); File file = new File(classLoader.getResource(NOME_ARQUIVO).getFile()); LineIterator it = null; try { it = FileUtils.lineIterator(file, "UTF-8"); while(it.hasNext()) { String linha = it.nextLine(); String[] dados = linha.split("\\|"); inserirCliente(dados[0], dados[1], dados[2], dados[3], dados[4], dados[5], dados[6], dados[7], dados[8], dados[9]); } } catch (Exception e) { e.printStackTrace(); } finally { it.close(); } }
public void realizarCargaArquivo() { ClassLoader classLoader = getClass().getClassLoader(); File file = new File(classLoader.getResource(NOME_ARQUIVO).getFile()); LineIterator it = null; try { it = FileUtils.lineIterator(file, "UTF-8"); while(it.hasNext()) { String linha = it.nextLine(); String[] dados = linha.split("\\|"); inserirItemAvaliado(dados[0], dados[1], dados[2], dados[3], dados[4]); } } catch (Exception e) { e.printStackTrace(); } finally { it.close(); } }
protected List<String> listRuntimeDependencies(String collectionName) throws IOException, SolrServerException { ModifiableSolrParams params = new ModifiableSolrParams().set("file",RUNTIME_LIB_FILE_NAME); SolrRequest request = new QueryRequest(params); request.setPath("/admin/file"); request.setResponseParser(new InputStreamResponseParser("json")); NamedList o = client.request(request, collectionName); LineIterator it = IOUtils.lineIterator((InputStream) o.get("stream"), "utf-8"); List<String> returnValues = Streams.stream(it).collect(Collectors.toList()); //if file not exists (a little hacky..) if(returnValues.size() == 1 && returnValues.get(0).startsWith("{\"responseHeader\":{\"status\":404")) { logger.warn("Release does not yet contain rumtimelib configuration file. Runtimelibs have to be installed manually."); return Collections.emptyList(); }; return returnValues; }
/** * Test that line above MaxLineLength are discarded * * @throws InterruptedException * @throws IOException */ @Test public void testMaxLineLengthwithAck() throws InterruptedException, IOException { String encoding = "UTF-8"; String ackEvent = "OK"; String ackErrorEvent = "FAILED: Event exceeds the maximum length (10 chars, including newline)"; startSource(encoding, "true", "1", "10"); Socket netcatSocket = new Socket(localhost, selectedPort); LineIterator inputLineIterator = IOUtils.lineIterator(netcatSocket.getInputStream(), encoding); try { sendEvent(netcatSocket, "123456789", encoding); Assert.assertArrayEquals("Channel contained our event", "123456789".getBytes(defaultCharset), getFlumeEvent()); Assert.assertEquals("Socket contained the Ack", ackEvent, inputLineIterator.nextLine()); sendEvent(netcatSocket, english, encoding); Assert.assertEquals("Channel does not contain an event", null, getRawFlumeEvent()); Assert.assertEquals("Socket contained the Error Ack", ackErrorEvent, inputLineIterator .nextLine()); } finally { netcatSocket.close(); stopSource(); } }
public static List<Code> fileToCodeList(String fileName) { List<Code> codes = new ArrayList<>(); try { LineIterator it = getLineIterator(fileName); while (it.hasNext()) { String line = it.nextLine(); if (line.equals("") || line.startsWith("#")) continue; String[] parts = line.split(";", 2); codes.add((new Code(parts[0], parts[1]))); } } catch (IOException e) { e.printStackTrace(); } return codes; }
private void converteerAfnemerindicatiebestand(final long maxAfnemerindicatieId, final OutputStream os, final LineIterator it) throws IOException { long voortgang = 0; final Map<Short, Short> partijConversieMap = partijConversie.getPartijConversieMap(); final Map<Integer, Integer> leveringsautorisatieConversieMap = leveringsautorisatieConversie.getLeveringsautorisatieConversieMap(); while (it.hasNext()) { final String line = it.nextLine(); final String[] splitLine = StringUtils.split(line, ","); final long origId = Long.parseLong(splitLine[0]); final long id = maxAfnemerindicatieId + origId; final String pers = splitLine[1]; final String afnemer = String.valueOf(partijConversieMap.get(Short.parseShort(splitLine[2]))); final String levsautorisatie = String.valueOf(leveringsautorisatieConversieMap.get(Integer.parseInt(splitLine[3]))); final String dataanvmaterieleperiode = StringUtils.defaultString(StringUtils.trimToNull(splitLine[4]), NULL_VALUE); final String dateindevolgen = StringUtils.defaultString(StringUtils.trimToNull(splitLine[5]), NULL_VALUE); final String indag = splitLine[6]; final String newLine = String.format("%s,%s,%s,%s,%s,%s,%s%n", id, pers, afnemer, levsautorisatie, dataanvmaterieleperiode, dateindevolgen, indag); IOUtils.write(newLine, os, StandardCharsets.UTF_8); voortgang++; if (voortgang % LOG_TRESHOLD == 0) { LOGGER.info("Voortgang persafnemerindicatie {}", voortgang); } } }
private void loadData() { File f = new File(getClass().getClassLoader().getResource(FILE).getFile()); try { LineIterator i = FileUtils.lineIterator(f); String[] header = null; while (i.hasNext()) { String[] cols = i.next().split("\t"); if (cols[0].equals("word")) { for (int c = 1; c < cols.length; c++) this.data.put(cols[c], new HashMap<String, Integer>()); header = cols; } else { String w = cols[0].toLowerCase(); for (int c = 1; c < cols.length; c++) { if (cols[c].length() > 0) this.data.get(header[c]).put(w, Integer.parseInt(cols[c])); } } } } catch (IOException e) { e.printStackTrace(); } }
private void loadData() { File f = new File(getClass().getClassLoader().getResource(FILE).getFile()); try { LineIterator i = FileUtils.lineIterator(f); while (i.hasNext()) { String[] cols = i.next().split("\t"); if (!cols[0].equals("Word")) { String w = cols[0].toLowerCase(); Double s = Double.parseDouble(cols[2]); this.data.put(w, s); } } } catch (IOException e) { e.printStackTrace(); } }
public void setWeights(String fileName) { File f = new File(fileName); try { LineIterator i = FileUtils.lineIterator(f); List<Double> weights = new ArrayList<Double>(); while (i.hasNext()) { String line = i.next().trim(); if (line.length() > 0) weights.add(Double.parseDouble(line)); } this.weights = new double[weights.size()]; for (int j = 0; j < weights.size(); j++) this.weights[j] = weights.get(j); } catch (IOException e) { e.printStackTrace(); } }
private static void loadFromDb(ArrayTable<Integer, Character, List<Person>> personsTable) throws IOException { long start = System.currentTimeMillis(); File dbFile = new File(Config.DB_FILE_NAME); LineIterator it = FileUtils.lineIterator(dbFile, "UTF-8"); while(it.hasNext()) { String line = it.next(); Person person = parseStringTokenizer(line); char fc = person.name.charAt(0); List<Person> persons = personsTable.get(person.age, fc); if(persons == null) { persons = new ArrayList<>(); personsTable.put(person.age, person.name.charAt(0), persons); } persons.add(person); } System.out.println("load data elapsed time : " + (System.currentTimeMillis() - start)); }
@Override public List<String> splitSentences(String text, String language_code) throws Exception { LOG.trace(String.format("Splitting sentences from text: %s", StringUtils.abbreviate(text, 200))); List<String> sentences = new ArrayList<String>(); text = de.tudarmstadt.lt.utilities.StringUtils.trim_and_replace_emptyspace(text, " "); for(LineIterator iter = new LineIterator(new StringReader(text)); iter.hasNext();){ String line = iter.nextLine(); BreakIterator sentence_bounds = BreakIterator.getSentenceInstance(LocaleUtils.toLocale(language_code)); sentence_bounds.setText(line); int begin_s = sentence_bounds.first(); for (int end_s = sentence_bounds.next(); end_s != BreakIterator.DONE; begin_s = end_s, end_s = sentence_bounds.next()) { String sentence = de.tudarmstadt.lt.utilities.StringUtils.trim(line.substring(begin_s, end_s)); if(sentence.isEmpty()) continue; sentences.add(sentence); LOG.trace(String.format("Current sentence: %s", StringUtils.abbreviate(sentence, 200))); } } LOG.trace(String.format("Split text '%s' into '%d' sentences.", StringUtils.abbreviate(text, 200), sentences.size())); return sentences; }
@Override public List<String>[] getNgrams(String text, String language_code) throws Exception { LOG.trace(String.format("Computing ngrams from text: %s", StringUtils.abbreviate(text, 200))); List<String>[] ngrams = null; text = text.trim(); for(LineIterator iter = new LineIterator(new StringReader(text)); iter.hasNext();){ List<String> tokens = tokenizeSentence(iter.nextLine()); LOG.trace(String.format("Current sentence: %s", StringUtils.abbreviate(tokens.toString(), 200))); if (tokens.size() < getLanguageModel().getOrder()){ LOG.trace("Too few tokens."); continue; } List<String>[] current_ngrams = getNgramSequenceFromSentence(tokens); LOG.trace(String.format("Current ngrams: %s", StringUtils.abbreviate(Arrays.toString(current_ngrams), 200))); if (ngrams == null) ngrams = current_ngrams; else ngrams = ArrayUtils.getConcatinatedArray(ngrams, current_ngrams); } LOG.trace(String.format("Ngrams for text: %n\t'%s'%n\t%s ", StringUtils.abbreviate(text, 200), StringUtils.abbreviate(Arrays.toString(ngrams), 200))); return ngrams; }
@Override public List<String> splitSentences(String text, String language_code) throws Exception { LOG.trace(String.format("Splitting sentences from text: %s", StringUtils.abbreviate(text, 200))); List<String> sentences = new ArrayList<String>(); text = de.tudarmstadt.lt.utilities.StringUtils.trim_and_replace_emptyspace(text, " "); for(LineIterator iter = new LineIterator(new StringReader(text)); iter.hasNext();){ String line = iter.nextLine(); String sentence = de.tudarmstadt.lt.utilities.StringUtils.trim(line); if(sentence.isEmpty()) continue; sentences.add(sentence); LOG.trace(String.format("Current sentence: %s", StringUtils.abbreviate(sentence, 200))); } LOG.debug(String.format("Split text '%s' into '%d' sentences.", StringUtils.abbreviate(text, 200), sentences.size())); return sentences; }
@Override public List<String> splitSentences(String text, String language_code) throws Exception { LOG.trace(String.format("Splitting sentences from text: %s", StringUtils.abbreviate(text, 200))); List<String> sentences = new ArrayList<String>(); if(Properties.onedocperline()){ LineIterator liter = new LineIterator(new StringReader(text)); for(String line; (line = liter.hasNext() ? liter.next() : null) != null;) split_and_add_sentences(line, sentences); }else{ split_and_add_sentences(text, sentences); } LOG.trace(String.format("Split text '%s' into '%d' sentences.", StringUtils.abbreviate(text, 200), sentences.size())); return sentences; }
@Override public void run() { LineIterator it = null; try { it = IOUtils.lineIterator(inputStream, "UTF-8"); while (it.hasNext()) { String line = it.nextLine(); LOGGER.debug(line); if (filtered) { filtered = filter(line); } } } catch (IOException ioe) { LOGGER.debug("Error consuming input stream: {}", ioe.getMessage()); } catch (IllegalStateException ise) { LOGGER.debug("Error reading from closed input stream: {}", ise.getMessage()); } finally { LineIterator.closeQuietly(it); // clean up all associated resources } }
public static Table<String, String, Long> loadTable(InputStream stream) throws IOException { Table<String, String, Long> result = TreeBasedTable.create(); LineIterator lineIterator = IOUtils.lineIterator(stream, "utf-8"); while (lineIterator.hasNext()) { String line = lineIterator.next(); System.out.println(line); String[] split = line.split("\t"); String language = split[0]; String license = split[1]; Long documents = Long.valueOf(split[2]); Long tokens = Long.valueOf(split[3]); result.put(language, "docs " + license, documents); result.put(language, "tokens " + license, tokens); } return result; }
public static LinkedHashMap<String, Integer> loadCorpusToRankedVocabulary(InputStream corpus) throws IOException { LinkedHashMap<String, Integer> result = new LinkedHashMap<>(); LineIterator lineIterator = IOUtils.lineIterator(corpus, "utf-8"); int counter = 0; while (lineIterator.hasNext()) { String line = lineIterator.next(); String word = line.split("\\s+")[0]; result.put(word, counter); counter++; } return result; }
private List<ActionDescriptor> parseIncludeDescriptors(Script script, Map<String, String> definitions, List<Script> includes, ResourceResolver resolver) throws ExecutionException { final List<ActionDescriptor> descriptors = new LinkedList<>(); LineIterator lineIterator = IOUtils.lineIterator(new StringReader(script.getData())); while (lineIterator.hasNext()) { String line = lineIterator.next(); if (ScriptUtils.isAction(line)) { final String command = ScriptUtils.parseCommand(line, definitions); final ActionDescriptor descriptor = actionFactory.evaluate(command); final Action action = descriptor.getAction(); descriptors.add(descriptor); if (action instanceof DefinitionProvider) { definitions.putAll(((DefinitionProvider) action).provideDefinitions(definitions)); } else if (action instanceof ScriptProvider) { getIncludes(definitions, includes, resolver, descriptors, (ScriptProvider) action); } } } return descriptors; }
private Set<String> loadFields() { Set<String> fields = Sets.newHashSet(); LineIterator it; try { it = FileUtils.lineIterator(_fieldsFile); } catch (IOException ex) { throw new OpenGammaRuntimeException("IOException when reading " + _fieldsFile, ex); } try { while (it.hasNext()) { String line = it.nextLine(); if (StringUtils.isBlank(line) || line.charAt(0) == '#') { continue; } fields.add(line); } } finally { LineIterator.closeQuietly(it); } return fields; }
/** * finds out how many lines are in the specified file. * * @param dataFile * the file to read * @return the number of lines. */ public static int getNumLines(DataFile dataFile) { FileStorage fileStorage = FileStorageFactory.getFileStorage(new TankConfig().getDataFileStorageDir(), false); FileData fd = DataFileUtil.getFileData(dataFile); int ret = 0; if (fileStorage.exists(fd)) { try { for (LineIterator iterator = IOUtils.lineIterator(fileStorage.readFileData(fd), "utf-8"); iterator.hasNext(); iterator.nextLine()) { ret++; } } catch (IOException e) { LOG.error("Error reading file: " + e, e); } } return ret; }
public static void createInputFile(Configuration conf, Path file, Path targetFile, String startNode) throws IOException { FileSystem fs = file.getFileSystem(conf); OutputStream os = fs.create(targetFile); LineIterator iter = org.apache.commons.io.IOUtils .lineIterator(fs.open(file), "UTF8"); while (iter.hasNext()) { String line = iter.nextLine(); String[] parts = StringUtils.split(line); int distance = Node.INFINITE; if (startNode.equals(parts[0])) { distance = 0; } IOUtils.write(parts[0] + '\t' + String.valueOf(distance) + "\t\t", os); IOUtils.write(StringUtils.join(parts, '\t', 1, parts.length), os); IOUtils.write("\n", os); } os.close(); }
public static int createInputFile(Path file, Path targetFile) throws IOException { Configuration conf = new Configuration(); FileSystem fs = file.getFileSystem(conf); int numNodes = getNumNodes(file); double initialPageRank = 1.0 / (double) numNodes; OutputStream os = fs.create(targetFile); LineIterator iter = IOUtils .lineIterator(fs.open(file), "UTF8"); while (iter.hasNext()) { String line = iter.nextLine(); String[] parts = StringUtils.split(line); Node node = new Node() .setPageRank(initialPageRank) .setAdjacentNodeNames( Arrays.copyOfRange(parts, 1, parts.length)); IOUtils.write(parts[0] + '\t' + node.toString() + '\n', os); } os.close(); return numNodes; }
/** * Writes the default system test style definition. */ protected void writeDefaultStyle() { xmlWriter_.writeElementStart( "STYLE"); xmlWriter_.indent(); LineIterator styleLines = null; try { for( styleLines = IOUtils.lineIterator( getClass().getResourceAsStream( "system-test.css"), "UTF-8"); styleLines.hasNext(); xmlWriter_.println( styleLines.next())); } catch( Exception e) { throw new RuntimeException( "Can't write resource=system-test.css", e); } finally { LineIterator.closeQuietly( styleLines); } xmlWriter_.unindent(); xmlWriter_.writeElementEnd( "STYLE"); }
/** * Writes the default system test presentation script. */ protected void writeDefaultScript() { xmlWriter_.writeElementStart( "SCRIPT"); xmlWriter_.indent(); LineIterator scriptLines = null; try { for( scriptLines = IOUtils.lineIterator( getClass().getResourceAsStream( "system-test.js"), "UTF-8"); scriptLines.hasNext(); xmlWriter_.println( scriptLines.next())); } catch( Exception e) { throw new RuntimeException( "Can't write resource=system-test.js", e); } finally { LineIterator.closeQuietly( scriptLines); } xmlWriter_.unindent(); xmlWriter_.writeElementEnd( "SCRIPT"); }
@Override public void getNext(JCas aJcas) throws IOException, CollectionException { File f = documents.get(i); LineIterator it = FileUtils.lineIterator(f); int start =0; int inds=0; StringBuffer sb = new StringBuffer(); while(it.hasNext()){ String line = it.nextLine(); Sentence sent = new Sentence(aJcas, start, start+line.length()); sent.addToIndexes(); start = start + line.length() + 1; sb.append(line+"\n"); if (inds%10000==0) System.out.println("R"+inds); } aJcas.setDocumentText(sb.toString()); //had to add english as default language, one could also add another configuration parameter aJcas.setDocumentLanguage("en"); i++; }
public static Set<String> getUndesiredTermsToFilterOut(String filename) { Set<String> result = new HashSet<String>(); File file = new File(FOLDER_PATH + filename); LineIterator it = null; try { it = FileUtils.lineIterator(file); while (it.hasNext()) { result.add(it.next().trim().toLowerCase()); } } catch (IOException e) { e.printStackTrace(); } finally { LineIterator.closeQuietly(it); } return result; }
public static Set<Integer> getUndesiredConceptsToFilterOut() { Set<Integer> things = new HashSet<Integer>(); // InputStreamReader(JochemCurator.class.getResourceAsStream("conceptsToRemove.txt"))); File file = new File(FOLDER_PATH + "conceptsToRemove.txt"); LineIterator it = null; try { it = FileUtils.lineIterator(file); while (it.hasNext()) { String conceptLine = it.next().trim(); String[] conceptNumbers = conceptLine.split(";"); for (String conceptNumber : conceptNumbers) { if (conceptNumber.length() != 0) things.add(Integer.parseInt(conceptNumber)); } } } catch (IOException e) { e.printStackTrace(); } finally { LineIterator.closeQuietly(it); } return things; }
public static Set<String> getPharmaceuticalCompanies() { Set<String> result = new HashSet<String>(); // InputStreamReader(JochemCurator.class.getResourceAsStream("pharmaceuticalCompanies.txt"))); File file = new File(FOLDER_PATH + "pharmaceuticalCompanies.txt"); LineIterator it = null; try { it = FileUtils.lineIterator(file); while (it.hasNext()) { result.add(it.next().trim().toLowerCase()); } } catch (IOException e) { e.printStackTrace(); } finally { LineIterator.closeQuietly(it); } return result; }
@Override public void defaultBuildCommand(String eclipseProjectName, String dockerBuildContext) { File baseDir = new File(dockerBuildContext); InputStream response = dockerClient.buildImageCmd(baseDir).exec(); StringWriter logwriter = new StringWriter(); messageConsole.getDockerConsoleOut().println(">>> Building " + dockerBuildContext + "/Dockerfile with default options"); messageConsole.getDockerConsoleOut().println(""); try { messageConsole.getDockerConsoleOut().flush(); LineIterator itr = IOUtils.lineIterator(response, "UTF-8"); while (itr.hasNext()) { String line = itr.next(); logwriter.write(line); messageConsole.getDockerConsoleOut().println(line); messageConsole.getDockerConsoleOut().flush(); } } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(response); } messageConsole.getDockerConsoleOut().println(""); messageConsole.getDockerConsoleOut().println("<<< Build ended"); }
public static void main(String[] args) throws IOException { LineIterator goldIt = FileUtils.lineIterator(new File("/home/seid/Desktop/tmp/engner/gold_testb.tsv")); LineIterator predIt = FileUtils.lineIterator(new File("/home/seid/Desktop/tmp/engner/pred.tsv")); boolean flag = false; OutputStream os = new FileOutputStream(new File("/home/seid/Desktop/tmp/engner/eval.tsv")); while (goldIt.hasNext()) { String goldLine = goldIt.next(); String predLine = predIt.next(); if (goldLine.isEmpty() && !flag) { flag = true; IOUtils.write("\n", os, "UTF8"); } else if (goldLine.isEmpty()) { continue; } else { IOUtils.write(goldLine.replace("\t", " ") + " " + predLine.split("\t")[1] + "\n", os, "UTF8"); flag = false; } } }
/** * Check if a TAB-Sep training file is in correct format before importing */ private boolean isTabSepFileFormatCorrect(File aFile) { try { LineIterator it = new LineIterator(new FileReader(aFile)); while (it.hasNext()) { String line = it.next(); if (line.trim().length() == 0) { continue; } if (line.split("\t").length != 2) { return false; } } } catch (Exception e) { return false; } return true; }
/** * Load the content of the context file. * * @param path path of the context File. * @return Context loaded. * @throws IOException if file not found. * @throws MalformedContextFileException if the Context file don't have the right structure. * @throws IllogicalContextException if an image is bigger than pattern max size. */ public static Context loadContext(String path) throws IOException, MalformedContextFileException, IllogicalContextException { File file = new File(path); LineIterator it = FileUtils.lineIterator(file, "UTF-8"); ArrayList<Box> boxes = new ArrayList<>(); try { Double x = loadLine(it, "^LX=[0-9]{1,13}(\\.[0-9]*)?$"); Double y = loadLine(it, "LY=[0-9]{1,13}(\\.[0-9]*)?"); int cost = loadLine(it, "m=[0-9]{1,13}(\\.[0-9]*)?").intValue(); while (it.hasNext()) { boxes.add(loadBox(it.nextLine())); } LineIterator.closeQuietly(it); double max = Math.max(x, y); if (boxes.parallelStream().anyMatch(b -> b.getSize().getX() > max) || boxes.parallelStream().anyMatch(b -> b.getSize().getY() > max)) { throw new IllogicalContextException("There is an image which is bigger than the pattern."); } return new Context(file.getName(), 20, 1, boxes, new Vector(x, y)); } catch (MalformedContextFileException mctx) { throw mctx; } finally { LineIterator.closeQuietly(it); } }
/** * @see org.neo4art.sentiment.service.DictionaryService#saveDictionary() */ @Override public void saveDictionary() throws IOException { String alphabet[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; for (int i = 0; i < alphabet.length; i++) { String dictionaryFile = "dictionary" + File.separator + this.locale.getLanguage() + File.separator + alphabet[i] + " Words.txt"; logger.info("Importing dictionary file: " + dictionaryFile); LineIterator dictionaryFileIterator = IOUtils.lineIterator(getClass().getClassLoader().getResourceAsStream(dictionaryFile), Charset.defaultCharset()); while (dictionaryFileIterator.hasNext()) { this.mergeWordWithoutFlushing(dictionaryFileIterator.next()); } } Neo4ArtBatchInserterSingleton.flushLegacyNodeIndex(NLPLegacyIndex.WORD_LEGACY_INDEX); }
/** * * @param file * @param polarity * @throws IOException */ private void addPolarity(String file, int polarity) throws IOException { logger.info("Adding polarity from file: " + file); LineIterator polarityFile = IOUtils.lineIterator(getClass().getClassLoader().getResourceAsStream(file), Charset.defaultCharset()); while (polarityFile.hasNext()) { String word = polarityFile.nextLine(); if (StringUtils.isNotEmpty(word) && !StringUtils.startsWith(word, ";")) { Long wordNodeId = this.mergeWordWithoutFlushing(DictionaryUtils.escapeWordForLuceneSearch(word)); Neo4ArtBatchInserterSingleton.setNodeProperty(wordNodeId, Word.POLARITY_PROPERTY_NAME, polarity); } } Neo4ArtBatchInserterSingleton.flushLegacyNodeIndex(NLPLegacyIndex.WORD_LEGACY_INDEX); }
public static String collectResponse(InputStream response) { StringWriter logwriter = new StringWriter(); try { LineIterator itr = IOUtils.lineIterator(response, "UTF-8"); while (itr.hasNext()) { String line = (String) itr.next(); logwriter.write(line + (itr.hasNext() ? "\n" : "")); } response.close(); return logwriter.toString(); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(response); } }
private void createProjFile(String file, String projectLabel) { File template = new File(FAQ_DIR+File.separator+"whc_template"+File.separator+"project.html"); StringBuffer buf = new StringBuffer(); String title = StringEscapeUtils.escapeHtml(projectLabel); LineIterator it = null; try { it = FileUtils.lineIterator(template, "UTF-8"); try { while (it.hasNext()) { String line = it.nextLine(); line = line.replaceAll("\\$title", title); buf.append(line+CRLF); } } finally { it.close(); } } catch (Exception e) { LOGGER.error("Can't copy project.html template file: " + e.getMessage()); } writeFile(buf.toString(), file); }
public static void accept(@Nonnull InputStream in, @Nonnull Charset charset, @Nonnull CheckedConsumer<String, IOException> consumer) throws IOException { checkNotNull(in); checkNotNull(charset); checkNotNull(consumer); LineIterator it = IOUtils.lineIterator(in, charset); try { while (it.hasNext()) { consumer.accept(it.nextLine()); } } catch (IllegalStateException e) { Throwables.throwIfInstanceOf(e.getCause(), IOException.class); throw new IOException(e); } finally { it.close(); } }
public String uploadFile(String fileName) { File file = new File(getDataFolder(), fileName); if (!file.exists()) return null; LineIterator it; String lines = ""; try { it = FileUtils.lineIterator(file, "UTF-8"); try { while (it.hasNext()) { String line = it.nextLine(); lines = lines + line + "\n"; } } finally { it.close(); } } catch (IOException e) { e.printStackTrace(); } return MCDebug.paste(fileName, lines); }
public static TransactionList readTransactions(final File inputFile) throws IOException { final List<Transaction> transactions = new ArrayList<>(); // for each line (transaction) until the end of file final LineIterator it = FileUtils.lineIterator(inputFile, "UTF-8"); while (it.hasNext()) { final String line = it.nextLine(); // if the line is a comment, is empty or is a // kind of metadata if (line.isEmpty() == true || line.charAt(0) == '#' || line.charAt(0) == '%' || line.charAt(0) == '@') { continue; } // split the transaction into items final String[] lineSplited = line.split(" "); // convert to Transaction class and add it to the structure transactions.add(getTransaction(lineSplited)); } // close the input file LineIterator.closeQuietly(it); return new TransactionList(transactions); }