當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。