List of usage examples for org.apache.commons.io IOUtils readLines
public static List readLines(Reader input) throws IOException
Reader
as a list of Strings, one entry per line. From source file:com.r573.enfili.common.io.file.FileHelper.java
public static String readTextFromStream(InputStream stream) { try {//from w ww .jav a2s . c om List<String> lines = IOUtils.readLines(stream); StringBuilder sb = new StringBuilder(); for (String line : lines) { sb.append(line); sb.append("\n"); } return sb.toString(); } catch (IOException e) { throw new FileOpException(e); } }
From source file:com.thoughtworks.go.agent.bootstrapper.LauncherTempFileHandler.java
private void reapFiles() { try (FileReader tmpFileReader = new FileReader(LAUNCHER_TMP_FILE_LIST)) { List<String> fileList = IOUtils.readLines(tmpFileReader); Set<String> fileSet = new HashSet<>(fileList); for (String fileName : fileSet) { File file = new File(fileName); FileUtils.deleteQuietly(file); File depsDir = new File(FileUtil.TMP_PARENT_DIR, fileName); FileUtils.deleteQuietly(depsDir); if (!file.exists() && !depsDir.exists()) { fileList.remove(fileName); }/* w ww. j av a 2 s. c o m*/ } writeToFile(fileList, false); } catch (Exception ignore) { } }
From source file:au.org.ala.delta.util.LocalConfigFiles.java
private File getFile(String filename, String resourcePath) { File f = new File( String.format("%s%s%s", getSettingsDirectory().getAbsolutePath(), File.separator, filename)); if (!f.exists()) { InputStream is = LocalConfigFiles.class.getResourceAsStream(resourcePath); if (is != null) { try { List<String> lines = IOUtils.readLines(is); FileWriter writer = new FileWriter(f); IOUtils.writeLines(lines, LINE_ENDING, writer); writer.flush();/*from www . j av a2 s. c om*/ writer.close(); } catch (IOException ioex) { throw new RuntimeException(ioex); } } } return f; }
From source file:com.webstersmalley.countdown.words.WordCounter.java
public void parseResource(String location) { long startTime = System.currentTimeMillis(); InputStream is = null;//from w w w.j a v a 2s .co m try { is = getClass().getResourceAsStream(location); List<String> words = IOUtils.readLines(is); for (String word : words) { parseLine(word); } } catch (Exception e) { logger.error("Error getting count: ", e); throw new RuntimeException("Error getting count: ", e); } finally { IOUtils.closeQuietly(is); } long endTime = System.currentTimeMillis(); logger.info("Parse of " + location + " complete. Time taken: " + (endTime - startTime) + "ms."); }
From source file:com.blogspot.jabelarminecraft.blocksmith.VersionChecker.java
@Override public void run() { InputStream in = null;/*from w ww .ja v a 2s .c o m*/ try { in = new URL( "https://raw.githubusercontent.com/jabelar/MagicBeans-1.7.10/master/src/main/java/com/blogspot/jabelarminecraft/magicbeans/version_file") .openStream(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { latestVersion = IOUtils.readLines(in).get(0); // toString(in); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { IOUtils.closeQuietly(in); } System.out.println("Latest mod version = " + latestVersion); isLatestVersion = BlockSmith.MODVERSION.equals(latestVersion); System.out.println("Are you running latest version = " + isLatestVersion); }
From source file:com.blogspot.jabelarminecraft.magicbeans.VersionChecker.java
@Override public void run() { InputStream in = null;/*w ww.j a va 2s. c om*/ try { in = new URL( "https://raw.githubusercontent.com/jabelar/MagicBeans-1.7.10/master/src/main/java/com/blogspot/jabelarminecraft/magicbeans/version_file") .openStream(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { latestVersion = IOUtils.readLines(in).get(0); // toString(in); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { IOUtils.closeQuietly(in); } System.out.println("Latest mod version = " + latestVersion); isLatestVersion = MagicBeans.MODVERSION.equals(latestVersion); System.out.println("Are you running latest version = " + isLatestVersion); }
From source file:com.blogspot.jabelarminecraft.movinglightsource.VersionChecker.java
@Override public void run() { InputStream in = null;/*from w w w . j a v a 2 s .c o m*/ try { in = new URL( "https://raw.githubusercontent.com/jabelar/MovingLightSource-1.8/master/src/main/java/com/blogspot/jabelarminecraft/movinglightsource/version_file") .openStream(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { latestVersion = IOUtils.readLines(in).get(0); // toString(in); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { IOUtils.closeQuietly(in); } // DEBUG System.out.println( "Current version is " + MovingLightSource.MODVERSION + " and latest version is " + latestVersion); isLatestVersion = MovingLightSource.MODVERSION.compareTo(latestVersion) >= 0; System.out.println("Are you running latest version = " + isLatestVersion); }
From source file:eu.delving.x3ml.TestBase.java
@Test public void testReadWrite() throws IOException { String xml = engine("/base/base.x3ml").toString(); String[] lines = xml.split("\n"); List<String> serialized = new ArrayList<String>(); List<String> originalLines = IOUtils.readLines(resource("/base/base.x3ml")); List<String> original = new ArrayList<String>(); boolean ignore = false; int index = 0; for (String orig : originalLines) { orig = orig.trim();//www . ja v a2s . com if (orig.startsWith("<!--")) continue; if (orig.startsWith("<comments") || orig.startsWith("<info")) ignore = true; if (!ignore) { serialized.add(lines[index].trim()); original.add(orig); index++; } if (orig.startsWith("</comments") || orig.startsWith("</info")) ignore = false; } Assert.assertEquals("Mismatch", StringUtils.join(original, "\n"), StringUtils.join(serialized, "\n")); }
From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.helpers.boilerplateremoval.impl.Utils.java
/** * load the stop-words list of a given language * * @param locale//from w w w.j av a 2s. c om * @return * @throws URISyntaxException * @throws IOException */ public static Set<String> loadStopWords(Locale locale) throws IOException { String streamName = "/stoplists/" + locale.getLanguage() + ".txt"; InputStream stream = Utils.class.getResourceAsStream(streamName); if (stream == null) { throw new IOException("Stream " + streamName + " not found"); } List<String> stopList = IOUtils.readLines(stream); HashSet<String> stopSet = new HashSet<String>(stopList); return stopSet; }
From source file:com.gameminers.mav.firstrun.TeachSphinxThread.java
@Override public void run() { try {/*from w ww . ja v a 2 s. c om*/ File training = new File(Mav.configDir, "training-data"); training.mkdirs(); while (Mav.silentFrames < 30) { sleep(100); } Mav.listening = true; InputStream prompts = ClassLoader.getSystemResourceAsStream("resources/sphinx/train/arcticAll.prompts"); List<String> arctic = IOUtils.readLines(prompts); IOUtils.closeQuietly(prompts); Mav.audioManager.playClip("listen1"); byte[] buf = new byte[2048]; int start = 0; int end = 21; AudioInputStream in = Mav.audioManager.getSource().getAudioInputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); while (true) { for (int i = start; i < end; i++) { baos.reset(); String prompt = arctic.get(i); RenderState.setText("\u00A7LRead this aloud:\n" + Fonts.wrapStringToFit( prompt.substring(prompt.indexOf(':') + 1), Fonts.base[1], Display.getWidth())); File file = new File(training, prompt.substring(0, prompt.indexOf(':')) + ".wav"); file.createNewFile(); int read = 0; while (Mav.silentListenFrames > 0) { read = Mav.audioManager.getSource().getAudioInputStream().read(buf); } baos.write(buf, 0, read); while (Mav.silentListenFrames < 60) { in.read(buf); if (read == -1) { RenderState.setText( "\u00A7LAn error occurred\nUnexpected end of stream\nPlease restart Mav"); RenderState.targetHue = 0; return; } baos.write(buf, 0, read); } AudioSystem.write(new AudioInputStream(new ByteArrayInputStream(baos.toByteArray()), in.getFormat(), baos.size() / 2), AudioFileFormat.Type.WAVE, file); Mav.audioManager.playClip("notif2"); } Mav.ttsInterface.say(Mav.phoneticUserName + ", that should be enough for now. Do you want to keep training anyway?"); RenderState.setText("\u00A7LOkay, " + Mav.userName + "\nI think that should be\nenough. Do you want to\nkeep training anyway?\n\u00A7s(Say 'Yes' or 'No' out loud)"); break; //start = end+1; //end += 20; } } catch (Exception e) { e.printStackTrace(); } }