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


Java Util.closeQuietly方法代码示例

本文整理汇总了Java中com.squareup.okhttp.internal.Util.closeQuietly方法的典型用法代码示例。如果您正苦于以下问题:Java Util.closeQuietly方法的具体用法?Java Util.closeQuietly怎么用?Java Util.closeQuietly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.squareup.okhttp.internal.Util的用法示例。


在下文中一共展示了Util.closeQuietly方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import com.squareup.okhttp.internal.Util; //导入方法依赖的package包/类
public static RequestBody create(final MediaType contentType, final File file) {
    if (file != null) {
        return new RequestBody() {
            public MediaType contentType() {
                return contentType;
            }

            public long contentLength() {
                return file.length();
            }

            public void writeTo(BufferedSink sink) throws IOException {
                Closeable source = null;
                try {
                    source = Okio.source(file);
                    sink.writeAll(source);
                } finally {
                    Util.closeQuietly(source);
                }
            }
        };
    }
    throw new NullPointerException("content == null");
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:25,代码来源:RequestBody.java

示例2: execute

import com.squareup.okhttp.internal.Util; //导入方法依赖的package包/类
protected void execute() {
    ErrorCode connectionErrorCode = ErrorCode.INTERNAL_ERROR;
    ErrorCode streamErrorCode = ErrorCode.INTERNAL_ERROR;
    try {
        if (!FramedConnection.this.client) {
            this.frameReader.readConnectionPreface();
        }
        while (true) {
            if (!this.frameReader.nextFrame(this)) {
                break;
            }
        }
        connectionErrorCode = ErrorCode.NO_ERROR;
        streamErrorCode = ErrorCode.CANCEL;
    } catch (IOException e) {
        connectionErrorCode = ErrorCode.PROTOCOL_ERROR;
        streamErrorCode = ErrorCode.PROTOCOL_ERROR;
    } finally {
        try {
            FramedConnection.this.close(connectionErrorCode, streamErrorCode);
        } catch (IOException e2) {
        }
        Util.closeQuietly(this.frameReader);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:26,代码来源:FramedConnection.java

示例3: close

import com.squareup.okhttp.internal.Util; //导入方法依赖的package包/类
@Override
public void close() throws IOException {
    if (!mClosed) {
        Util.closeQuietly(mFileOutputStream);
        mByteArrayOutputStream.reset();
        mClosed = true;
    }
}
 
开发者ID:fivef,项目名称:add_to_evernote_note,代码行数:9,代码来源:DiskBackedByteStore.java

示例4: disconnect

import com.squareup.okhttp.internal.Util; //导入方法依赖的package包/类
@Override public final void disconnect() {
  // Calling disconnect() before a connection exists should have no effect.
  if (httpEngine != null) {
    // We close the response body here instead of in
    // HttpEngine.release because that is called when input
    // has been completely read from the underlying socket.
    // However the response body can be a GZIPInputStream that
    // still has unread data.
    if (httpEngine.hasResponse()) {
      Util.closeQuietly(httpEngine.getResponseBody());
    }
    httpEngine.release(true);
  }
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:15,代码来源:HttpURLConnectionImpl.java

示例5: abort

import com.squareup.okhttp.internal.Util; //导入方法依赖的package包/类
public void abort() {
    synchronized (Cache.this) {
        if (this.done) {
            return;
        }
        this.done = true;
        Cache.this.writeAbortCount = Cache.this.writeAbortCount + 1;
        Util.closeQuietly(this.cacheOut);
        try {
            this.editor.abort();
        } catch (IOException e) {
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:15,代码来源:Cache.java

示例6: recycle

import com.squareup.okhttp.internal.Util; //导入方法依赖的package包/类
/**
 * Gives {@code connection} to the pool. The pool may store the connection,
 * or close it, as its policy describes.
 *
 * <p>It is an error to use {@code connection} after calling this method.
 */
public void recycle(Connection connection) {
  if (connection.isSpdy()) {
    return;
  }

  if (!connection.isAlive()) {
    Util.closeQuietly(connection);
    return;
  }

  try {
    Platform.get().untagSocket(connection.getSocket());
  } catch (SocketException e) {
    // When unable to remove tagging, skip recycling and close.
    Platform.get().logW("Unable to untagSocket(): " + e);
    Util.closeQuietly(connection);
    return;
  }

  synchronized (this) {
    connections.addFirst(connection);
    connection.resetIdleStartTime();
  }

  executorService.submit(connectionsCleanupCallable);
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:33,代码来源:ConnectionPool.java

示例7: abort

import com.squareup.okhttp.internal.Util; //导入方法依赖的package包/类
@Override public void abort() {
  synchronized (HttpResponseCache.this) {
    if (done) {
      return;
    }
    done = true;
    writeAbortCount++;
  }
  Util.closeQuietly(cacheOut);
  try {
    editor.abort();
  } catch (IOException ignored) {
  }
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:15,代码来源:HttpResponseCache.java

示例8: cleanup

import com.squareup.okhttp.internal.Util; //导入方法依赖的package包/类
long cleanup(long now) {
    int inUseConnectionCount = 0;
    int idleConnectionCount = 0;
    RealConnection longestIdleConnection = null;
    long longestIdleDurationNs = Long.MIN_VALUE;
    synchronized (this) {
        for (RealConnection connection : this.connections) {
            if (pruneAndGetAllocationCount(connection, now) > 0) {
                inUseConnectionCount++;
            } else {
                idleConnectionCount++;
                long idleDurationNs = now - connection.idleAtNanos;
                if (idleDurationNs > longestIdleDurationNs) {
                    longestIdleDurationNs = idleDurationNs;
                    longestIdleConnection = connection;
                }
            }
        }
        if (longestIdleDurationNs >= this.keepAliveDurationNs || idleConnectionCount > this
                .maxIdleConnections) {
            this.connections.remove(longestIdleConnection);
            Util.closeQuietly(longestIdleConnection.getSocket());
            return 0;
        } else if (idleConnectionCount > 0) {
            r10 = this.keepAliveDurationNs - longestIdleDurationNs;
            return r10;
        } else if (inUseConnectionCount > 0) {
            r10 = this.keepAliveDurationNs;
            return r10;
        } else {
            return -1;
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:35,代码来源:ConnectionPool.java

示例9: evictAll

import com.squareup.okhttp.internal.Util; //导入方法依赖的package包/类
/** Close and remove all connections in the pool. */
public void evictAll() {
  List<Connection> connections;
  synchronized (this) {
    connections = new ArrayList<Connection>(this.connections);
    this.connections.clear();
  }

  for (Connection connection : connections) {
    Util.closeQuietly(connection);
  }
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:13,代码来源:ConnectionPool.java

示例10: close

import com.squareup.okhttp.internal.Util; //导入方法依赖的package包/类
public StreamAllocation close() {
    if (this.bufferedRequestBody != null) {
        Util.closeQuietly(this.bufferedRequestBody);
    } else if (this.requestBodyOut != null) {
        Util.closeQuietly(this.requestBodyOut);
    }
    if (this.userResponse != null) {
        Util.closeQuietly(this.userResponse.body());
    } else {
        this.streamAllocation.connectionFailed();
    }
    return this.streamAllocation;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:14,代码来源:HttpEngine.java

示例11: deallocate

import com.squareup.okhttp.internal.Util; //导入方法依赖的package包/类
private void deallocate(boolean noNewStreams, boolean released, boolean streamFinished) {
    RealConnection connectionToClose = null;
    synchronized (this.connectionPool) {
        if (streamFinished) {
            this.stream = null;
        }
        if (released) {
            this.released = true;
        }
        if (this.connection != null) {
            if (noNewStreams) {
                this.connection.noNewStreams = true;
            }
            if (this.stream == null && (this.released || this.connection.noNewStreams)) {
                release(this.connection);
                if (this.connection.streamCount > 0) {
                    this.routeSelector = null;
                }
                if (this.connection.allocations.isEmpty()) {
                    this.connection.idleAtNanos = System.nanoTime();
                    if (Internal.instance.connectionBecameIdle(this.connectionPool, this
                            .connection)) {
                        connectionToClose = this.connection;
                    }
                }
                this.connection = null;
            }
        }
    }
    if (connectionToClose != null) {
        Util.closeQuietly(connectionToClose.getSocket());
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:34,代码来源:StreamAllocation.java

示例12: get

import com.squareup.okhttp.internal.Util; //导入方法依赖的package包/类
/** Returns a recycled connection to {@code address}, or null if no such connection exists. */
public synchronized Connection get(Address address) {
  Connection foundConnection = null;
  for (ListIterator<Connection> i = connections.listIterator(connections.size());
      i.hasPrevious(); ) {
    Connection connection = i.previous();
    if (!connection.getRoute().getAddress().equals(address)
        || !connection.isAlive()
        || System.nanoTime() - connection.getIdleStartTimeNs() >= keepAliveDurationNs) {
      continue;
    }
    i.remove();
    if (!connection.isSpdy()) {
      try {
        Platform.get().tagSocket(connection.getSocket());
      } catch (SocketException e) {
        Util.closeQuietly(connection);
        // When unable to tag, skip recycling and close
        Platform.get().logW("Unable to tagSocket(): " + e);
        continue;
      }
    }
    foundConnection = connection;
    break;
  }

  if (foundConnection != null && foundConnection.isSpdy()) {
    connections.addFirst(foundConnection); // Add it back after iteration.
  }

  executorService.submit(connectionsCleanupCallable);
  return foundConnection;
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:34,代码来源:ConnectionPool.java

示例13: initResponseSource

import com.squareup.okhttp.internal.Util; //导入方法依赖的package包/类
/**
 * Initialize the source for this response. It may be corrected later if the
 * request headers forbids network use.
 */
private void initResponseSource() throws IOException {
  responseSource = ResponseSource.NETWORK;
  if (!policy.getUseCaches()) return;

  OkResponseCache responseCache = client.getOkResponseCache();
  if (responseCache == null) return;

  CacheResponse candidate = responseCache.get(
      uri, method, requestHeaders.getHeaders().toMultimap(false));
  if (candidate == null) return;

  Map<String, List<String>> responseHeadersMap = candidate.getHeaders();
  cachedResponseBody = candidate.getBody();
  if (!acceptCacheResponseType(candidate)
      || responseHeadersMap == null
      || cachedResponseBody == null) {
    Util.closeQuietly(cachedResponseBody);
    return;
  }

  RawHeaders rawResponseHeaders = RawHeaders.fromMultimap(responseHeadersMap, true);
  cachedResponseHeaders = new ResponseHeaders(uri, rawResponseHeaders);
  long now = System.currentTimeMillis();
  this.responseSource = cachedResponseHeaders.chooseResponseSource(now, requestHeaders);
  if (responseSource == ResponseSource.CACHE) {
    this.cacheResponse = candidate;
    setResponse(cachedResponseHeaders, cachedResponseBody);
  } else if (responseSource == ResponseSource.CONDITIONAL_CACHE) {
    this.cacheResponse = candidate;
  } else if (responseSource == ResponseSource.NETWORK) {
    Util.closeQuietly(cachedResponseBody);
  } else {
    throw new AssertionError();
  }
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:40,代码来源:HttpEngine.java

示例14: sendRequest

import com.squareup.okhttp.internal.Util; //导入方法依赖的package包/类
/**
 * Figures out what the response source will be, and opens a socket to that
 * source if necessary. Prepares the request headers and gets ready to start
 * writing the request body if it exists.
 */
public final void sendRequest() throws IOException {
  if (responseSource != null) {
    return;
  }

  prepareRawRequestHeaders();
  initResponseSource();
  OkResponseCache responseCache = client.getOkResponseCache();
  if (responseCache != null) {
    responseCache.trackResponse(responseSource);
  }

  // The raw response source may require the network, but the request
  // headers may forbid network use. In that case, dispose of the network
  // response and use a GATEWAY_TIMEOUT response instead, as specified
  // by http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.4.
  if (requestHeaders.isOnlyIfCached() && responseSource.requiresConnection()) {
    if (responseSource == ResponseSource.CONDITIONAL_CACHE) {
      Util.closeQuietly(cachedResponseBody);
    }
    this.responseSource = ResponseSource.CACHE;
    this.cacheResponse = GATEWAY_TIMEOUT_RESPONSE;
    RawHeaders rawResponseHeaders = RawHeaders.fromMultimap(cacheResponse.getHeaders(), true);
    setResponse(new ResponseHeaders(uri, rawResponseHeaders), cacheResponse.getBody());
  }

  if (responseSource.requiresConnection()) {
    sendSocketRequest();
  } else if (connection != null) {
    client.getConnectionPool().recycle(connection);
    connection = null;
  }
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:39,代码来源:HttpEngine.java

示例15: flush

import com.squareup.okhttp.internal.Util; //导入方法依赖的package包/类
@Override
public void flush() throws TTransportException {
    Util.closeQuietly(mResponseBody);
    mResponseBody = null;

    RequestBody requestBody = new RequestBody() {
        @Override
        public MediaType contentType() {
            if (mHeaders != null && mHeaders.containsKey("Content-Type")) {
                return MediaType.parse(mHeaders.get("Content-Type"));
            } else {
                return MEDIA_TYPE_THRIFT;
            }
        }

        @Override
        public void writeTo(BufferedSink sink) throws IOException {
            sink.write(mByteStore.getData(), 0, mByteStore.getBytesWritten());
        }
    };

    try {
        Request.Builder builder = new Request.Builder()
                .url(mUrl)
                .post(requestBody);

        if (mHeaders != null) {
            for (String name : mHeaders.keySet()) {
                builder.header(name, mHeaders.get(name));
            }
        }

        Response response = mHttpClient.newCall(builder.build()).execute();

        if (response.code() != 200) {
            throw new TTransportException("HTTP Response code: " + response.code() + ", message " + response.message());
        }

        mResponseBody = response.body().byteStream();

    } catch (Exception e) {
        throw new TTransportException(e);

    } finally {
        try {
            mByteStore.reset();
        } catch (IOException ignored) {
        }
    }
}
 
开发者ID:fivef,项目名称:add_to_evernote_note,代码行数:51,代码来源:TAndroidTransport.java


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