com.squareup.okhttp.internal.Util.closeQuietly()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(4.0k)|赞(0)|评价(0)|浏览(214)

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

Util.closeQuietly介绍

暂无

代码示例

代码示例来源:origin: evernote/evernote-sdk-android

  1. @Override
  2. public void close() {
  3. Util.closeQuietly(mResponseBody);
  4. mResponseBody = null;
  5. }
  6. }

代码示例来源:origin: evernote/evernote-sdk-android

  1. private static void readFile(File file, byte[] buffer, int length) throws IOException {
  2. InputStream inputStream = null;
  3. try {
  4. inputStream = new FileInputStream(file);
  5. int read = 0;
  6. int offset = 0;
  7. while (length > 0 && read >= 0) {
  8. read = inputStream.read(buffer, offset, length);
  9. offset += read;
  10. length -= read;
  11. }
  12. } finally {
  13. Util.closeQuietly(inputStream);
  14. }
  15. }

代码示例来源:origin: evernote/evernote-sdk-android

  1. @Override
  2. public void close() throws IOException {
  3. if (!mClosed) {
  4. Util.closeQuietly(mFileOutputStream);
  5. mByteArrayOutputStream.reset();
  6. mClosed = true;
  7. }
  8. }

代码示例来源:origin: com.squareup.okhttp/mockwebserver

  1. @Override protected void execute() {
  2. try {
  3. logger.info(MockWebServer.this + " starting to accept connections");
  4. acceptConnections();
  5. } catch (Throwable e) {
  6. logger.log(Level.WARNING, MockWebServer.this + " failed unexpectedly", e);
  7. }
  8. // Release all sockets and all threads, even if any close fails.
  9. Util.closeQuietly(serverSocket);
  10. for (Iterator<Socket> s = openClientSockets.iterator(); s.hasNext(); ) {
  11. Util.closeQuietly(s.next());
  12. s.remove();
  13. }
  14. for (Iterator<FramedConnection> s = openFramedConnections.iterator(); s.hasNext(); ) {
  15. Util.closeQuietly(s.next());
  16. s.remove();
  17. }
  18. executor.shutdown();
  19. }

代码示例来源:origin: com.squareup.okhttp/mockwebserver

  1. private void run() throws Exception {
  2. ServerSocket serverSocket = new ServerSocket(8888);
  3. serverSocket.setReuseAddress(true);
  4. while (true) {
  5. Socket socket = null;
  6. try {
  7. socket = serverSocket.accept();
  8. SSLSocket sslSocket = doSsl(socket);
  9. String protocolString = Platform.get().getSelectedProtocol(sslSocket);
  10. Protocol protocol = protocolString != null ? Protocol.get(protocolString) : null;
  11. if (protocol == null || !framedProtocols.contains(protocol)) {
  12. throw new ProtocolException("Protocol " + protocol + " unsupported");
  13. }
  14. FramedConnection framedConnection = new FramedConnection.Builder(false)
  15. .socket(sslSocket)
  16. .protocol(protocol)
  17. .listener(this)
  18. .build();
  19. framedConnection.sendConnectionPreface();
  20. } catch (IOException e) {
  21. logger.log(Level.INFO, "FramedServer connection failure: " + e);
  22. Util.closeQuietly(socket);
  23. } catch (Exception e) {
  24. logger.log(Level.WARNING, "FramedServer unexpected failure", e);
  25. Util.closeQuietly(socket);
  26. }
  27. }
  28. }

代码示例来源:origin: com.squareup.okhttp/mockwebserver

  1. private void serveFile(FramedStream stream, File file) throws IOException {
  2. List<Header> responseHeaders = Arrays.asList(
  3. new Header(":status", "200"),
  4. new Header(":version", "HTTP/1.1"),
  5. new Header("content-type", contentType(file))
  6. );
  7. stream.reply(responseHeaders, true);
  8. Source source = Okio.source(file);
  9. try {
  10. BufferedSink out = Okio.buffer(stream.getSink());
  11. out.writeAll(source);
  12. out.close();
  13. } finally {
  14. Util.closeQuietly(source);
  15. }
  16. }

代码示例来源:origin: com.squareup.okhttp/mockwebserver

  1. Util.closeQuietly(sink);
  2. Util.closeQuietly(source);

代码示例来源:origin: liferay/liferay-mobile-sdk

  1. public static void transfer(
  2. InputStream is, FileProgressCallback callback, Object tag,
  3. BufferedSink sink)
  4. throws IOException {
  5. Source source = null;
  6. try {
  7. source = Okio.source(is);
  8. Buffer os = new Buffer();
  9. while ((source.read(os, 2048) != -1) && !isCancelled(callback)) {
  10. byte[] bytes = os.readByteArray();
  11. if (sink != null) {
  12. sink.write(bytes);
  13. }
  14. if (callback != null) {
  15. callback.onBytes(bytes);
  16. callback.increment(bytes.length);
  17. }
  18. }
  19. if (isCancelled(callback)) {
  20. HttpUtil.cancel(tag);
  21. }
  22. }
  23. finally {
  24. Util.closeQuietly(source);
  25. }
  26. }

代码示例来源:origin: com.squareup.okhttp/okhttp-ws

  1. private void createWebSocket(Response response, WebSocketListener listener) throws IOException {
  2. if (response.code() != 101) {
  3. Util.closeQuietly(response.body());
  4. throw new ProtocolException("Expected HTTP 101 response but was '"
  5. + response.code()

代码示例来源:origin: evernote/evernote-sdk-android

  1. @Override
  2. public void flush() throws TTransportException {
  3. Util.closeQuietly(mResponseBody);
  4. mResponseBody = null;

相关文章