java.io.BufferedReader.ready()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(267)

本文整理了Java中java.io.BufferedReader.ready()方法的一些代码示例,展示了BufferedReader.ready()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BufferedReader.ready()方法的具体详情如下:
包路径:java.io.BufferedReader
类名称:BufferedReader
方法名:ready

BufferedReader.ready介绍

[英]Indicates whether this reader is ready to be read without blocking.
[中]指示此读卡器是否已准备好在不阻塞的情况下读取。

代码示例

代码示例来源:origin: stackoverflow.com

BufferedReader br = new BufferedReader(new InputStreamReader(System.in, Charset.forName("ISO-8859-1")),1024);
 // ...
    // inside some iteration / processing logic:
    if (br.ready()) {
      int readCount = br.read(inputData, bufferOffset, inputData.length-bufferOffset);
    }

代码示例来源:origin: spotbugs/spotbugs

String falsePositive(BufferedReader r) throws IOException {
    if (!r.ready())
      return "";
    return r.readLine().trim();
  }
}

代码示例来源:origin: stackoverflow.com

private void loadCommands(String fileName) {
  BufferedReader br = null;
  try {
    br = new BufferedReader(new FileReader(fileName));

    while (br.ready()) {
      actionList.add(CommandFactory.GetCommandFromText(this, br.readLine()));
    }
  } catch (FileNotFoundException e) {
    e.printStackTrace();
  } catch (IOException e) {
    e.printStackTrace();
  } finally {
    if (br != null) try { br.close(); } catch (IOException logOrIgnore) {}
  }       
}

代码示例来源:origin: jersey/jersey

private static List<JavaFile> getJavaFiles(File configFile) throws Exception {
  final List<JavaFile> javaFiles = new LinkedList<>();
  try (BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(configFile), "UTF-8"))) {
    while (r.ready()) {
      final String className = r.readLine();
      if (!className.startsWith("#")) {
        javaFiles.add(new JavaFile(className, SRC_MAIN_JAVA));
        LOGGER.info(String.format(" + included class %s.\n", className));
      } else {
        LOGGER.info(String.format(" - ignored class %s\n", className.substring(1)));
      }
    }
  }
  return javaFiles;
}

代码示例来源:origin: huaban/jieba-analysis

public void loadUserDict(Path userDict, Charset charset) {                
  try {
    BufferedReader br = Files.newBufferedReader(userDict, charset);
    long s = System.currentTimeMillis();
    int count = 0;
    while (br.ready()) {
      String line = br.readLine();
      String[] tokens = line.split("[\t ]+");
      if (tokens.length < 1) {
        // Ignore empty line
        continue;
      }
      String word = tokens[0];
      double freq = 3.0d;
      if (tokens.length == 2)
        freq = Double.valueOf(tokens[1]);
      word = addWord(word); 
      freqs.put(word, Math.log(freq / total));
      count++;
    }
    System.out.println(String.format(Locale.getDefault(), "user dict %s load finished, tot words:%d, time elapsed:%dms", userDict.toString(), count, System.currentTimeMillis() - s));
    br.close();
  }
  catch (IOException e) {
    System.err.println(String.format(Locale.getDefault(), "%s: load user dict failure!", userDict.toString()));
  }
}

代码示例来源:origin: apache/flink

