当前位置: 首页>>代码示例>>Java>>正文


Java Files.readLines方法代码示例

本文整理汇总了Java中com.google.common.io.Files.readLines方法的典型用法代码示例。如果您正苦于以下问题:Java Files.readLines方法的具体用法?Java Files.readLines怎么用?Java Files.readLines使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.io.Files的用法示例。


在下文中一共展示了Files.readLines方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dumpsStepsReplacingAliases

import com.google.common.io.Files; //导入方法依赖的package包/类
@Test
public void dumpsStepsReplacingAliases() throws IOException {
    Map<String, String> firstStep = new HashMap<>();
    firstStep.put(EVENT, loadPageActionName);
    firstStep.put(aliasUrl, aliasUrlValue);

    Map<String, String> secondStep = new HashMap<>();
    secondStep.put(EVENT, typeInNameInputActionName);
    secondStep.put(aliasText, aliasTextValue);

    TestScenarioSteps testScenarioSteps = new TestScenarioSteps();
    testScenarioSteps.add(firstStep);
    testScenarioSteps.add(secondStep);


    Map<String, ApplicationActionConfiguration> actionConfigurationMap = createAliasesMockConfiguration();

    StepsDumper stepsDumper = new DslStepsDumper(actionConfigurationMap);
    stepsDumper.dump(testScenarioSteps, outputFilename);

    List<String> lines = Files.readLines(outputFile, Charsets.UTF_8);
    assertEquals(2, lines.size());
    assertEquals("loadPage: Load text-field.html page ", lines.get(0));
    assertEquals("typeInNameInput: Type admin in name input ", lines.get(1));
}
 
开发者ID:hristo-vrigazov,项目名称:bromium,代码行数:26,代码来源:DslStepsDumperTest.java

示例2: parseExcludeIds

