List of usage examples for org.apache.commons.io FileUtils readLines
public static List readLines(File file, String encoding) throws IOException
From source file:com.xeiam.datasets.hjabirdsong.bootstrap.RawData2DB.java
private void go(String labelsFile, String wavNameFile) throws IOException { List<String> labelsLines = FileUtils.readLines(new File(labelsFile), "UTF-8"); List<String> wavNameLines = FileUtils.readLines(new File(wavNameFile), "UTF-8"); for (int i = 0; i < labelsLines.size(); i++) { String labelLine = labelsLines.get(i); String wavNameLine = wavNameLines.get(i); // System.out.println(labelLine); // System.out.println(wavNameLine); String bagIDString = labelLine.substring(0, labelLine.indexOf(",")); String labelsCSV = labelLine.substring(labelLine.indexOf(",") + 1, labelLine.length()); String wavFileName = wavNameLine.substring(wavNameLine.indexOf(",") + 1, wavNameLine.length()) + ".wav"; InputStream fis = null;//from w ww . j a v a2 s . c o m try { // the Wav file Bytes File srcFile = new File("./raw/wav/" + wavFileName); fis = new FileInputStream(srcFile); byte[] buffer = new byte[(int) srcFile.length()]; fis.read(buffer, 0, buffer.length); HJABirdSong hJABirdSong = new HJABirdSong(); hJABirdSong.setBagid(Integer.parseInt(bagIDString)); hJABirdSong.setLabels(labelsCSV); hJABirdSong.setWavfilename(wavFileName); hJABirdSong.setWavbytes(new SerialBlob(buffer)); HJABirdsongDAO.insert(hJABirdSong); // System.out.println(hJABirdSong.toString()); idx++; } catch (Exception e) { e.printStackTrace(); // eat it. skip first line in file. } finally { if (fis != null) { fis.close(); } } } System.out.println("Number parsed: " + idx); }
From source file:com.edgenius.test.TestMain.java
protected List<TestItem> readTestcaseFile(String filename) throws IOException { System.out.println(/* w w w . j av a2 s. co m*/ "Load test file from URL:" + this.getClass().getClassLoader().getResource("testcase/" + filename)); URL url = this.getClass().getClassLoader().getResource("testcase/" + filename); TestItem item = null; int exp = 0; boolean withNewline = false; List<String> lines; try { lines = FileUtils.readLines(new File(url.toURI()), "UTF8"); } catch (URISyntaxException e) { throw new IOException(e.toString()); } List<TestItem> testcases = new ArrayList<TestItem>(); for (String line : lines) { if (!"".equals(line)) { if (line.startsWith("REM ")) continue; if (line.startsWith("===========")) { if (item != null) { testcases.add(item); } item = null; exp = 1; withNewline = false; continue; } if (line.startsWith("----------")) { exp = 2; withNewline = false; continue; } } if (exp == 1) { //if it is after first line of input if (withNewline) { item.expected += "\n"; } else { withNewline = true; } if (item == null) item = new TestItem(); item.expected += line; } else if (exp == 2) { //if it is after first line of input if (withNewline) { item.input += "\n"; } else { withNewline = true; } item.input += line; } } if (item != null) testcases.add(item); return testcases; }
From source file:gda.jython.logger.RedirectableFileLoggerTest.java
private String readLogLine(String filepath, int i) throws IOException { String line;//from ww w .j av a2 s .c o m try { line = (String) FileUtils.readLines(new File(filepath), "utf-8").get(i); } catch (IndexOutOfBoundsException e) { return "NOSUCHLINE"; } return line.split("(\\| )")[1]; // split off the date preceding "| " }
From source file:com.textocat.textokit.morph.opencorpora.MorphologyDictionaryLookup.java
private void run() throws Exception { // read dictionary MorphDictionary dict = DictionaryDeserializer.from(serializedDictFile); for (File srcFile : srcFiles) { // read input List<String> srcLines = FileUtils.readLines(srcFile, "utf-8"); // prepare output File outFile = getOutFile(srcFile); out = IoUtils.openPrintWriter(outFile); try {//from www .j a va2 s .c o m for (String s : srcLines) { s = s.trim(); if (s.isEmpty()) { continue; } s = WordUtils.normalizeToDictionaryForm(s); List<Wordform> sEntries = dict.getEntries(s); if (sEntries == null || sEntries.isEmpty()) { writeEntry(s, "?UNKNOWN?"); continue; } for (Wordform se : sEntries) { BitSet gramBits = getAllGramBits(se, dict); List<String> grams = dict.getGramModel().toGramSet(gramBits); writeEntry(s, grams); } } } finally { IOUtils.closeQuietly(out); } } }
From source file:com.javacreed.examples.sc.part3.MembersServiceImpl.java
@Override @CacheEvict(value = "members", allEntries = true) public void saveMember(final Member member) { try {/*from ww w . j a v a 2 s.c om*/ final StringBuilder toSave = new StringBuilder(); for (final String line : FileUtils.readLines(dataFile, "UTF-8")) { final String[] parts = line.split(","); final int memberId = Integer.parseInt(parts[0]); if (memberId == member.getMemberId()) { toSave.append(memberId).append(",").append(member.getMemberName()).append("\n"); } else { toSave.append(line).append("\n"); } } FileUtils.write(new File("members.txt"), toSave.toString().trim(), "UTF-8"); } catch (final Exception e) { throw new RuntimeException("Failed to save members", e); } }
From source file:jp.igapyon.selecrawler.SeleCrawlerSettings.java
public List<String> getUrllistWaitRegex() throws IOException { if (waitRegexList == null) { waitRegexList = FileUtils.readLines(new File(getPathUrllistWaitRegexTxt()), "UTF-8"); }// w w w. j av a2 s . c om return waitRegexList; }
From source file:jp.igapyon.selecrawler.SeleCrawlerWebContentNewUrlFinder.java
public void process(final SeleCrawlerSettings settings) throws IOException { this.settings = settings; System.err.println("[jp.igapyon.selecrawler] Find new url from fetched contents."); final List<String> urlList = new ArrayList<String>(); processGatherUrl(urlList);/* w ww. ja v a 2 s. c o m*/ Collections.sort(urlList); // remove duplicated urls for (int index = 1; index < urlList.size(); index++) { if (urlList.get(index - 1).equals(urlList.get(index))) { urlList.remove(index--); } } // remove if already registered. { final List<String> registeredList = FileUtils.readLines(new File(settings.getPathUrllisttTxt()), "UTF-8"); final Map<String, String> registeredMap = new HashMap<String, String>(); for (String urlRegistered : registeredList) { registeredMap.put(urlRegistered, urlRegistered); } for (int index = 0; index < urlList.size(); index++) { if (registeredMap.get(urlList.get(index)) != null) { // remove registered url. urlList.remove(index--); } } } // remove it if it is marked as exclude for (int index = 0; index < urlList.size(); index++) { final String url = urlList.get(index); final List<String> excludeRegexList = FileUtils .readLines(new File(settings.getPathUrllistExcludeRegexTxt()), "UTF-8"); for (String regex : excludeRegexList) { final Pattern pat = Pattern.compile(regex); final Matcher mat = pat.matcher(url); if (mat.find()) { // remove registered url. urlList.remove(index--); } } } final File newurlcandidate = new File(new File(settings.getPathTargetDir()), SeleCrawlerConstants.EXT_SC_NEWURLCANDIDATE); System.err.println( "[selecrawler] create/update new url candidate file: " + newurlcandidate.getCanonicalPath()); FileUtils.writeLines(newurlcandidate, urlList); }
From source file:at.medevit.elexis.gdt.handler.GDTFileInputHandler.java
public static String[] readFileGetUTF8(File file) { int encoding = GDTConstants.ZEICHENSATZ_IBM_CP_437; try {/*from w w w .j a v a 2s. c o m*/ List<String> dataList = FileUtils.readLines(file, "cp437"); String[] data = dataList.toArray(new String[] {}); String usedEncoding = GDTSatzNachrichtHelper .getValueIfExists(GDTConstants.FELDKENNUNG_VERWENDETER_ZEICHENSATZ, data); if (usedEncoding == null) return data; // Not set return default encoding int usedEncodingInt = Integer.parseInt(usedEncoding); if (encoding == usedEncodingInt) return data; // Set, but default if (usedEncodingInt == GDTConstants.ZEICHENSATZ_7BIT) { return FileUtils.readLines(file, GDTConstants.ZEICHENSATZ_7BIT_CHARSET_STRING) .toArray(new String[] {}); } else if (usedEncodingInt == GDTConstants.ZEICHENSATZ_ISO8859_1_ANSI_CP_1252) { return FileUtils.readLines(file, "Cp1252").toArray(new String[] {}); } } catch (IOException e) { String message = "GDT: Ein-/Ausgabe Fehler beim Lesen von " + file.getAbsolutePath(); Status status = new Status(IStatus.WARNING, Activator.PLUGIN_ID, message, e); StatusManager.getManager().handle(status, StatusManager.SHOW); logger.log(e, message, Log.WARNINGS); } return null; }
From source file:com.l2jfree.loginserver.manager.BanManager.java
/** * Load banned list//from w w w. j av a2 s. c o m * */ public void load() { try { _bannedIps.clear(); _restrictedIps.clear(); // try to read banned list File file = new File(BAN_LIST); List<?> lines = FileUtils.readLines(file, ENCODING); for (int i = 0; i < lines.size(); i++) { String line = (String) lines.get(i); line = line.trim(); if (line.length() > 0 && !line.startsWith("#")) { addBannedIP(line); } } _log.info("BanManager: Loaded."); _log.info(" - temporary banned IPs:" + getTempBanCount()); _log.info(" - forever banned IPs:" + getEternalBanCount()); } catch (IOException e) { _log.warn("BanManager: Cannot read IP list: ", e); } }
From source file:core.test.server.mock.util.PersonNameUtil.java
/** * initialize femail names from file/* w w w. ja v a 2 s. c o m*/ * @throws IOException * */ private void initializeFemaleNames() throws IOException { URL url = getClass().getClassLoader().getResource("people-names/female-names.txt"); File file = new File(url.getFile()); femaleNames = FileUtils.readLines(file, "UTF-8"); }