APISonar


org.apache.commons.io.IOUtils.readLines

> org > apache > commons > io > IOUtils > readLines
org APIs apache APIs commons APIs io APIs IOUtils APIs readLines APIs

Example 1
public static List<String> readLines(InputStream is) {
        List<String> lines = null;
        try {
            lines = IOUtils.readLines(is);
        } catch (IOException ex) {
            throw new UnexpectedException(ex);
        }
        return lines;
    }
Example 2
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");
  }
Example 3
private String readPasswordFromFile(final String passwordFileName) throws IOException {

		try (final InputStream is = new FileInputStream(passwordFileName)) {

			final List<String> lines = IOUtils.readLines(is, "utf-8");

			if (!lines.isEmpty()) {

				return lines.get(0);
			}
		}

		return "";
	}
Example 4
private void dump(File file) throws IOException {
    try (FileInputStream in = new FileInputStream(file)) {
      for (String line : IOUtils.readLines(in)) {
        println(line);
      }
    }
  }
Example 5
private void checkOutputFile(String fileName) throws IOException {
		@SuppressWarnings("resource")
		List<String> outputLines = IOUtils.readLines(new FileInputStream(fileName), "UTF-8");

		String output = "";
		for (String line : outputLines) {
			output += line;
		}

		assertEquals(EXPECTED_OUTPUT_FILE, output);
	}
Example 6
private static final List<String> lines(Resource dir, String path) throws IOException {
        try (InputStream input = dir.get(path).in()) {
            return IOUtils.readLines(input, StandardCharsets.UTF_8);
        }
    }
Example 7
public static String readToEnd(InputStream input) throws IOException {
        try {
            @SuppressWarnings("unchecked") List<String> list = IOUtils.readLines(input);
            StringBuilder builder = new StringBuilder();
            for (String line : list) {
                builder.append(line);
                builder.append(lineSeparator());
            }
            return builder.toString().trim();
        } finally {
            IOUtils.closeQuietly(input);
        }
    }
Example 8
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);
        }
    }
Example 9
private String implementationVersionFromManifrest(URL log4jJarFromClasspath) throws IOException {
        JarInputStream in = new JarInputStream(log4jJarFromClasspath.openStream());
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        in.getManifest().write(out);
        out.close();

        List<String> lines = IOUtils.readLines(new ByteArrayInputStream(out.toByteArray()));
        for (String line : lines) {
            if (line.startsWith("Implementation-Version")) {
                 return line.split(":")[1].trim();
            }
        }
        return null;
    }
Example 10
protected void loadConfigFromStream(InputStream in) throws IOException {
		config = new Properties();
		try {
			byte[] byteArray = IOUtils.toByteArray(in);
			config.load(new ByteArrayInputStream(byteArray));
			originalConfig = IOUtils.readLines(new ByteArrayInputStream(byteArray), "UTF-8");
		} finally {
			in.close();
		}
	}
