本文整理汇总了Java中org.apache.commons.io.IOUtils.readLines方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtils.readLines方法的具体用法?Java IOUtils.readLines怎么用?Java IOUtils.readLines使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.io.IOUtils
的用法示例。
在下文中一共展示了IOUtils.readLines方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadData
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
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;
}
示例2: loadLocaleData
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
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);
}
}
}
}
示例3: initSql
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
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) {
}
}
示例4: setUpDirectories
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
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();
}
}
}
示例5: loadLocaleData
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
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);
}
}
}
}
示例6: loadLocaleData
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
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);
}
}
}
}
示例7: loadTrainingData
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
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;
}
示例8: LanguageMap
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
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)
{
;
}
}
示例9: load
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
/**
* 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);
}
}
示例10: write
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@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));
}
示例11: validate
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
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));
}
}
示例12: StringTranslate
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
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)
{
;
}
}
示例13: main
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
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();
}
示例14: process
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
/**
* 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();
}
示例15: getNumEntries
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@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;
}