&& (!readConsoleInput || !in.ready())) {
  Thread.sleep(200L);
if (readConsoleInput && in.ready()) {
  String command = in.readLine();
  switch (command) {
    case "quit":
      System.err.println(YARN_SESSION_HELP);
      break;
    default:
      System.err.println("Unknown command '" + command + "'. Showing help:");
      System.err.println(YARN_SESSION_HELP);
      break;

代码示例来源:origin: apache/flink

@Test
public void testSortingParallelism4() throws Exception {
  final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
  DataSet<Long> ds = env.generateSequence(0, 1000);
  // randomize
  ds.map(new MapFunction<Long, Long>() {
    Random rand = new Random(1234L);
    @Override
    public Long map(Long value) throws Exception {
      return rand.nextLong();
    }
  }).writeAsText(resultPath)
    .sortLocalOutput("*", Order.ASCENDING)
    .setParallelism(4);
  env.execute();
  BufferedReader[] resReaders = getResultReader(resultPath);
  for (BufferedReader br : resReaders) {
    long cmp = Long.MIN_VALUE;
    while (br.ready()) {
      long cur = Long.parseLong(br.readLine());
      assertTrue("Invalid order of sorted output", cmp <= cur);
      cmp = cur;
    }
    br.close();
  }
}

代码示例来源:origin: nutzam/nutz

br = (BufferedReader)r;
else
  br = new BufferedReader(r);
StringBuilder key = new StringBuilder();
StringBuilder sb = new StringBuilder();
OUT: while (br.ready()) {
  String line = Streams.nextLineTrim(br);
  if (line == null)
    } else {
      key.append(line.substring(2).trim());
      while (br.ready()) {
        line = Streams.nextLineTrim(br);
        if (line == null)

代码示例来源:origin: stackoverflow.com

try {
  mPIn = new PipedInputStream(mPOut);
  mReader = new LineNumberReader(new InputStreamReader(mPIn));
} catch (IOException e) {
  cancel(true);
try {
  while (mReader.ready()) {

代码示例来源:origin: chewiebug/GCViewer

private String readFile(String fileName) throws IOException {
  try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName)) {
    if (in != null) {
      try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"))) {
        
        StringBuilder text = new StringBuilder();
        while (reader.ready()) {
          text.append(addHtmlTags(reader.readLine())).append("<br/>");
        }
        
        return text.toString();
      }
    }
    else {
      return "'" + fileName + "' not found";
    }
  }
}

代码示例来源:origin: stanfordnlp/CoreNLP

/**
 * Constructs a new stoplist from the contents of a file. It is
 * assumed that the file contains stopwords, one on a line.
 * The stopwords need not be in any order.
 */
public StopList(File list) {
 wordSet = Generics.newHashSet();
 try {
  BufferedReader reader = new BufferedReader(new FileReader(list));
  while (reader.ready()) {
   wordSet.add(new Word(reader.readLine()));
  }
 } catch (IOException e) {
  throw new RuntimeException(e);
  //e.printStackTrace(System.err);
  //addGenericWords();
 }
}

代码示例来源:origin: GlowstoneMC/Glowstone

try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
  if (br.ready()) {
    json = (JSONObject) new JSONParser().parse(br);
  } else {

代码示例来源:origin: stanfordnlp/CoreNLP

private static void getWordsFromFile(String filename, Set<String> resultSet, boolean lowercase) throws IOException {
 if(filename==null) {
  return ;
 }
 try (BufferedReader reader = IOUtils.readerFromString(filename)) {
  while(reader.ready()) {
   if(lowercase) resultSet.add(reader.readLine().toLowerCase());
   else resultSet.add(reader.readLine());
  }
 }
}

代码示例来源:origin: stanfordnlp/CoreNLP

BufferedReader stdIn = new BufferedReader(
    new InputStreamReader(System.in, charset));
log.info("Input some text and press RETURN to POS tag it, or just RETURN to finish.");
for (String userInput; (userInput = stdIn.readLine()) != null && ! userInput.matches("\\n?"); ) {
 try {
  Socket socket = new Socket(host, port);
  PrintWriter out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), charset), true);
  BufferedReader in = new BufferedReader(new InputStreamReader(
      socket.getInputStream(), charset));
  PrintWriter stdOut = new PrintWriter(new OutputStreamWriter(System.out, charset), true);
  stdOut.println(in.readLine());
  while (in.ready()) {
   stdOut.println(in.readLine());
  in.close();
  socket.close();
 } catch (UnknownHostException e) {
stdIn.close();

代码示例来源:origin: stanfordnlp/CoreNLP

String stopToken   = "#";
BufferedReader in = new BufferedReader(new FileReader(modelFile));
 in.readLine();
 modelLineCount ++;
String thresholdLine = in.readLine();
modelLineCount ++;
String[] pieces = thresholdLine.split("\\s+");
double threshold = Double.parseDouble(pieces[0]);
while (in.ready()) {
 String svLine = in.readLine();
 modelLineCount ++;
 pieces = svLine.split("\\s+");
in.close();

代码示例来源:origin: stanfordnlp/CoreNLP

new Thread(mainWorker).start();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
   if (br.ready()) {
    log.info("received quit command: quitting");
    log.info("training completed by interruption");

代码示例来源:origin: stanfordnlp/CoreNLP

private static void getWordsFromFile(String filename, Set<String> resultSet, boolean lowercase) throws IOException {
 if(filename==null) {
  return ;
 }
 try (BufferedReader reader = IOUtils.readerFromString(filename)) {
  while (reader.ready()) {
   if (lowercase) resultSet.add(reader.readLine().toLowerCase());
   else resultSet.add(reader.readLine());
  }
 }
}

代码示例来源:origin: marytts/marytts

BufferedReader in = new BufferedReader(new InputStreamReader(resourceStream, "UTF-8"));
  while (in.ready()) {
    String line = in.readLine();
    listSet.add(line);
  in.close();
  return listSet; // put the set on the map
} else {

代码示例来源:origin: apache/geode

return ("Cannot read logFileName=" + logFileName);
input = new BufferedReader(new FileReader(logFileName));
String line;
File logToBeWrittenToFile = new File(logToBeWritten);
output = new BufferedWriter(new FileWriter(logToBeWrittenToFile));
if (!logToBeWrittenToFile.exists()) {
 input.close();
 output.flush();
 output.close();
 input.close();
 output.flush();
 output.close();
 input.close();
 output.flush();
 output.close();
boolean foundLogLevelTag = false;
boolean validateLogLevel = true;
while (input.ready() && (line = input.readLine()) != null) {
 if (!new File(logFileName).canRead()) {
  return ("Cannot read logFileName=" + logFileName);

代码示例来源:origin: igniterealtime/Openfire

@Override
  public void run() {
    try { 
      if (stdin.ready()) {
        if (EXIT.equalsIgnoreCase(stdin.readLine())) {
          System.exit(0); // invokes shutdown hook(s)
        }
      }
    } catch (IOException ioe) {
      logger.error("Error reading console input", ioe);
    }
  }
}

相关文章