Example 11
private static Map<Integer, String> readEnumCSV(String csvFileClasspath) {
        try {
            List<String> lines = IOUtils.readLines(new FileInputStream(new File(dataLocalPath, csvFileClasspath)), StandardCharsets.UTF_8);
            Map<Integer, String> enums = new HashMap<>();
            for (String line : lines) {
                String[] parts = line.split(",");
                enums.put(Integer.parseInt(parts[0]), parts[1]);
            }
            return enums;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
Example 12
private void testArguments(String... args) throws IOException, InterruptedException, TimeoutException {
    byte[] bytes = printArguments(args).execute().output();
    List<String> expected = Arrays.asList(args);
    List<String> actual = IOUtils.readLines(new ByteArrayInputStream(bytes));
    Assert.assertEquals(expected, actual);
  }
Example 13
public void get_content_for_xml_file() {
    initModel();
    Reader xmlFileReader = null;
    try {
      xmlFileReader = underTest.createReaderForXMLFile("csharp");
      assertNotNull(xmlFileReader);
      List<String> lines = IOUtils.readLines(xmlFileReader);
      assertThat(lines.size()).isEqualTo(25);
      assertThat(lines.get(0)).isEqualTo("<sqale>");
    } catch (Exception e) {
      fail("Should be able to read the XML file.");
    } finally {
      IOUtils.closeQuietly(xmlFileReader);
    }
  }
Example 14
public void testSaveDataToCacheAndReturnData() throws Exception {
        inFileStringObjectPersister.saveDataToCacheAndReturnData(TEST_DATA, TEST_CACHE_KEY);

        File cachedFile = inFileStringObjectPersister.getCacheFile(TEST_CACHE_KEY);
        assertTrue(cachedFile.exists());

        @SuppressWarnings("unchecked")
        List<String> actual = IOUtils.readLines(new FileInputStream(cachedFile), CharEncoding.UTF_8);
        assertEquals(1, actual.size());
        assertEquals(TEST_DATA, actual.get(0));
    }
Example 15
protected String jsonFromFile(final String path) throws IOException {
        return IOUtils.readLines(StreamUtil.openStream(getClass(), path))
                .stream()
                .collect(Collectors.joining("\n"));
    }
Example 16
String readKeyFromFile(URL url, int majorVersion) throws IOException {
        String majorVersionStr = String.valueOf(majorVersion);
        List<String> lines = IOUtils.readLines(url.openStream());
        String defaultKey = null;
        for (String line : lines) {
            String[] parts = line.split("\\s*=\\s*");
            if (parts.length < 2) {
                defaultKey = parts[0].trim();
            }
            if (parts[0].equals(majorVersionStr)) {
                return parts[1].trim();
            }
        }
        return defaultKey;
    }
Example 17
private Map<String, String> load(File file) throws IOException {
        Map<String, String> config = new LinkedHashMap<String, String>();
        FileInputStream is = new FileInputStream(file);
        List<String> lines = IOUtils.readLines(is);
        for (String line : lines) {
            String[] parameterPair = line.split("=");
            if (parameterPair.length == 2) {
                config.put(parameterPair[0].trim(), parameterPair[1].trim());
            } else {
                config.put(parameterPair[0], "");
            }
        }
        IOUtils.closeQuietly(is);
        return config;
    }
Example 18
public static void main(String[] args) throws Exception {
      values = createValuesList(keys);
      File carsFile = new File("../example/cars/data/cars.json");
      File resultFile = new File("test_data.json");
      FileWriter fileWriter = new FileWriter(resultFile, true);
      
      for (String line : IOUtils.readLines(new FileInputStream(carsFile))) {
        line = line.replaceFirst(",", formDocEntry(numOfElementsPerDoc));
        fileWriter.append(line + "\n");
      }
      fileWriter.close();
      
      String value  = formDocEntry(numOfElementsPerDoc);
      
    }
Example 19
private static String getArtemisVersion() throws IOException {
		InputStream is = EclipseProcessorCommand.class.getResourceAsStream("/artemis-version.txt");
		return IOUtils.readLines(is).get(0);
	}
Example 20
public void testSimple() {

        String javasource = null;
        try {
            List<String> lines = IOUtils.readLines(Thread.currentThread().getContextClassLoader().getResourceAsStream("compiler.txt"));
            javasource = StringUtils.join(lines, "\n");
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        JdkCompiler compiler = new JdkCompiler();

        Class<?> clazz = compiler.compile(javasource);
        System.out.println(clazz.getName());
    }
Example 21
public byte[] processHtml(Resource resource, Book book, String outputEncoding) throws IOException {
		Reader reader = resource.getReader();
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		Writer writer = new OutputStreamWriter(out, Constants.CHARACTER_ENCODING);
		for(String line: IOUtils.readLines(reader)) {
			writer.write(processLine(line));
			writer.flush();
		}
		return out.toByteArray();
	}
Example 22
public static List<String> readFile(Configuration config, String path) throws IOException {
    Path inPath = new Path(path);
    FileSystem fs = FileSystem.get(inPath.toUri(), config);
    try (FSDataInputStream inputStream = fs.open(inPath)) {
      return IOUtils.readLines(inputStream, "UTF-8");
    }
  }
Example 23
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;
    }
Example 24
public void create() throws Exception {
        if (getRepository().count() == 0) {
            Resource resource = new ClassPathResource(IMPORT_SQL);
            List<String> lines = IOUtils.readLines(resource.getInputStream());
            String[] array = new String[lines.size()];
            jdbcTemplate.batchUpdate(lines.toArray(array));
        }
    }
Example 25
private String removeIndentation(String s) throws IOException {
        List<String> lines = IOUtils.readLines(new ByteArrayInputStream(s
                .getBytes()));
        List<String> lines2 = new LinkedList<String>();
        for (String line : lines) {
            lines2.add(line.trim());
        }
        return StringUtils.join(lines2, "\n");
    }