本文整理了Java中com.squareup.okhttp.internal.Util.closeQuietly()
方法的一些代码示例,展示了Util.closeQuietly()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.closeQuietly()
方法的具体详情如下:
包路径:com.squareup.okhttp.internal.Util
类名称:Util
方法名:closeQuietly
暂无
代码示例来源:origin: evernote/evernote-sdk-android
@Override
public void close() {
Util.closeQuietly(mResponseBody);
mResponseBody = null;
}
}
代码示例来源:origin: evernote/evernote-sdk-android
private static void readFile(File file, byte[] buffer, int length) throws IOException {
InputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
int read = 0;
int offset = 0;
while (length > 0 && read >= 0) {
read = inputStream.read(buffer, offset, length);
offset += read;
length -= read;
}
} finally {
Util.closeQuietly(inputStream);
}
}
代码示例来源:origin: evernote/evernote-sdk-android
@Override
public void close() throws IOException {
if (!mClosed) {
Util.closeQuietly(mFileOutputStream);
mByteArrayOutputStream.reset();
mClosed = true;
}
}
代码示例来源:origin: com.squareup.okhttp/mockwebserver
@Override protected void execute() {
try {
logger.info(MockWebServer.this + " starting to accept connections");
acceptConnections();
} catch (Throwable e) {
logger.log(Level.WARNING, MockWebServer.this + " failed unexpectedly", e);
}
// Release all sockets and all threads, even if any close fails.
Util.closeQuietly(serverSocket);
for (Iterator<Socket> s = openClientSockets.iterator(); s.hasNext(); ) {
Util.closeQuietly(s.next());
s.remove();
}
for (Iterator<FramedConnection> s = openFramedConnections.iterator(); s.hasNext(); ) {
Util.closeQuietly(s.next());
s.remove();
}
executor.shutdown();
}
代码示例来源:origin: com.squareup.okhttp/mockwebserver
private void run() throws Exception {
ServerSocket serverSocket = new ServerSocket(8888);
serverSocket.setReuseAddress(true);
while (true) {
Socket socket = null;
try {
socket = serverSocket.accept();
SSLSocket sslSocket = doSsl(socket);
String protocolString = Platform.get().getSelectedProtocol(sslSocket);
Protocol protocol = protocolString != null ? Protocol.get(protocolString) : null;
if (protocol == null || !framedProtocols.contains(protocol)) {
throw new ProtocolException("Protocol " + protocol + " unsupported");
}
FramedConnection framedConnection = new FramedConnection.Builder(false)
.socket(sslSocket)
.protocol(protocol)
.listener(this)
.build();
framedConnection.sendConnectionPreface();
} catch (IOException e) {
logger.log(Level.INFO, "FramedServer connection failure: " + e);
Util.closeQuietly(socket);
} catch (Exception e) {
logger.log(Level.WARNING, "FramedServer unexpected failure", e);
Util.closeQuietly(socket);
}
}
}
代码示例来源:origin: com.squareup.okhttp/mockwebserver
private void serveFile(FramedStream stream, File file) throws IOException {
List<Header> responseHeaders = Arrays.asList(
new Header(":status", "200"),
new Header(":version", "HTTP/1.1"),
new Header("content-type", contentType(file))
);
stream.reply(responseHeaders, true);
Source source = Okio.source(file);
try {
BufferedSink out = Okio.buffer(stream.getSink());
out.writeAll(source);
out.close();
} finally {
Util.closeQuietly(source);
}
}
代码示例来源:origin: com.squareup.okhttp/mockwebserver
Util.closeQuietly(sink);
Util.closeQuietly(source);
代码示例来源:origin: liferay/liferay-mobile-sdk
public static void transfer(
InputStream is, FileProgressCallback callback, Object tag,
BufferedSink sink)
throws IOException {
Source source = null;
try {
source = Okio.source(is);
Buffer os = new Buffer();
while ((source.read(os, 2048) != -1) && !isCancelled(callback)) {
byte[] bytes = os.readByteArray();
if (sink != null) {
sink.write(bytes);
}
if (callback != null) {
callback.onBytes(bytes);
callback.increment(bytes.length);
}
}
if (isCancelled(callback)) {
HttpUtil.cancel(tag);
}
}
finally {
Util.closeQuietly(source);
}
}
代码示例来源:origin: com.squareup.okhttp/okhttp-ws
private void createWebSocket(Response response, WebSocketListener listener) throws IOException {
if (response.code() != 101) {
Util.closeQuietly(response.body());
throw new ProtocolException("Expected HTTP 101 response but was '"
+ response.code()
代码示例来源:origin: evernote/evernote-sdk-android
@Override
public void flush() throws TTransportException {
Util.closeQuietly(mResponseBody);
mResponseBody = null;
内容来源于网络,如有侵权,请联系作者删除!