List of usage examples for org.apache.commons.io FileUtils readLines
public static List readLines(File file) throws IOException
From source file:com.mvdb.scratch.HadoopClient.java
/** * Convert the lines of text in a file to binary and write to a Hadoop * sequence file.// ww w . j a v a 2s .c om * * @param dataFile File containing lines of text * @param sequenceFileName Name of the sequence file to create * @param hadoopFS Hadoop file system * * @throws IOException */ public static void writeToSequenceFile(File dataFile, String sequenceFileName, String hadoopFS) throws IOException { IntWritable key = null; BytesWritable value = null; conf.set("fs.defaultFS", hadoopFS); FileSystem fs = FileSystem.get(conf); Path path = new Path(sequenceFileName); if ((conf != null) && (dataFile != null) && (dataFile.exists())) { SequenceFile.Writer writer = SequenceFile.createWriter(fs, conf, path, IntWritable.class, BytesWritable.class); List<String> lines = FileUtils.readLines(dataFile); for (int i = 0; i < lines.size(); i++) { value = new BytesWritable(lines.get(i).getBytes()); key = new IntWritable(i); writer.append(key, value); } IOUtils.closeStream(writer); } }
From source file:net.nicholaswilliams.java.teamcity.plugin.linux.LinuxPropertiesLocatorDefault.java
@Override protected void locateLinuxProperties(Map<String, String> properties) { if (this.isLinux()) { if (LinuxPropertiesLocatorDefault.logger.isDebugEnabled()) LinuxPropertiesLocatorDefault.logger.debug("Operating system is Linux; detecting flavor."); for (Flavor flavor : Flavor.values()) { try { File flavorFile = flavor.getFlavorFile(); if (flavorFile.exists()) { @SuppressWarnings("unchecked") List<String> flavorFileContents = FileUtils.readLines(flavorFile); properties.put(LinuxPropertiesLocator.OS_FLAVOR_KEY, flavor.name()); flavor.locateLinuxProperties(flavorFileContents, properties); if (LinuxPropertiesLocatorDefault.logger.isDebugEnabled()) { LinuxPropertiesLocatorDefault.logger .debug("Detected Linux flavor " + flavor.name() + "."); }//from www . j a v a2 s. c o m break; } else if (LinuxPropertiesLocatorDefault.logger.isDebugEnabled()) { LinuxPropertiesLocatorDefault.logger.debug("Linux flavor not " + flavor.name() + "."); } } catch (IOException e) { LinuxPropertiesLocatorDefault.logger .info("Linux flavor not " + flavor.name() + "; " + e.toString()); } } } }
From source file:jenkins.plugins.asqatasun.ProjectAsqatasunAction.java
private String buildAuditResultUrl(String webappUrl) { try {/* www . j av a 2 s . c om*/ for (Object obj : FileUtils.readLines(project.getLastBuild().getLogFile())) { String line = (String) obj; if (StringUtils.startsWith(line, "Audit Id")) { return doBuildAuditResultUrl(line, webappUrl); } } } catch (IOException ex) { Logger.getLogger(ProjectAsqatasunAction.class.getName()).log(Level.SEVERE, null, ex); } return webappUrl; }
From source file:MdDetect.java
/** * Create instances of the process function per file * * @param file the file to process/* w w w . ja va 2 s . c o m*/ * @return nothing */ private static Callable<Void> newProcessFileAction(final File file) { return new Callable<Void>() { @Override public Void call() throws Exception { // read the lines of the 'in'-file List<String> inLines = FileUtils.readLines(file); // queue up the output List<String> outLines = new ArrayList<>(); // flip/flop for blocks boolean inBlock = false; // line counter int ii = 0; for (String line : inLines) { if (line.matches(MD_CODE_REGEX)) { // is the line the start of a code block? line = line.trim(); // clean it up // flip the block toggle inBlock = !inBlock; if (inBlock && !isAlreadyAnnotated(line)) { // there needs to be a kind of 'look-ahead' here to figure out what tag to use... // lets do a best effort to figure our what it is // how about we grab the next few lines and so some casual checks List<String> codeBlockLines = new ArrayList<>(); // grab the rest of this code block grabCodeBlock(inLines, ii, codeBlockLines); // grab the tag to use String tag = supposeLang(codeBlockLines); // then use it line = line.replace("```", "```" + tag); } } outLines.add(line); ii++; // increment the lines counter } // write the outlines over the old file.... FileUtils.writeLines(file, outLines); return null; } }; }
From source file:dkpro.similarity.algorithms.lexical.ngrams.CharacterNGramMeasure.java
public CharacterNGramMeasure(int n, String idfValuesFile) throws IOException { this.n = n;//from ww w . j av a 2 s . c om URL resourceUrl = ResourceUtils.resolveLocation(idfValuesFile, this, null); idf = new HashMap<String, Double>(); for (String line : FileUtils.readLines(new File(resourceUrl.getFile()))) { String[] linesplit = line.split("\t"); idf.put(linesplit[0], Double.parseDouble(linesplit[1])); } }
From source file:hip.ch3.seqfile.writable.seqfile.SequenceFileStockWriter.java
/** * Write the sequence file./*from w w w . j a v a 2 s . c om*/ * * @param args the command-line arguments * @return the process exit code * @throws Exception if something goes wrong */ public int run(final String[] args) throws Exception { Cli cli = Cli.builder().setArgs(args).addOptions(CliCommonOpts.MrIoOpts.values()).build(); int result = cli.runCmd(); if (result != 0) { return result; } File inputFile = new File(cli.getArgValueAsString(CliCommonOpts.MrIoOpts.INPUT)); Path outputPath = new Path(cli.getArgValueAsString(CliCommonOpts.MrIoOpts.OUTPUT)); Configuration conf = super.getConf(); SequenceFile.Writer writer = //<co id="ch03_comment_seqfile_write1"/> SequenceFile.createWriter(conf, SequenceFile.Writer.file(outputPath), SequenceFile.Writer.keyClass(Text.class), SequenceFile.Writer.valueClass(StockPriceWritable.class), SequenceFile.Writer.compression(SequenceFile.CompressionType.BLOCK, new DefaultCodec())); try { Text key = new Text(); for (String line : FileUtils.readLines(inputFile)) { StockPriceWritable stock = StockPriceWritable.fromLine(line); System.out.println("Stock = " + stock); key.set(stock.getSymbol()); writer.append(key, stock); //<co id="ch03_comment_seqfile_write4"/> } } finally { writer.close(); } return 0; }
From source file:de.tudarmstadt.ukp.dkpro.keyphrases.core.evaluator.KeyphraseGoldStandardFilter.java
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { DocumentMetaData md = DocumentMetaData.get(jcas); String goldFile = md.getDocumentUri().substring(0, md.getDocumentUri().lastIndexOf(".")).replace("file:", "") + goldSuffix; System.out.println("Loading gold standard from " + goldFile); try {/*w w w .ja va 2s . com*/ List<String> keyphrases = FileUtils.readLines(new File(goldFile)); List<String> filteredKeyphrases = new ArrayList<String>(); List<String> lemmas = new ArrayList<String>(); for (Lemma lemma : JCasUtil.select(jcas, Lemma.class)) { lemmas.add(lemma.getValue().toLowerCase()); } List<String> tokens = new ArrayList<String>(); for (Token token : JCasUtil.select(jcas, Token.class)) { tokens.add(token.getCoveredText().toLowerCase()); } for (String keyphrase : keyphrases) { if (tokens.contains(keyphrase.toLowerCase()) || lemmas.contains(keyphrase.toLowerCase())) { filteredKeyphrases.add(keyphrase); } } FileUtils.writeLines(new File(goldFile + ".filtered"), filteredKeyphrases); } catch (IOException e) { throw new AnalysisEngineProcessException(e); } }
From source file:dkpro.similarity.algorithms.lsr.aggregate.MCS06AggregateComparator.java
/** * The constructor ideally should take a _Term_SimilarityMeasure as parameter, * not a _Text_SimilarityMeasure. However, as the LSR-based comparators are * implemented as the latter, we stick to that here, but use only the word- * relatedness function. /*from w w w . j ava 2 s . c o m*/ * @param measure The word similarity measure to use. * @throws IOException */ public MCS06AggregateComparator(TextSimilarityMeasure measure, File idfValuesFile) throws IOException { initialize(measure); // Read idf values idfValues = new HashMap<String, Double>(); for (String line : (List<String>) FileUtils.readLines(idfValuesFile)) { if (line.length() > 0) { String[] cols = line.split("\t"); idfValues.put(cols[0], Double.parseDouble(cols[1])); } } }
From source file:aes.pica.touresbalon.tb_serviciosbolivariano.ServiciosBolivarianos.java
@Override public List<ViajeVO> consultarViajes(String fechaViaje, String ciudadOrigen, String ciudadDestino) { List<ViajeVO> listaViajes = new ArrayList<>(); String nombreArchivo = Constantes.NAME_VIAJES + fechaViaje + Constantes.CSV_FILE; try {//from w ww.ja v a 2 s. com File archivoConsulta = FileUtils.getFile(rutaConsulta, nombreArchivo); if (archivoConsulta != null && archivoConsulta.exists()) { List<String> lineasArchivo = FileUtils.readLines(archivoConsulta); System.out.println("Archivo encontrado: " + archivoConsulta.getAbsoluteFile()); ViajeVO viajeAux; for (String s : lineasArchivo) { viajeAux = new ViajeVO(s); if (viajeAux.getCiudadOrigen().equalsIgnoreCase(ciudadOrigen) && viajeAux.getCiudadDestino().equalsIgnoreCase(ciudadDestino)) { listaViajes.add(viajeAux); } } } else { System.out.println("No existe archivo: " + nombreArchivo + " en el directorio: " + rutaConsulta); } } catch (IOException ex) { System.err.println(ex.toString()); } return listaViajes; }
From source file:de.tudarmstadt.ukp.dkpro.tc.testing.TestPairReader.java
@Override public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); fileOffset = 0;/*from ww w. j a va 2s . co m*/ texts1 = new ArrayList<String>(); texts2 = new ArrayList<String>(); try { for (String line : FileUtils.readLines(inputFile)) { String parts[] = line.split("\t"); if (parts.length != 2) { throw new ResourceInitializationException(new Throwable("Wrong file format: " + line)); } texts1.add(parts[0]); texts2.add(parts[1]); } } catch (IOException e) { throw new ResourceInitializationException(e); } }