import com.google.common.io.Files; //导入方法依赖的package包/类
public static List<Integer> parseExcludeIds() {
    String businessLog = "business.log";

    try {
        List<String> lines = Files.readLines(new File(LOG_BASE_PATH + "/" + businessLog), Charset.defaultCharset());
        return lines.stream()
                .filter(line -> line.contains("-get urls"))
                .map(line -> {
                    Matcher matcher = ID_PATTERN.matcher(line);
                    if (matcher.find()) {
                        return Integer.valueOf(matcher.group(1).trim());
                    }
                    return 0;
                }).filter(id -> id != 0).collect(Collectors.toList());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:cbooy,项目名称:cakes,代码行数:19,代码来源:ParseLogs.java

示例3: loadHistory

import com.google.common.io.Files; //导入方法依赖的package包/类
/**
 * Loads projects from the history.
 */

public final void loadHistory() {
	try {
		final File history = new File(Utils.getParentFolder(), Constants.FILE_GUI_HISTORY);
		if(!history.exists()) {
			return;
		}
		for(final String path : Files.readLines(history, StandardCharsets.UTF_8)) {
			final File projectData = new File(path, Constants.FILE_PROJECT_DATA);
			if(!projectData.exists()) {
				continue;
			}
			projectsModel.addElement(path);
		}
	}
	catch(final Exception ex) {
		ex.printStackTrace(guiPrintStream);
		ex.printStackTrace();
		JOptionPane.showMessageDialog(ProjectsFrame.this, String.format(Constants.GUI_DIALOG_ERROR_MESSAGE, ex.getMessage()), ex.getClass().getName(), JOptionPane.ERROR_MESSAGE);
	}
}
 
开发者ID:Skyost,项目名称:SkyDocs,代码行数:25,代码来源:ProjectsFrame.java

示例4: visitStyleSheet

import com.google.common.io.Files; //导入方法依赖的package包/类
@Override
public void visitStyleSheet(StyleSheetTree tree) {
  List<String> lines;
  try {
    lines = Files.readLines(getContext().getFile(), charset);
  } catch (IOException e) {
    throw new IllegalStateException("Check css:" + this.getClass().getAnnotation(Rule.class).key()
      + ": Error while reading " + getContext().getFile().getName(), e);
  }
  for (String line : lines) {
    if (line.contains("\t")) {
      addFileIssue("Replace all tab characters in this file by sequences of whitespaces.");
      break;
    }
  }
  super.visitStyleSheet(tree);
}
 
开发者ID:racodond,项目名称:sonar-css-plugin,代码行数:18,代码来源:TabCharacterCheck.java

示例5: readFile

import com.google.common.io.Files; //导入方法依赖的package包/类
static List<String> readFile(File inFile, Map<String, String[]> read) throws IOException
{
    List<String> list = Files.readLines(inFile, Charsets.UTF_8);

    for (String s : list)
    {
        s = s.trim();

        if (!s.startsWith("#") && s.length() >= 1)
        {
            String[] astring = s.split("\\|");
            read.put(astring[0].toLowerCase(Locale.ROOT), astring);
        }
    }

    return list;
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:18,代码来源:PreYggdrasilConverter.java

示例6: thenXMLResponseSimilarToFile

import com.google.common.io.Files; //导入方法依赖的package包/类
@Then("verify REST-XML response is similar to '$file'")
public void thenXMLResponseSimilarToFile(String file) throws IOException, SAXException {
    File fileFromResources = getFileFromResourcesByFilePath(file);
    List<String> expected = Files.readLines(fileFromResources, Charset.defaultCharset());
    String expectedXml = expected.stream()
            .map(StringUtils::chomp)
            .map(StringUtils::strip)
            .collect(Collectors.joining());
    Response response = getVariableValue(KEY);
    String actualXml = response.getBody().asString();
    Diff diff = new Diff(expectedXml, actualXml);
    diff.overrideDifferenceListener(new IgnoreTextAndAttributeValuesDifferenceListener());
    StringBuffer stringBuffer = diff.appendMessage(new StringBuffer());
    stringBuffer.append("\nExpected: ")
            .append(expectedXml)
            .append("\n     but: ")
            .append(actualXml)
            .append("\n");
    assertTrue(stringBuffer.toString(), diff.similar());
}
 
开发者ID:tapack,项目名称:satisfy,代码行数:21,代码来源:RestXMLOnlySteps.java

示例7: correctlyHandlesNoAliases

import com.google.common.io.Files; //导入方法依赖的package包/类
@Test
public void correctlyHandlesNoAliases() throws IOException {
    Map<String, String> firstStep = new HashMap<>();
    firstStep.put(EVENT, clickLoginButtonActionName);

    TestScenarioSteps testScenarioSteps = new TestScenarioSteps();
    testScenarioSteps.add(firstStep);

    Map<String, ApplicationActionConfiguration> actionConfigurationMap = createNoAliasesMockConfiguration();

    StepsDumper stepsDumper = new DslStepsDumper(actionConfigurationMap);
    stepsDumper.dump(testScenarioSteps, outputFilename);

    List<String> lines = Files.readLines(outputFile, Charsets.UTF_8);
    assertEquals(1, lines.size());
    assertEquals("clickLoginButtonActionName: Click login button ", lines.get(0));
}
 
开发者ID:hristo-vrigazov,项目名称:bromium,代码行数:18,代码来源:DslStepsDumperTest.java

示例8: testAppYamlIsDockerignored

import com.google.common.io.Files; //导入方法依赖的package包/类
@Test
public void testAppYamlIsDockerignored()
    throws IOException, BuildStepException {
  String relativeAppYamlPath = "foo/bar/app.yaml";
  Path workspace = new TestWorkspaceBuilder()
      .file(relativeAppYamlPath).withContents("env: flex").build()
      .file("app.jar").build()
      .build();

  when(appYamlFinder.findAppYamlFile(workspace))
      .thenReturn(Optional.of(workspace.resolve(relativeAppYamlPath)));

  buildPipelineConfigurator.generateDockerResources(workspace);

  List<String> dockerIgnoreLines = Files.readLines(workspace.resolve(".dockerignore").toFile(),
      Charset.defaultCharset());
  assertTrue(dockerIgnoreLines.contains(relativeAppYamlPath));
}
 
开发者ID:GoogleCloudPlatform,项目名称:runtime-builder-java,代码行数:19,代码来源:BuildPipelineConfiguratorTest.java

示例9: parseFinished

import com.google.common.io.Files; //导入方法依赖的package包/类
public static List<Integer> parseFinished() {
    String errorLog = "error.log";

    try {
        List<String> lines = Files.readLines(new File(LOG_BASE_PATH + "/" + errorLog), Charset.defaultCharset());
        return lines.stream()
                //.peek(System.out::println)
                .filter(line -> line.contains("finished:"))
                .map(line -> {
                    String[] sp = line.split("finished:");
                    return Integer.valueOf(sp[1]);
                })
                .collect(Collectors.toList());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:cbooy,项目名称:cakes,代码行数:18,代码来源:ParseLogs.java

示例10: get

import com.google.common.io.Files; //导入方法依赖的package包/类
@Override
public long get() throws UnsupportedOperationException {
    List<String> meminfoOutputLines;
    try {
        meminfoOutputLines = Files.readLines(new File(MEMINFO_FILE_PATH), Charset.defaultCharset());
    } catch (IOException e) {
        throw new UnsupportedOperationException("Unable to read free memory from " + MEMINFO_FILE_PATH, e);
    }
    long freeMemoryFromProcMeminfo = parseFreeMemoryFromMeminfo(meminfoOutputLines);
    if (freeMemoryFromProcMeminfo == -1) {
        throw new UnsupportedOperationException("Unable to get free memory from " + MEMINFO_FILE_PATH);
    }
    return freeMemoryFromProcMeminfo;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:15,代码来源:MeminfoAvailableMemory.java

示例11: sortAndFindKeyWords

import com.google.common.io.Files; //导入方法依赖的package包/类
/**
 * 查找关键字
 * @param file
 * @throws IOException
 */
private static void sortAndFindKeyWords(File file) throws IOException {
    content = Files.readLines(file, Charset.defaultCharset());
    LOGGER.info(String.valueOf(content));

    for (String value : content) {

        boolean flag = value.contains(KEYWORD) ;
        if (!flag){
            continue;
        }

        if (countMap.containsKey(value)){
            countMap.put(value,countMap.get(value) + 1) ;
        } else {
            countMap.put(value,1) ;
        }
    }

    for (String key :countMap.keySet()){
        SortString sort = new SortString() ;
        sort.setKey(key);
        sort.setCount(countMap.get(key));

        contentSet.add(sort) ;
    }

}
 
开发者ID:crossoverJie,项目名称:Java-Interview,代码行数:33,代码来源:ReadFile.java

示例12: main

import com.google.common.io.Files; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    List<String> lines = Files.readLines(new File(LINKS_FILE_PATH), Charset.defaultCharset());
    lines.stream()
            .filter(line -> line.startsWith("http"))
            .forEach(line -> {
                try {
                    OkHttpClient client = new OkHttpClient();

                    Request request = new Request.Builder()
                            .url(line)
                            .get()
                            .build();

                    Response response = client.newCall(request).execute();
                    if (response.isSuccessful()) {
                        String respData = response.body().string();
                        Matcher matcher = TITLE_PATTERN.matcher(respData);
                        if (matcher.find()) {
                            String title = matcher.group(1);
                            System.out.println(title + "\t:\t" + line);
                        }
                    }
                    response.body().close();
                } catch (Exception e) {
                    if (e instanceof SocketTimeoutException) {
                        System.out.println("超时: " + line);
                    }
                }
            });
}
 
开发者ID:cbooy,项目名称:cakes,代码行数:31,代码来源:LoadLinksTitle.java

示例13: visitStyleSheet

import com.google.common.io.Files; //导入方法依赖的package包/类
@Override
public void visitStyleSheet(StyleSheetTree tree) {
  List<String> lines;
  try {
    lines = Files.readLines(getContext().getFile(), charset);
  } catch (IOException e) {
    throw new IllegalStateException("Check css:" + this.getClass().getAnnotation(Rule.class).key()
      + ": Error while reading " + getContext().getFile().getName(), e);
  }
  if (lines.size() > max) {
    addFileIssue("This file contains " + lines.size() + " lines, that is more than the maximum allowed " + max + "."
      + " Split this file into smaller files.");
  }
  super.visitStyleSheet(tree);
}
 
开发者ID:racodond,项目名称:sonar-css-plugin,代码行数:16,代码来源:FileTooManyLinesCheck.java

示例14: load

import com.google.common.io.Files; //导入方法依赖的package包/类
public void load() throws IOException {
    List<String> lines = Files.readLines(mSymbolFile, Charsets.UTF_8);

    mSymbols = HashBasedTable.create();

    int lineIndex = 1;
    String line = null;
    try {
        final int count = lines.size();
        for (; lineIndex <= count ; lineIndex++) {
            line = lines.get(lineIndex-1);

            // format is "<type> <class> <name> <value>"
            // don't want to split on space as value could contain spaces.
            int pos = line.indexOf(' ');
            String type = line.substring(0, pos);
            int pos2 = line.indexOf(' ', pos + 1);
            String className = line.substring(pos + 1, pos2);
            int pos3 = line.indexOf(' ', pos2 + 1);
            String name = line.substring(pos2 + 1, pos3);
            String value = line.substring(pos3 + 1);

            mSymbols.put(className, name, new SymbolEntry(name, type, value));
        }
    } catch (Exception e) {
        String s = String.format("File format error reading %s\tline %d: '%s'",
                mSymbolFile.getAbsolutePath(), lineIndex, line);
        throw new IOException(s, e);
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:31,代码来源:SymbolLoader.java

示例15: readLines

import com.google.common.io.Files; //导入方法依赖的package包/类
/**
 * Reads all lines from a file and get them as a list of strings.
 *
 * @param file The file
 * @return The list of lines
 */
public static List<String> readLines(File file) {
    try {
        return Files.readLines(file, Charset.forName("UTF-8"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    return new ArrayList<>();
}
 
开发者ID:DianoxDragon,项目名称:UltimateSpawn,代码行数:15,代码来源:FileUtils.java


注:本文中的com.google.common.io.Files.readLines方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。