Java Code Examples for org.apache.commons.io.IOUtils.readLines()

The following are Jave code examples for showing how to use readLines() of the org.apache.commons.io.IOUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: argument-reasoning-comprehension-task   File: ClassificationMain.java   View Source Code Vote up 6 votes
public static Set<SingleInstance> loadData(File file)
        throws IOException
{
    Set<SingleInstance> result = new HashSet<>();

    List<String> lines = IOUtils
            .readLines(new InputStreamReader(new FileInputStream(file), "utf-8"));

    for (String line : lines) {
        if (!line.startsWith("#")) {
            result.add(new SingleInstance(line));
        }
    }

    // make sure there are all instances (minus one for the comment line)
    if (result.size() != (lines.size() - 1)) {
        throw new IllegalStateException("Inconsistent input");
    }

    return result;
}
 
Example 2
Project: DecompiledMinecraft   File: Locale.java   View Source Code Vote up 6 votes
private void loadLocaleData(InputStream p_135021_1_) throws IOException
{
    for (String s : IOUtils.readLines(p_135021_1_, Charsets.UTF_8))
    {
        if (!s.isEmpty() && s.charAt(0) != 35)
        {
            String[] astring = (String[])Iterables.toArray(splitter.split(s), String.class);

            if (astring != null && astring.length == 2)
            {
                String s1 = astring[0];
                String s2 = pattern.matcher(astring[1]).replaceAll("%$1s");
                this.properties.put(s1, s2);
            }
        }
    }
}
 
Example 3
Project: dubbo-mock   File: BootStartServer.java   View Source Code Vote up 6 votes
private void initSql() {
	try {
		Connection conn = mockDataSource.getConnection();
		Statement stmt = conn.createStatement();

		List<String> aa = IOUtils.readLines(getClass().getClassLoader().getResourceAsStream("sqlite.sql"));
		String s = StringUtils.join(aa, "\r\n");
		String[] sqls = s.split(";");

		for (int i = 0; i < sqls.length; i++) {
			String sql = sqls[i];
			System.out.println("初始化sql : " + sql);
			stmt.execute(sql);
		}
		stmt.close();
		conn.close();
	} catch (Exception e) {
	}
}
 
Example 4
Project: TOSCAna   File: AbstractLifecycle.java   View Source Code Vote up 6 votes
private void setUpDirectories(PluginFileAccess access) throws IOException {
    access.createDirectories(UTIL_DIR_PATH);

    //Iterate over all files in the script list
    List<String> files = IOUtils.readLines(
        getClass().getResourceAsStream(RESOURCE_PATH_BASE + "scripts-list"),
        Charsets.UTF_8
    );
    for (String line : files) {
        if (!line.isEmpty()) {
            //Copy the file into the desired directory
            InputStreamReader input = new InputStreamReader(
                getClass().getResourceAsStream(RESOURCE_PATH_BASE + line)
            );
            BufferedWriter output = access.access(UTIL_DIR_PATH + line);
            IOUtils.copy(input, output);
            input.close();
            output.close();
        }
    }
}
 
Example 5
Project: CustomWorldGen   File: Locale.java   View Source Code Vote up 6 votes
private void loadLocaleData(InputStream inputStreamIn) throws IOException
{
    inputStreamIn = net.minecraftforge.fml.common.FMLCommonHandler.instance().loadLanguage(properties, inputStreamIn);
    if (inputStreamIn == null) return;
    for (String s : IOUtils.readLines(inputStreamIn, Charsets.UTF_8))
    {
        if (!s.isEmpty() && s.charAt(0) != 35)
        {
            String[] astring = (String[])Iterables.toArray(SPLITTER.split(s), String.class);

            if (astring != null && astring.length == 2)
            {
                String s1 = astring[0];
                String s2 = PATTERN.matcher(astring[1]).replaceAll("%$1s");
                this.properties.put(s1, s2);
            }
        }
    }
}
 
Example 6
Project: Backmemed   File: Locale.java   View Source Code Vote up 6 votes
private void loadLocaleData(InputStream inputStreamIn) throws IOException
{
    for (String s : IOUtils.readLines(inputStreamIn, Charsets.UTF_8))
    {
        if (!s.isEmpty() && s.charAt(0) != 35)
        {
            String[] astring = (String[])Iterables.toArray(SPLITTER.split(s), String.class);

            if (astring != null && astring.length == 2)
            {
                String s1 = astring[0];
                String s2 = PATTERN.matcher(astring[1]).replaceAll("%$1s");
                this.properties.put(s1, s2);
            }
        }
    }
}
 
