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


Java BufferedReader.reset方法代码示例

本文整理汇总了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;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:26,代码来源:JHLogAnalyzer.java

示例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());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:CSVProcessor.java

示例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());
}
 
开发者ID:zg2pro,项目名称:spring-rest-basis,代码行数:20,代码来源:LoggingRequestInterceptor.java

示例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;
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:27,代码来源:FilesUtil.java

示例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());
}
 
开发者ID:DNAProject,项目名称:DNASDKJava,代码行数:16,代码来源:JBigInt.java

示例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()));
}
 
开发者ID:DNAProject,项目名称:DNASDKJava,代码行数:16,代码来源:JNumber.java

示例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;

    }
 
开发者ID:quaap,项目名称:BookyMcBookface,代码行数:36,代码来源:EpubBook.java

示例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;
}
 
开发者ID:quaap,项目名称:BookyMcBookface,代码行数:28,代码来源:EpubBook.java

示例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());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:35,代码来源:WC.java

示例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);
  }
}
 
开发者ID:alfasoftware,项目名称:morf,代码行数:44,代码来源:Version2to4TransformingReader.java


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