/** * @deprecated Use instead {@link org.apache.commons.io.IOUtils#readLines(java.io.Reader)} */ @Deprecated public static List readLines(Reader input) throws IOException { return org.apache.commons.io.IOUtils.readLines(input); }
/** * @deprecated Use instead {@link org.apache.commons.io.IOUtils#readLines(java.io.InputStream)} */ @Deprecated public static List readLines(InputStream input) throws IOException { return org.apache.commons.io.IOUtils.readLines(input); }
/** * @deprecated Use instead {@link org.apache.commons.io.IOUtils#readLines(java.io.InputStream, String)} */ @Deprecated public static List readLines(InputStream input, String encoding) throws IOException { return org.apache.commons.io.IOUtils.readLines(input, encoding); }
private static Stream<String> configLines(InputStream is) throws IOException { return org.apache.commons.io.IOUtils.readLines(is, StandardCharsets.UTF_8).stream().filter(line -> !line.matches("#.*|\\s*")); }
/** * Gets the contents of an <code>InputStream</code> as a list of Strings, * one entry per line, using the default character encoding of the platform. * <p> * This method buffers the input internally, so there is no need to use a * <code>BufferedInputStream</code>. * * @param input the <code>InputStream</code> to read from, not null * @return the list of Strings, never null * @throws NullPointerException if the input is null * @throws IOException if an I/O error occurs * @since 1.1 * @deprecated 2.5 use {@link #readLines(InputStream, Charset)} instead */ @Deprecated public static List<String> readLines(final InputStream input) throws IOException { return readLines(input, Charset.defaultCharset()); }
private synchronized void reloadFromDefault() { try (InputStream is = StaticRoutingDecisionProvider.class.getResourceAsStream("default-whitelist.txt")) { whitelistSignaturesFromFixedList = new HashSet<>(); blacklistSignaturesFromFixedList = new HashSet<>(); parseFileIntoList( IOUtils.readLines(is, StandardCharsets.UTF_8), whitelistSignaturesFromFixedList, blacklistSignaturesFromFixedList ); } catch (IOException e) { throw new ExceptionInInitializerError(e); } LOGGER.log(Level.FINE, "Found {0} getter in the standard whitelist", whitelistSignaturesFromFixedList.size()); }
/** * Reads the contents of a file line by line to a List of Strings. * The file is always closed. * * @param file the file to read, must not be {@code null} * @param encoding the encoding to use, {@code null} means platform default * @return the list of Strings representing each line in the file, never {@code null} * @throws IOException in case of an I/O error * @since 2.3 */ public static List<String> readLines(final File file, final Charset encoding) throws IOException { try (InputStream in = openInputStream(file)) { return IOUtils.readLines(in, Charsets.toCharset(encoding)); } }
/** * Gets the contents of an <code>InputStream</code> as a list of Strings, * one entry per line, using the specified character encoding. * <p> * This method buffers the input internally, so there is no need to use a * <code>BufferedInputStream</code>. * * @param input the <code>InputStream</code> to read from, not null * @param encoding the encoding to use, null means platform default * @return the list of Strings, never null * @throws NullPointerException if the input is null * @throws IOException if an I/O error occurs * @since 2.3 */ public static List<String> readLines(final InputStream input, final Charset encoding) throws IOException { final InputStreamReader reader = new InputStreamReader(input, Charsets.toCharset(encoding)); return readLines(reader); }
public Object getResource() { try { List<String> lines = IOUtils.readLines(new FileInputStream(file)); return callback.execute(lines); } catch (Exception e) { LOG.warn("Error reading the stream ", e); } return null; } }
/** * Gets the contents of an <code>InputStream</code> as a list of Strings, * one entry per line, using the specified character encoding. * <p> * Character encoding names can be found at * <a href="http://www.iana.org/assignments/character-sets">IANA</a>. * <p> * This method buffers the input internally, so there is no need to use a * <code>BufferedInputStream</code>. * * @param input the <code>InputStream</code> to read from, not null * @param encoding the encoding to use, null means platform default * @return the list of Strings, never null * @throws NullPointerException if the input is null * @throws IOException if an I/O error occurs * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io * .UnsupportedEncodingException} in version 2.2 if the * encoding is not supported. * @since 1.1 */ public static List<String> readLines(final InputStream input, final String encoding) throws IOException { return readLines(input, Charsets.toCharset(encoding)); }
public static Long getFreePhysicalMem() { if (!OSInfo.isLinux()) { return 0L; } try { List<String> lines = IOUtils.readLines(new FileInputStream(PROCFS_MEMINFO)); String free = lines.get(1).split("\\s+")[1]; return Long.valueOf(free); } catch (Exception ignored) { LOG.warn("failed to get total free memory."); } return 0L; }
private static boolean processExists(String processName) throws Exception { Process ps = Runtime.getRuntime().exec(new String[] {"ps", "ax"}); InputStream psOutput = ps.getInputStream(); Process processGrep = Runtime.getRuntime().exec(new String[] {"grep", processName}); OutputStream processGrepInput = processGrep.getOutputStream(); IOUtils.copy(psOutput, processGrepInput); InputStream processGrepOutput = processGrep.getInputStream(); processGrepInput.close(); // Filter out the grep process itself. Process filterGrep = Runtime.getRuntime().exec(new String[] {"grep", "-v", "grep"}); OutputStream filterGrepInput = filterGrep.getOutputStream(); IOUtils.copy(processGrepOutput, filterGrepInput); filterGrepInput.close(); return IOUtils.readLines(filterGrep.getInputStream()).size() >= 1; }
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); } } writeToFile(fileList, false); } catch (Exception ignore) { } }
@Override public Map<String, Properties> getAllConfigsMap() { try { String rawConfigContent = Joiner.on("\n") .join(IOUtils.readLines(new FileReader(getConfigFile()))) .trim(); return ClientConfigUtil.readMultipleClientConfigAvro(rawConfigContent); } catch(IOException e) { logger.error(PROBLEM_READING_CONFIG_FILE, e); throw new RuntimeException(PROBLEM_READING_CONFIG_FILE, e); } }
@Initializer(after = InitMilestone.PLUGINS_PREPARED, before = InitMilestone.PLUGINS_STARTED, fatal = false) public static void load() throws IOException { Map<String, Boolean> overrides = ExtensionList.lookup(CustomClassFilter.class).get(Contributed.class).overrides; overrides.clear(); Enumeration<URL> resources = Jenkins.getInstance().getPluginManager().uberClassLoader.getResources("META-INF/hudson.remoting.ClassFilter"); while (resources.hasMoreElements()) { try (InputStream is = resources.nextElement().openStream()) { for (String entry : IOUtils.readLines(is, StandardCharsets.UTF_8)) { if (entry.matches("#.*|\\s*")) { // skip } else if (entry.startsWith("!")) { overrides.put(entry.substring(1), false); } else { overrides.put(entry, true); } } } } Logger.getLogger(Contributed.class.getName()).log(Level.FINE, "plugin-defined entries: {0}", overrides); }
private String readFile(Path file, Charset defaultEncoding) throws IOException { CharsetDetector detector = new CharsetDetector(file, defaultEncoding); assertThat(detector.run()).isTrue(); List<String> readLines = IOUtils.readLines(new InputStreamReader(detector.inputStream(), detector.charset())); return StringUtils.join(readLines, "\n"); }
@Test public void testReadLines_Reader() throws Exception { final File file = TestUtils.newFile(getTestDirectory(), "lines.txt"); Reader in = null; try { final String[] data = new String[] { "hello", "/u1234", "", "this is", "some text" }; TestUtils.createLineBasedFile(file, data); in = new InputStreamReader(new FileInputStream(file)); final List<String> lines = IOUtils.readLines(in); assertEquals(Arrays.asList(data), lines); assertEquals(-1, in.read()); } finally { IOUtils.closeQuietly(in); TestUtils.deleteFile(file); } }
@Test public void read_file_source() throws Exception { ScannerReportWriter writer = new ScannerReportWriter(dir); try (FileOutputStream outputStream = new FileOutputStream(writer.getSourceFile(1))) { IOUtils.write("line1\nline2", outputStream); } try (InputStream inputStream = FileUtils.openInputStream(underTest.readFileSource(1))) { assertThat(IOUtils.readLines(inputStream)).containsOnly("line1", "line2"); } }
@Test public void testReadLines_InputStream() throws Exception { final File file = TestUtils.newFile(getTestDirectory(), "lines.txt"); InputStream in = null; try { final String[] data = new String[] { "hello", "world", "", "this is", "some text" }; TestUtils.createLineBasedFile(file, data); in = new FileInputStream(file); final List<String> lines = IOUtils.readLines(in); assertEquals(Arrays.asList(data), lines); assertEquals(-1, in.read()); } finally { IOUtils.closeQuietly(in); TestUtils.deleteFile(file); } }
@Test public void testReadLines_InputStream_String() throws Exception { final File file = TestUtils.newFile(getTestDirectory(), "lines.txt"); InputStream in = null; try { final String[] data = new String[] { "hello", "/u1234", "", "this is", "some text" }; TestUtils.createLineBasedFile(file, data); in = new FileInputStream(file); final List<String> lines = IOUtils.readLines(in, "UTF-8"); assertEquals(Arrays.asList(data), lines); assertEquals(-1, in.read()); } finally { IOUtils.closeQuietly(in); TestUtils.deleteFile(file); } }