Example 7
Project: semeval2018-task12   File: ClassificationMain.java   View Source Code Vote up 6 votes
public static Set<LabeledInstance> loadTrainingData(InputStream inputStream)
        throws IOException
{
    Set<LabeledInstance> result = new HashSet<>();

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

    for (String line : lines) {
        if (!line.startsWith("#")) {
            result.add(new LabeledInstance(line));
        }
    }

    return result;
}
 
Example 8
Project: Backmemed   File: LanguageMap.java   View Source Code Vote up 5 votes
public LanguageMap()
{
    try
    {
        InputStream inputstream = LanguageMap.class.getResourceAsStream("/assets/minecraft/lang/en_us.lang");

        for (String s : IOUtils.readLines(inputstream, Charsets.UTF_8))
        {
            if (!s.isEmpty() && s.charAt(0) != 35)
            {
                String[] astring = (String[])Iterables.toArray(EQUAL_SIGN_SPLITTER.split(s), String.class);

                if (astring != null && astring.length == 2)
                {
                    String s1 = astring[0];
                    String s2 = NUMERIC_VARIABLE_PATTERN.matcher(astring[1]).replaceAll("%$1s");
                    this.languageList.put(s1, s2);
                }
            }
        }

        this.lastUpdateTimeInMilliseconds = System.currentTimeMillis();
    }
    catch (IOException var7)
    {
        ;
    }
}
 
Example 9
Project: dragoman   File: CannedDatasetsLoaderImpl.java   View Source Code Vote up 5 votes
/**
 * Loads {@link CannedDataset}s from the classpath with the given {@code rootAddress} being the
 * address from which to load them. It is expected that the {@code rootAddress} will contains a
 * file named {@code table-of-contents.txt} and this file will list the files to be loaded. Each
 * file represents a single {@link CannedDataset}. This might sounds odd; why not just interrogate
 * a folder and load the files found therein? Well, that's not a runner when the canned dataset
 * resources are bundled inside the application JAR. Since we have to cater for the dataset
 * resources beingbundled inside the application JAR we use this table-of-contents approach.
 *
 * @param rootAddress the root address for the serialised representations of the {@link
 *     CannedDataset} instances
 * @return deserialised {@link CannedDataset} representations
 */
@Override
public List<CannedDataset> load(String rootAddress) {
  List<CannedDataset> cannedDatasets = Lists.newArrayList();

  try {
    logger.info("Looking for canned datasets from: {}", rootAddress + "/table-of-contents.txt");

    InputStream resourceAsStream =
        this.getClass().getResourceAsStream(rootAddress + "/" + TABLE_OF_CONTENTS);
    if (resourceAsStream != null) {
      List<String> tableOfContents =
          IOUtils.readLines(resourceAsStream, Charset.forName("UTF-8"));

      logger.info("Loading canned datasets: {}", Joiner.on(",").join(tableOfContents));

      for (String cannedDatasetFileName : tableOfContents) {
        Optional<CannedDataset> cannedDataset =
            loadCannedDataset(rootAddress + "/" + cannedDatasetFileName);
        if (cannedDataset.isPresent()) {
          cannedDatasets.add(cannedDataset.get());
        }
      }
    } else {
      logger.warn(
          "A canned datasets directory ({}) was supplied but it does not contain {} so no canned "
              + "datasets can be loaded!",
          rootAddress,
          TABLE_OF_CONTENTS);
    }

    logger.info("Loaded {} canned datasets from {}", cannedDatasets.size(), rootAddress);

    return cannedDatasets;
  } catch (Exception ex) {
    throw new RuntimeException(format("Failed to read files from: %s", rootAddress), ex);
  }
}
 
Example 10
Project: TOSCAna   File: PluginFileAccessTest.java   View Source Code Vote up 5 votes
@Test
public void write() throws Exception {
    String secondString = "second_test_string";
    access.access(targetFileName).appendln(fileContent).close();
    access.access(targetFileName).append(secondString).close();
    assertTrue(targetFile.isFile());
    List<String> result = IOUtils.readLines(new FileInputStream(targetFile));
    assertEquals(fileContent, result.get(result.size() - 2));
    assertEquals(secondString, result.get(result.size() - 1));
}
 
