okio.BufferedSource.readUtf8Line()方法的使用及代码示例

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

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

BufferedSource.readUtf8Line介绍

[英]Removes and returns characters up to but not including the next line break. A line break is either "\n" or "\r\n"; these characters are not included in the result.

On the end of the stream this method returns null, just like java.io.BufferedReader. If the source doesn't end with a line break then an implicit line break is assumed. Null is returned once the source is exhausted. Use this for human-generated data, where a trailing line break is optional.
[中]删除并返回最多到但不包括下一个换行符的字符。换行符为“\n”或“\r\n”;这些字符不包括在结果中。
在流的末尾,这个方法返回null,就像java一样。木卫一。缓冲读取器。如果源未以换行符结束,则假定为隐式换行符。一旦源耗尽,就会返回Null。对人工生成的数据使用此选项,其中尾随换行是可选的。

代码示例

代码示例来源:origin: square/okio

public void readLines(File file) throws IOException {
 try (Source fileSource = Okio.source(file);
    BufferedSource bufferedFileSource = Okio.buffer(fileSource)) {
  while (true) {
   String line = bufferedFileSource.readUtf8Line();
   if (line == null) break;
   if (line.contains("square")) {
    System.out.println(line);
   }
  }
 }
}

代码示例来源:origin: square/okio

public static void main(String[] args) throws IOException {
  SocksProxyServer proxyServer = new SocksProxyServer();
  proxyServer.start();

  URL url = new URL("https://publicobject.com/helloworld.txt");
  URLConnection connection = url.openConnection(proxyServer.proxy());
  try (BufferedSource source = Okio.buffer(Okio.source(connection.getInputStream()))) {
   for (String line; (line = source.readUtf8Line()) != null; ) {
    System.out.println(line);
   }
  }

  proxyServer.shutdown();
 }
}

代码示例来源:origin: hidroh/materialistic

@WorkerThread
private static Void loadFromAssets(Context context) throws IOException {
  InputStream stream = context.getAssets().open(AD_HOSTS_FILE);
  BufferedSource buffer = Okio.buffer(Okio.source(stream));
  String line;
  while ((line = buffer.readUtf8Line()) != null) {
    AD_HOSTS.add(line);
  }
  buffer.close();
  stream.close();
  return null;
}

代码示例来源:origin: testcontainers/testcontainers-java

@Override
  public void accept(BufferedSource source) {
    try {
      while (true) {
        String line = source.readUtf8Line();
        if (line == null) {
          break;
        }
        resultCallback.onNext(objectMapper.readValue(line, typeReference));
      }
    } catch (Exception e) {
      resultCallback.onError(e);
    }
  }
}

代码示例来源:origin: k9mail/k-9

private void readAdditionalCommands() throws IOException {
  String command = input.readUtf8Line();
  if (command == null) {
    throw new EOFException();
  }
  logger.log("Received additional command: %s", command);
}

代码示例来源:origin: k9mail/k-9

private void readAdditionalCommands() throws IOException {
  String command = input.readUtf8Line();
  if (command == null) {
    throw new EOFException();
  }
  logger.log("Received additional command: %s", command);
}

代码示例来源:origin: k9mail/k-9

private void readAdditionalCommands() throws IOException {
  String command = input.readUtf8Line();
  if (command == null) {
    throw new EOFException();
  }
  logger.log("Received additional command: %s", command);
}

代码示例来源:origin: square/okio

@Test public void bufferedReaderCompatible() throws IOException {
 data.writeUtf8("abc\ndef");
 assertEquals("abc", source.readUtf8Line());
 assertEquals("def", source.readUtf8Line());
 assertEquals(null, source.readUtf8Line());
}

代码示例来源:origin: square/okio

@Test public void bufferedReaderCompatibleWithTrailingNewline() throws IOException {
  data.writeUtf8("abc\ndef\n");
  assertEquals("abc", source.readUtf8Line());
  assertEquals("def", source.readUtf8Line());
  assertEquals(null, source.readUtf8Line());
 }
}

代码示例来源:origin: guoguibing/librec

