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


Java BufferedReader.lines方法代码示例

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


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

示例1: open

import java.io.BufferedReader; //导入方法依赖的package包/类
@Override
public void open(Serializable prevCheckpointInfo) throws Exception {
	JobOperator jobOperator = getJobOperator();
	Properties jobParameters = jobOperator.getParameters(jobContext.getExecutionId());
	String resourceName = (String) jobParameters.get(INPUT_DATA_FILE_NAME);
	InputStream inputStream = new FileInputStream(resourceName);
	br = new BufferedReader(new InputStreamReader(inputStream));

	Stream<String> lines = br.lines();
	if (prevCheckpointInfo != null)
		recordNumber = (Integer) prevCheckpointInfo;
	else
		recordNumber = 0;
	stringLines = lines.toArray();
	logger.info("[SimpleItemReader] Opened Payroll file for reading from record number: " + recordNumber);
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:17,代码来源:PayrollItemReader.java

示例2: testIterator

import java.io.BufferedReader; //导入方法依赖的package包/类
public void testIterator() throws IOException {
    MockLineReader r = new MockLineReader(6);
    BufferedReader br = new BufferedReader(r);
    String line = br.readLine();
    assertEquals(r.getLineNumber(), 1, "Read one line");
    Stream<String> s = br.lines();
    Iterator<String> it = s.iterator();
    // Ensure iterate with only next works
    for (int i = 0; i < 5; i++) {
        String str = it.next();
        assertEquals(str, "Line " + (i + 2), "Addtional five lines");
    }
    // NoSuchElementException
    try {
        it.next();
        fail("Should have run out of lines.");
    } catch (NoSuchElementException nsse) {}
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:Lines.java

示例3: testInterlacedRead

import java.io.BufferedReader; //导入方法依赖的package包/类
public void testInterlacedRead() throws IOException {
    MockLineReader r = new MockLineReader(10);
    BufferedReader br = new BufferedReader(r);
    char[] buf = new char[5];
    Stream<String> s = br.lines();
    Iterator<String> it = s.iterator();

    br.read(buf);
    assertEquals(new String(buf), "Line ");
    assertEquals(it.next(), "1");
    try {
        s.iterator().next();
        fail("Should failed on second attempt to get iterator from s");
    } catch (IllegalStateException ise) {}
    br.read(buf, 0, 2);
    assertEquals(new String(buf, 0, 2), "Li");
    // Get stream again should continue from where left
    // Only read remaining of the line
    br.lines().limit(1L).forEach(line -> assertEquals(line, "ne 2"));
    br.read(buf, 0, 2);
    assertEquals(new String(buf, 0, 2), "Li");
    br.read(buf, 0, 2);
    assertEquals(new String(buf, 0, 2), "ne");
    assertEquals(it.next(), " 3");
    // Line 4
    br.readLine();
    // interator pick
    assertEquals(it.next(), "Line 5");
    // Another stream instantiated by lines()
    AtomicInteger line_no = new AtomicInteger(6);
    br.lines().forEach(l -> assertEquals(l, "Line " + line_no.getAndIncrement()));
    // Read after EOL
    assertFalse(it.hasNext());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:35,代码来源:Lines.java

示例4: link

import java.io.BufferedReader; //导入方法依赖的package包/类
void link() throws Exception {
    Process p = Runtime.getRuntime().exec(linkerCmd);
    final int exitCode = p.waitFor();
    if (exitCode != 0) {
        InputStream stderr = p.getErrorStream();
        if (stderr.read() == -1) {
            stderr = p.getInputStream();
        }
        BufferedReader br = new BufferedReader(new InputStreamReader(stderr));
        Stream<String> lines = br.lines();
        StringBuilder sb = new StringBuilder();
        lines.iterator().forEachRemaining(e -> sb.append(e));
        throw new InternalError(sb.toString());
    }
    File objFile = new File(objectFileName);
    if (objFile.exists()) {
        if (!objFile.delete()) {
            throw new InternalError("Failed to delete " + objectFileName + " file");
        }
    }
    // Make non-executable for all.
    File libFile = new File(libraryFileName);
    if (libFile.exists() && !options.osName.startsWith("Windows")) {
        if (!libFile.setExecutable(false, false)) {
            throw new InternalError("Failed to change attribute for " + libraryFileName + " file");
        }
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:Linker.java

示例5: getRuns

import java.io.BufferedReader; //导入方法依赖的package包/类
/**
 	* Returns a list of test runs for the rule.
 	* @param url The URL of rule additional parameters file
 	* @return Returns a list of test runs for the rule
   	*/	
public static List<RuleRun> getRuns(Rule rule, URL url) throws FileNotFoundException, IOException, NumberFormatException {
   		List<RuleRun> runs = new LinkedList<RuleRun>();		
   		runs.add(new RuleRun(Collections.emptyMap()));
	if (url != null) {
		File file = new File(url.getFile());			
		BufferedReader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8);
		Stream<String> entries = reader.lines();
		entries.forEach(entry -> {
			String[] parts = entry.split("\\s");
			if (parts.length > 1) {
				String suffix = parts[0];
				Map<RuleParam, ParamValue> params = new EnumMap<RuleParam, ParamValue>(RuleParam.class);
				switch (rule) {
					case _RANDOM_ALT_LINE:
						int seed = Integer.parseInt(parts[1]);
						params.put(RuleParam._RANDOM_SEED, ParamValue.createInt(seed));
						break;
					case _JOIN:
						int col = Integer.parseInt(parts[1]);
						params.put(RuleParam._JOIN_COL1, ParamValue.createInt(col));
						if (parts.length > 2) {
							col = Integer.parseInt(parts[2]);
							params.put(RuleParam._JOIN_COL2, ParamValue.createInt(col));
						}	
						break;
					case _ZIP_LINE:
					case _ZIP_CELL:
					case _ZIP_CHAR:
						String sep = parts[1];
						params.put(RuleParam._ZIP_SEP, ParamValue.createString(sep));
				}
				if (suffix.equals(DEFAULT_OUTPUT_FILE)) {
					runs.add(new RuleRun(null, params));
				} else {
					runs.add(new RuleRun(suffix, params));
				}
			}
		});
	}
   		return runs;
 	}
 
开发者ID:Innovimax-SARL,项目名称:mix-them,代码行数:47,代码来源:RuleRuns.java

示例6: Linker

import java.io.BufferedReader; //导入方法依赖的package包/类
Linker(Main main) throws Exception {
    this.options = main.options;
    String name = options.outputName;
    objectFileName = name;
    libraryFileName = name;

    if (options.linkerpath != null && !(new File(options.linkerpath).exists())) {
        throw new InternalError("Invalid linker path: " + options.linkerpath);
    }
    String linkerPath;
    String linkerCheck;

    switch (options.osName) {
        case "Linux":
            if (name.endsWith(".so")) {
                objectFileName = name.substring(0, name.length() - ".so".length());
            }
            linkerPath = (options.linkerpath != null) ? options.linkerpath : "ld";
            linkerCmd = linkerPath + " -shared -z noexecstack -o " + libraryFileName + " " + objectFileName;
            linkerCheck = linkerPath + " -v";
            break;
        case "SunOS":
            if (name.endsWith(".so")) {
                objectFileName = name.substring(0, name.length() - ".so".length());
            }
            objectFileName = objectFileName + ".o";
            linkerPath = (options.linkerpath != null) ? options.linkerpath : "ld";
            linkerCmd = linkerPath + " -shared -o " + libraryFileName + " " + objectFileName;
            linkerCheck = linkerPath + " -V";
            break;
        case "Mac OS X":
            if (name.endsWith(".dylib")) {
                objectFileName = name.substring(0, name.length() - ".dylib".length());
            }
            objectFileName = objectFileName + ".o";
            linkerPath = (options.linkerpath != null) ? options.linkerpath : "ld";
            linkerCmd = linkerPath + " -dylib -o " + libraryFileName + " " + objectFileName;
            linkerCheck = linkerPath + " -v";
            break;
        default:
            if (options.osName.startsWith("Windows")) {
                if (name.endsWith(".dll")) {
                    objectFileName = name.substring(0, name.length() - ".dll".length());
                }
                objectFileName = objectFileName + ".obj";
                linkerPath = (options.linkerpath != null) ? options.linkerpath : getWindowsLinkPath();
                if (linkerPath == null) {
                    throw new InternalError("Can't locate Microsoft Visual Studio amd64 link.exe");
                }
                linkerCmd = linkerPath + " /DLL /OPT:NOREF /NOLOGO /NOENTRY" + " /OUT:" + libraryFileName + " " + objectFileName;
                linkerCheck = null; // link.exe presence is verified already
                break;
            } else {
                throw new InternalError("Unsupported platform: " + options.osName);
            }
    }

    // Check linker presence on platforms by printing its version
    if (linkerCheck != null) {
        Process p = Runtime.getRuntime().exec(linkerCheck);
        final int exitCode = p.waitFor();
        if (exitCode != 0) {
            InputStream stderr = p.getErrorStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(stderr));
            Stream<String> lines = br.lines();
            StringBuilder sb = new StringBuilder();
            lines.iterator().forEachRemaining(e -> sb.append(e));
            throw new InternalError(sb.toString());
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:72,代码来源:Linker.java


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