Example 11
Project: TOSCAna   File: BaseDockerfileTest.java   View Source Code Vote up 5 votes
public void validate(String s, String path) throws IOException {
    List<String> lines = IOUtils.readLines(
        getClass().getClassLoader().getResourceAsStream(path),
        "UTF-8"
    );
    List<String> lines2 = Arrays.asList(s.split("\n"));
    for (int i = 0; i < lines.size(); i++) {
        assertEquals(lines.get(i), lines2.get(i));
    }
}
 
Example 12
Project: BaseClient   File: StringTranslate.java   View Source Code Vote up 5 votes
public StringTranslate()
{
    try
    {
        InputStream inputstream = StringTranslate.class.getResourceAsStream("/assets/minecraft/lang/en_US.lang");

        for (String s : IOUtils.readLines(inputstream, Charsets.UTF_8))
        {
            if (!s.isEmpty() && s.charAt(0) != 35)
            {
                String[] astring = (String[])Iterables.toArray(equalSignSplitter.split(s), String.class);

                if (astring != null && astring.length == 2)
                {
                    String s1 = astring[0];
                    String s2 = numericVariablePattern.matcher(astring[1]).replaceAll("%$1s");
                    this.languageList.put(s1, s2);
                }
            }
        }

        this.lastUpdateTimeInMilliseconds = System.currentTimeMillis();
    }
    catch (IOException var7)
    {
        ;
    }
}
 
Example 13
Project: argument-reasoning-comprehension-task   File: MainCrawler.java   View Source Code Vote up 5 votes
public static void main(String[] args)
        throws Exception
{
    String chromeDriverFile = args[0];
    String urlListFile = args[1];
    File outputDir = new File(args[2]);

    DebateFetcher debateFetcher = new DebateFetcher(chromeDriverFile);

    // read URLs to fetch first
    List<String> urlList = IOUtils.readLines(new FileInputStream(urlListFile));
    System.out.println(urlList.size() + " URLs to fetch");

    for (String url : urlList) {
        String name = url.replaceAll("^http://", "").replaceAll("/", "___") + ".html";

        System.out.println("Fetching " + url);
        String html = debateFetcher.fetchDiscussionPage(url);

        // save to file
        File outputFile = new File(outputDir, name);
        FileUtils.write(outputFile, html, "utf-8");
        System.out.println("Written " + outputFile);
    }

    debateFetcher.finishFetching();
}
 
Example 14
Project: flume-release-1.7.0   File: TestIRCSink.java   View Source Code Vote up 5 votes
/**
 * Process the incoming request from IRC client
 *
 * @param socket  IRC client connection socket
 * @throws IOException
 */
private void process(Socket socket) throws IOException {
  FileOutputStream fileOutputStream = FileUtils.openOutputStream(eventFile);
  List<String> input = IOUtils.readLines(socket.getInputStream());
  for (String next : input) {
    if (isPrivMessage(next)) {
      fileOutputStream.write(next.getBytes());
      fileOutputStream.write("\n".getBytes());
    }
  }
  fileOutputStream.close();
  socket.close();
}
 
Example 15
Project: Geolosys   File: ItemFieldManual.java   View Source Code Vote up 5 votes
@SideOnly(Side.CLIENT)
public int getNumEntries()
{
    String langFile = Minecraft.getMinecraft().gameSettings.language;
    langFile = langFile.substring(0, langFile.indexOf("_")) + langFile.substring(langFile.indexOf("_")).toUpperCase();
    InputStream in = Geolosys.class.getResourceAsStream("/assets/geolosys/book/" + langFile + ".lang");
    int numLines = 0;
    if (in == null)
    {
        langFile = "en_US";
        in = Geolosys.class.getResourceAsStream("/assets/geolosys/lang/" + langFile + ".lang");
    }
    try
    {
        for (String s : IOUtils.readLines(in, "utf-8"))
        {
            if (s.indexOf("=") == -1)
            {
                continue;
            }
            if (s.contains("_title"))
            {
                numLines++;
            }
        }
    }
    catch (IOException e)
    {
    }
    return numLines;
}
 
Example 16
Project: OperatieBRP   File: RubriekMap.java   View Source Code Vote up 5 votes
private void parseStream(final InputStream is) throws IOException {
    final List<String> strings = IOUtils.readLines(is);
    for (String rubriek : strings) {
        final String[] split = StringUtils.split(rubriek, ",");
        if (split.length >= LENGTE_2) {
            final AttribuutElement attribuutElement = ElementHelper.getAttribuutElement(split[1]);
            rubriekAttribuutMultimap.put(split[0], attribuutElement);
            categorieGroepMultimap.put(Integer.parseInt(StringUtils.split(split[0], ".")[0]), attribuutElement.getGroep());
        }
    }
}
 