BufferedSource bufferedSource = Okio.buffer(fileSource)) {
String temp;
while ((temp = bufferedSource.readUtf8Line()) != null) {
  if ("".equals(temp.trim())) {
    break;

代码示例来源:origin: k9mail/k-9

private void readExpectedCommand(ExpectedCommand expectedCommand) throws IOException,
    UnexpectedCommandException {
  String command = input.readUtf8Line();
  if (command == null) {
    throw new EOFException();
  }
  logger.log("C: %s", command);
  String expected = expectedCommand.getCommand();
  if (!command.equals(expected)) {
    logger.log("EXPECTED: %s", expected);
    throw new UnexpectedCommandException(expected, command);
  }
}

代码示例来源:origin: k9mail/k-9

private void readExpectedCommand(ExpectedCommand expectedCommand) throws IOException,
    UnexpectedCommandException {
  String command = input.readUtf8Line();
  if (command == null) {
    throw new EOFException();
  }
  logger.log("C: %s", command);
  String expected = expectedCommand.getCommand();
  if (!command.equals(expected)) {
    logger.log("EXPECTED: %s", expected);
    throw new UnexpectedCommandException(expected, command);
  }
}

代码示例来源:origin: k9mail/k-9

private void readExpectedCommand(ExpectedCommand expectedCommand) throws IOException,
    UnexpectedCommandException {
  String command = input.readUtf8Line();
  if (command == null) {
    throw new EOFException();
  }
  logger.log("C: %s", command);
  String expected = expectedCommand.getCommand();
  if (!command.equals(expected)) {
    logger.log("EXPECTED: %s", expected);
    logger.log("ACTUAL: %s", command);
    throw new UnexpectedCommandException(expected, command);
  }
}

代码示例来源:origin: hencoder/PlusDemo

private static void okio1() {
  try (BufferedSource source = Okio.buffer(Okio.source(new File("./26/text.txt")))) {
    System.out.println(source.readUtf8Line());
  } catch (IOException e) {
    e.printStackTrace();
  }
}

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

public static Observable<String> events(BufferedSource source) {
  return Observable.create(new Observable.OnSubscribe<String>() {
    @Override
    public void call(Subscriber<? super String> subscriber) {
      try {
        while (!source.exhausted()) {
          subscriber.onNext(source.readUtf8Line());
        }
      } catch (IOException e) {
        e.printStackTrace();
        subscriber.onError(e);
      }
      subscriber.onCompleted();
    }
  });
}

代码示例来源:origin: ittianyu/MobileGuard

/**
 * @return the device total memory in byte
 */
public static long getTotalMemory() {
  File file = new File("/proc/meminfo");
  BufferedSource source = null;
  try {
    // read meminfo file
    source = Okio.buffer(Okio.source(file));
    String totalMemoryStr = source.readUtf8Line();
    // get total memory
    String[] split = totalMemoryStr.split("\\s+");
    return Integer.valueOf(split[1]).intValue() * 1024;
  } catch (Exception e) {
    e.printStackTrace();
  } finally {
    try {
      if (source != null) {
        source.close();
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  return 0;
}

代码示例来源:origin: kubernetes-client/java

public Response<T> next() {
 try {
  String line = response.source().readUtf8Line();
  if (line == null) {
   throw new RuntimeException("Null response from the server.");
  }
  try {
   return json.deserialize(line, watchType);
  } catch (JsonParseException ex) {
   Type statusType = new TypeToken<Response<V1Status>>() {}.getType();
   Response<V1Status> status = json.deserialize(line, statusType);
   return new Response<T>(status.type, status.object);
  }
 } catch (IOException e) {
  throw new RuntimeException("IO Exception during next method.", e);
 }
}

代码示例来源:origin: io.kubernetes/client-java

public Response<T> next() {
 try {
  String line = response.source().readUtf8Line();
  if (line == null) {
   throw new RuntimeException("Null response from the server.");
  }
  try {
   return json.deserialize(line, watchType);
  } catch (JsonParseException ex) {
   Type statusType = new TypeToken<Response<V1Status>>() {}.getType();
   Response<V1Status> status = json.deserialize(line, statusType);
   return new Response<T>(status.type, status.object);
  }
 } catch (IOException e) {
  throw new RuntimeException("IO Exception during next method.", e);
 }
}

代码示例来源:origin: Azure/azure-libraries-for-java

@Override
  public void call(Emitter<String> stringEmitter) {
    try {
      while (!source.exhausted()) {
        stringEmitter.onNext(source.readUtf8Line());
      }
      stringEmitter.onCompleted();
    } catch (IOException e) {
      stringEmitter.onError(e);
    }
  }
}, BackpressureMode.BUFFER);

相关文章

微信公众号

最新文章

更多