本文整理匯總了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) {}
}
示例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());
}
示例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");
}
}
}
示例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;
}
示例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());
}
}
}