Example 17
Project: PACE   File: EntryEncryptorTest.java   View Source Code Vote up 5 votes
/**
 * Get the value encryptors for this test class. The default set of keys will be used.
 *
 * @return Entry encryptors.
 */
private Collection<EntryEncryptor> getEncryptors() throws Exception {
  List<EntryEncryptor> encryptors = new ArrayList<>();
  for (String line : IOUtils.readLines(this.getClass().getResourceAsStream(this.getClass().getSimpleName()))) {
    encryptors.add(new EntryEncryptor(new EncryptionConfigBuilder().readFromFile(new InputStreamReader(TestUtils.getResourceAsStream(this.getClass(), line)))
        .build(), keys));
  }
  return encryptors;
}
 
Example 18
Project: Geolosys   File: ItemFieldManual.java   View Source Code Vote up 5 votes
@SideOnly(Side.CLIENT)
public String translateTitle(int pageNumber)
{
    String langFile = Minecraft.getMinecraft().gameSettings.language;
    langFile = langFile.substring(0, langFile.indexOf("_")) + langFile.substring(langFile.indexOf("_")).toUpperCase();
    InputStream in = Geolosys.class.getResourceAsStream("/assets/geolosys/book/" + langFile + ".lang");
    if (in == null)
    {
        langFile = "en_US";
        in = Geolosys.class.getResourceAsStream("/assets/geolosys/book/" + langFile + ".lang");
    }
    try
    {
        for (String s : IOUtils.readLines(in, "utf-8"))
        {
            if (s.indexOf("=") == -1)
            {
                continue;
            }
            if (s.substring(0, s.indexOf("=")).equals("page_" + pageNumber + "_title"))
            {
                return s.substring(s.indexOf("=") + 1);
            }
        }
    }
    catch (IOException e)
    {
    }
    return "ERROR READING PAGE " + pageNumber;
}
 
Example 19
Project: plugin-id-ldap   File: CsvStreamingOutputTest.java   View Source Code Vote up 4 votes
@Test
public void write() throws IOException {
	final ActivitiesComputations computations = new ActivitiesComputations();

	// Nodes
	final Collection<INamableBean<String>> nodes = new ArrayList<>();
	final NamedBean<String> node1 = new NamedBean<>();
	nodes.add(node1);
	node1.setId("J0");
	node1.setName("J0N");
	final NamedBean<String> node2 = new NamedBean<>();
	nodes.add(node2);
	node2.setId("J1");
	node2.setName("J1N");
	computations.setNodes(nodes);

	// Activities
	final Map<String, Map<String, Activity>> activities = new HashMap<>();
	final Map<String, Activity> userActivities = new HashMap<>();
	activities.put("U0", userActivities);
	final Activity activity1 = new Activity();
	activity1.setLastConnection(new Date(0));
	userActivities.put("J0", activity1);
	computations.setActivities(activities);

	// Users
	final Collection<UserOrg> users = new ArrayList<>();
	final UserOrg user = new UserOrg();
	user.setFirstName("F0");
	user.setLastName("L0");
	user.setId("U0");
	user.setMails(new ArrayList<>());
	users.add(user);
	final UserOrg user2 = new UserOrg();
	user2.setFirstName("F1");
	user2.setLastName("L1");
	user2.setId("U1");
	user2.setMails(Arrays.asList("M1", "M2"));
	users.add(user2);
	computations.setUsers(users);

	// Call
	final ByteArrayOutputStream out = new ByteArrayOutputStream();
	new CsvStreamingOutput(computations).write(out);
	final List<String> lines = IOUtils.readLines(new ByteArrayInputStream(out.toByteArray()), StandardCharsets.UTF_8);

	// Check
	Assert.assertEquals(3, lines.size());
	Assert.assertEquals("user;firstName;lastName;mail;J0N;J1N", lines.get(0));
	Assert.assertEquals("U0;F0;L0;;1970/01/01 01:00:00;", lines.get(1));
	Assert.assertEquals("U1;F1;L1;M1", lines.get(2));

}
 
Example 20
Project: lightgbm_predict4j   File: Boosting.java   View Source Code Vote up 4 votes
static String getBoostingTypeFromModelFile(String filename) throws FileNotFoundException, IOException {
    List<String> lines = IOUtils.readLines(new FileInputStream(filename));
    return lines.get(0);
}