本文整理汇总了Java中java.io.BufferedReader.reset方法的典型用法代码示例。如果您正苦于以下问题:Java BufferedReader.reset方法的具体用法?Java BufferedReader.reset怎么用?Java BufferedReader.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.BufferedReader
的用法示例。
在下文中一共展示了BufferedReader.reset方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readLine
import java.io.BufferedReader; //导入方法依赖的package包/类
private String readLine(BufferedReader reader) throws IOException {
resBuffer.setLength(0);
reader.mark(maxJobDelimiterLineLength);
for(String line = reader.readLine();
line != null; line = reader.readLine()) {
if(isEndOfJobLog(line)) {
if(resBuffer.length() == 0)
resBuffer.append(line);
else
reader.reset();
break;
}
if(resBuffer.length() == 0)
resBuffer.append(line);
else if(resBuffer.length() < 32000)
resBuffer.append(line);
if(line.endsWith(" .") || line.endsWith("\" ")) {
break;
}
reader.mark(maxJobDelimiterLineLength);
}
String result = resBuffer.length() == 0 ? null : resBuffer.toString();
resBuffer.setLength(0);
return result;
}
示例2: statInSeveralPasses
import java.io.BufferedReader; //导入方法依赖的package包/类
private static void statInSeveralPasses(BufferedReader br, int column)
throws IOException {
System.out.println("#-----Statistics in several passes-------#");
//Create a comparator to compare records by the column.
Comparator<String> comparator
= Comparator.comparing(
(String str) -> parseDouble(getCell(str, column)));
//Find max record by using Collectors.maxBy(...)
System.out.println(
"Max: " + br.lines().collect(maxBy(comparator)).get());
br.reset();
//Find min record by using Collectors.minBy(...)
System.out.println(
"Min: " + br.lines().collect(minBy(comparator)).get());
br.reset();
//Compute the average value and sum with
//Collectors.toDoubleSummaryStatistics(...)
DoubleSummaryStatistics doubleSummaryStatistics
= br.lines().collect(summarizingDouble(
str -> parseDouble(getCell(str, column))));
System.out.println("Average: " + doubleSummaryStatistics.getAverage());
System.out.println("Sum: " + doubleSummaryStatistics.getSum());
}
示例3: writeBody
import java.io.BufferedReader; //导入方法依赖的package包/类
private void writeBody(final BufferedReader bufferedReader) throws IOException {
char[] buffer = new char[BUFFER_LENGTH];
StringBuilder inputStringBuilder = new StringBuilder("Response Body : ");
bufferedReader.mark(MARK_LENGTH);
int len = bufferedReader.read(buffer);
String line = new String(buffer);
int curLen = 0;
while (!StringUtils.isEmpty(line) && curLen > -1 && len < MARK_LENGTH) {
inputStringBuilder.append(line);
curLen = bufferedReader.read(buffer);
len += curLen;
line = new String(buffer);
}
if (len == MARK_LENGTH) {
inputStringBuilder.append("...");
}
bufferedReader.reset();
log(inputStringBuilder.toString());
}
示例4: sessionAlreadyImported
import java.io.BufferedReader; //导入方法依赖的package包/类
public static boolean sessionAlreadyImported(File xmlImportFile, File xmlSessionFile) throws IOException {
BufferedReader br1 = new BufferedReader(new FileReader(xmlSessionFile)); //sessionfile
BufferedReader br2 = new BufferedReader(new FileReader(xmlImportFile)); //desktop import
String s1, s2;
s1 = br1.readLine();
s2 = br2.readLine();
s2 = br2.readLine();
br2.mark(2000);;
while(s1 != null) {
while (s1 != null && s2 != null && s1.equals(s2)) {
s1 = br1.readLine();
s2 = br2.readLine();
if (s2 == null) {
br1.close();
br2.close();
return true;
}
}
br2.reset();
s1 = br1.readLine();
}
br1.close();
br2.close();
return false;
}
示例5: parseNumber
import java.io.BufferedReader; //导入方法依赖的package包/类
static JBigInt parseNumber(BufferedReader reader) throws IOException {
skipSpace(reader);
StringBuilder sb = new StringBuilder();
while (true) {
reader.mark(1);
int c = reader.read();
if (c >= '0' && c <= '9' || c == '.' || c == '-') {
sb.append((char)c);
} else {
reader.reset();
break;
}
}
return new JBigInt(sb.toString());
}
示例6: parseNumber
import java.io.BufferedReader; //导入方法依赖的package包/类
static JNumber parseNumber(BufferedReader reader) throws IOException {
skipSpace(reader);
StringBuilder sb = new StringBuilder();
while (true) {
reader.mark(1);
int c = reader.read();
if (c >= '0' && c <= '9' || c == '.' || c == '-') {
sb.append((char)c);
} else {
reader.reset();
break;
}
}
return new JNumber(Double.parseDouble(sb.toString()));
}
示例7: getRootFilesFromContainer
import java.io.BufferedReader; //导入方法依赖的package包/类
private static List<String> getRootFilesFromContainer(BufferedReader containerxml) {
List<String> rootFiles = new ArrayList<>();
try {
containerxml.mark(4);
if ('\ufeff' != containerxml.read()) containerxml.reset(); // not the BOM marker
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(false);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(containerxml);
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
if (xpp.getName().equals("rootfile")) {
for (int i = 0; i < xpp.getAttributeCount(); i++) {
if (xpp.getAttributeName(i).equals("full-path")) {
rootFiles.add(xpp.getAttributeValue(i));
}
}
}
}
eventType = xpp.next();
}
} catch (Exception e) {
Log.e("BMBF", "Error parsing xml " + e, e);
}
return rootFiles;
}
示例8: processToc
import java.io.BufferedReader; //导入方法依赖的package包/类
private static Map<String,?> processToc(BufferedReader tocReader) {
Map<String,Object> bookdat = new LinkedHashMap<>();
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
XPathFactory factory = XPathFactory.newInstance();
DocumentBuilder builder = null;
try {
builder = dfactory.newDocumentBuilder();
tocReader.mark(4);
if ('\ufeff' != tocReader.read()) tocReader.reset(); // not the BOM marker
Document doc = builder.parse(new InputSource(tocReader));
XPath tocPath = factory.newXPath();
tocPath.setNamespaceContext(tocnsc);
Node nav = (Node)tocPath.evaluate("/ncx/navMap", doc, XPathConstants.NODE);
int total = readNavPoint(nav, tocPath, bookdat, 0);
bookdat.put(TOCCOUNT, total);
} catch (ParserConfigurationException | IOException | SAXException | XPathExpressionException e) {
Log.e("BMBF", "Error parsing xml " + e.getMessage(), e);
}
return bookdat;
}
示例9: collectInFourPasses
import java.io.BufferedReader; //导入方法依赖的package包/类
private static void collectInFourPasses(BufferedReader reader)
throws IOException {
/*
* Input is read as a stream of lines by lines().
* Every line is turned into a stream of chars by the flatMapToInt(...)
* method.
* Length of the stream is counted by count().
*/
System.out.println("Character count = "
+ reader.lines().flatMapToInt(String::chars).count());
/*
* Input is read as a stream of lines by lines().
* Every line is split by nonWordPattern into words by flatMap(...)
* method.
* Empty lines are removed by the filter(...) method.
* Length of the stream is counted by count().
*/
reader.reset();
System.out.println("Word count = "
+ reader.lines()
.flatMap(nonWordPattern::splitAsStream)
.filter(str -> !str.isEmpty()).count());
reader.reset();
System.out.println("Newline count = " + reader.lines().count());
/*
* Input is read as a stream of lines by lines().
* Every line is mapped to its length.
* Maximum of the lengths is calculated.
*/
reader.reset();
System.out.println("Max line length = "
+ reader.lines().mapToInt(String::length).max().getAsInt());
}
示例10: readVersion
import java.io.BufferedReader; //导入方法依赖的package包/类
/**
* Tests whether a given input stream contains XML format 2, and therefore
* should have the transform applied.
* <p>
* This is designed to match the known output format of
* {@link XmlDataSetConsumer} which previously produced invalid XML. It is
* deliberately brittle. There is no need for a more intelligent XML parser
* here.
* </p>
*
* @param bufferedReader The input stream in a buffered reader
* @return true if the transform should be applied. (because it's format 2)
*/
static int readVersion(BufferedReader bufferedReader) {
try {
bufferedReader.mark(1024); // arbitrary read-ahead limit - that's enough to get the info we want
try {
char[] buffer = new char[1024];
int read = bufferedReader.read(buffer);
if (read == -1) {
return -1;
}
String content = new String(buffer, 0, read);
// Apply the transform if the version number is 2 or 1
Pattern pattern = Pattern.compile("table\\sversion=\"(\\d+)\""); //
Matcher matcher = pattern.matcher(content);
if (!matcher.find()) {
return -1;
} else {
return Integer.parseInt(matcher.group(1));
}
} finally {
bufferedReader.reset();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}