下面列出了怎么用com.squareup.okhttp.internal.AbstractOutputStream的API类实例代码及写法,或者点击链接到github查看源代码。
public boolean makeReusable(boolean streamCanceled, OutputStream requestBodyOut,
InputStream responseBodyIn) {
if (streamCanceled) {
return false;
}
// We cannot reuse sockets that have incomplete output.
if (requestBodyOut != null && !((AbstractOutputStream) requestBodyOut).isClosed()) {
return false;
}
// If the request specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.requestHeaders.hasConnectionClose()) {
return false;
}
// If the response specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.responseHeaders != null && httpEngine.responseHeaders.hasConnectionClose()) {
return false;
}
if (responseBodyIn instanceof UnknownLengthHttpInputStream) {
return false;
}
if (responseBodyIn != null) {
return discardStream(httpEngine, responseBodyIn);
}
return true;
}
public boolean makeReusable(boolean streamCanceled, OutputStream requestBodyOut,
InputStream responseBodyIn) {
if (streamCanceled) {
return false;
}
// We cannot reuse sockets that have incomplete output.
if (requestBodyOut != null && !((AbstractOutputStream) requestBodyOut).isClosed()) {
return false;
}
// If the request specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.requestHeaders.hasConnectionClose()) {
return false;
}
// If the response specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.responseHeaders != null && httpEngine.responseHeaders.hasConnectionClose()) {
return false;
}
if (responseBodyIn instanceof UnknownLengthHttpInputStream) {
return false;
}
if (responseBodyIn != null) {
return discardStream(httpEngine, responseBodyIn);
}
return true;
}
public boolean makeReusable(boolean streamCanceled, OutputStream requestBodyOut, InputStream responseBodyIn) {
if (streamCanceled) {
return false;
}
// We cannot reuse sockets that have incomplete output.
if (requestBodyOut != null && !((AbstractOutputStream) requestBodyOut).isClosed()) {
return false;
}
// If the request specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.requestHeaders.hasConnectionClose()) {
return false;
}
// If the response specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.responseHeaders != null && httpEngine.responseHeaders.hasConnectionClose()) {
return false;
}
if (responseBodyIn instanceof UnknownLengthHttpInputStream) {
return false;
}
if (responseBodyIn != null) {
return discardStream(httpEngine, responseBodyIn);
}
return true;
}
public boolean makeReusable(boolean streamCanceled, OutputStream requestBodyOut,
InputStream responseBodyIn) {
if (streamCanceled) {
return false;
}
// We cannot reuse sockets that have incomplete output.
if (requestBodyOut != null && !((AbstractOutputStream) requestBodyOut).isClosed()) {
return false;
}
// If the request specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.requestHeaders.hasConnectionClose()) {
return false;
}
// If the response specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.responseHeaders != null && httpEngine.responseHeaders.hasConnectionClose()) {
return false;
}
if (responseBodyIn instanceof UnknownLengthHttpInputStream) {
return false;
}
if (responseBodyIn != null) {
return discardStream(httpEngine, responseBodyIn);
}
return true;
}
public boolean makeReusable(boolean streamCanceled, OutputStream requestBodyOut,
InputStream responseBodyIn) {
if (streamCanceled) {
return false;
}
// We cannot reuse sockets that have incomplete output.
if (requestBodyOut != null && !((AbstractOutputStream) requestBodyOut).isClosed()) {
return false;
}
// If the request specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.requestHeaders.hasConnectionClose()) {
return false;
}
// If the response specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.responseHeaders != null && httpEngine.responseHeaders.hasConnectionClose()) {
return false;
}
if (responseBodyIn instanceof UnknownLengthHttpInputStream) {
return false;
}
if (responseBodyIn != null) {
return discardStream(httpEngine, responseBodyIn);
}
return true;
}
public boolean makeReusable(boolean streamCanceled, OutputStream requestBodyOut,
InputStream responseBodyIn) {
if (streamCanceled) {
return false;
}
// We cannot reuse sockets that have incomplete output.
if (requestBodyOut != null && !((AbstractOutputStream) requestBodyOut).isClosed()) {
return false;
}
// If the request specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.requestHeaders.hasConnectionClose()) {
return false;
}
// If the response specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.responseHeaders != null && httpEngine.responseHeaders.hasConnectionClose()) {
return false;
}
if (responseBodyIn instanceof UnknownLengthHttpInputStream) {
return false;
}
if (responseBodyIn != null) {
return discardStream(httpEngine, responseBodyIn);
}
return true;
}
public boolean makeReusable(boolean streamCanceled, OutputStream requestBodyOut,
InputStream responseBodyIn) {
if (streamCanceled) {
return false;
}
// We cannot reuse sockets that have incomplete output.
if (requestBodyOut != null && !((AbstractOutputStream) requestBodyOut).isClosed()) {
return false;
}
// If the request specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.requestHeaders.hasConnectionClose()) {
return false;
}
// If the response specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.responseHeaders != null && httpEngine.responseHeaders.hasConnectionClose()) {
return false;
}
if (responseBodyIn instanceof UnknownLengthHttpInputStream) {
return false;
}
if (responseBodyIn != null) {
return discardStream(httpEngine, responseBodyIn);
}
return true;
}
public boolean makeReusable(boolean streamCanceled, OutputStream requestBodyOut,
InputStream responseBodyIn) {
if (streamCanceled) {
return false;
}
// We cannot reuse sockets that have incomplete output.
if (requestBodyOut != null && !((AbstractOutputStream) requestBodyOut).isClosed()) {
return false;
}
// If the request specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.requestHeaders.hasConnectionClose()) {
return false;
}
// If the response specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.responseHeaders != null && httpEngine.responseHeaders.hasConnectionClose()) {
return false;
}
if (responseBodyIn instanceof UnknownLengthHttpInputStream) {
return false;
}
if (responseBodyIn != null) {
return discardStream(httpEngine, responseBodyIn);
}
return true;
}
public boolean makeReusable(boolean streamCanceled, OutputStream requestBodyOut,
InputStream responseBodyIn) {
if (streamCanceled) {
return false;
}
// We cannot reuse sockets that have incomplete output.
if (requestBodyOut != null && !((AbstractOutputStream) requestBodyOut).isClosed()) {
return false;
}
// If the request specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.requestHeaders.hasConnectionClose()) {
return false;
}
// If the response specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.responseHeaders != null && httpEngine.responseHeaders.hasConnectionClose()) {
return false;
}
if (responseBodyIn instanceof UnknownLengthHttpInputStream) {
return false;
}
if (responseBodyIn != null) {
return discardStream(httpEngine, responseBodyIn);
}
return true;
}
@Override public final OutputStream getOutputStream() throws IOException {
connect();
OutputStream out = httpEngine.getRequestBody();
if (out == null) {
throw new ProtocolException("method does not support a request body: " + method);
} else if (httpEngine.hasResponse()) {
throw new ProtocolException("cannot write request body after response has been read");
}
if (faultRecoveringRequestBody == null) {
faultRecoveringRequestBody = new FaultRecoveringOutputStream(MAX_REPLAY_BUFFER_LENGTH, out) {
@Override protected OutputStream replacementStream(IOException e) throws IOException {
if (httpEngine.getRequestBody() instanceof AbstractOutputStream
&& ((AbstractOutputStream) httpEngine.getRequestBody()).isClosed()) {
return null; // Don't recover once the underlying stream has been closed.
}
if (handleFailure(e)) {
return httpEngine.getRequestBody();
}
return null; // This is a permanent failure.
}
};
}
return faultRecoveringRequestBody;
}
public boolean makeReusable(boolean streamCancelled, OutputStream requestBodyOut,
InputStream responseBodyIn) {
if (streamCancelled) {
return false;
}
// We cannot reuse sockets that have incomplete output.
if (requestBodyOut != null && !((AbstractOutputStream) requestBodyOut).isClosed()) {
return false;
}
// If the request specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.requestHeaders.hasConnectionClose()) {
return false;
}
// If the response specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.responseHeaders != null && httpEngine.responseHeaders.hasConnectionClose()) {
return false;
}
if (responseBodyIn instanceof UnknownLengthHttpInputStream) {
return false;
}
if (responseBodyIn != null) {
return discardStream(httpEngine, responseBodyIn);
}
return true;
}
public boolean makeReusable(boolean streamCanceled, OutputStream requestBodyOut,
InputStream responseBodyIn) {
if (streamCanceled) {
return false;
}
// We cannot reuse sockets that have incomplete output.
if (requestBodyOut != null && !((AbstractOutputStream) requestBodyOut).isClosed()) {
return false;
}
// If the request specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.requestHeaders.hasConnectionClose()) {
return false;
}
// If the response specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.responseHeaders != null && httpEngine.responseHeaders.hasConnectionClose()) {
return false;
}
if (responseBodyIn instanceof UnknownLengthHttpInputStream) {
return false;
}
if (responseBodyIn != null) {
return discardStream(httpEngine, responseBodyIn);
}
return true;
}
@Override public final OutputStream getOutputStream() throws IOException {
connect();
OutputStream out = httpEngine.getRequestBody();
if (out == null) {
throw new ProtocolException("method does not support a request body: " + method);
} else if (httpEngine.hasResponse()) {
throw new ProtocolException("cannot write request body after response has been read");
}
if (faultRecoveringRequestBody == null) {
faultRecoveringRequestBody = new FaultRecoveringOutputStream(MAX_REPLAY_BUFFER_LENGTH, out) {
@Override protected OutputStream replacementStream(IOException e) throws IOException {
if (httpEngine.getRequestBody() instanceof AbstractOutputStream
&& ((AbstractOutputStream) httpEngine.getRequestBody()).isClosed()) {
return null; // Don't recover once the underlying stream has been closed.
}
if (handleFailure(e)) {
return httpEngine.getRequestBody();
}
return null; // This is a permanent failure.
}
};
}
return faultRecoveringRequestBody;
}
public boolean makeReusable(boolean streamCancelled, OutputStream requestBodyOut,
InputStream responseBodyIn) {
if (streamCancelled) {
return false;
}
// We cannot reuse sockets that have incomplete output.
if (requestBodyOut != null && !((AbstractOutputStream) requestBodyOut).isClosed()) {
return false;
}
// If the request specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.requestHeaders.hasConnectionClose()) {
return false;
}
// If the response specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.responseHeaders != null && httpEngine.responseHeaders.hasConnectionClose()) {
return false;
}
if (responseBodyIn instanceof UnknownLengthHttpInputStream) {
return false;
}
if (responseBodyIn != null) {
return discardStream(httpEngine, responseBodyIn);
}
return true;
}
public boolean makeReusable(boolean streamCanceled, OutputStream requestBodyOut,
InputStream responseBodyIn) {
if (streamCanceled) {
return false;
}
// We cannot reuse sockets that have incomplete output.
if (requestBodyOut != null && !((AbstractOutputStream) requestBodyOut).isClosed()) {
return false;
}
// If the request specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.requestHeaders.hasConnectionClose()) {
return false;
}
// If the response specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.responseHeaders != null && httpEngine.responseHeaders.hasConnectionClose()) {
return false;
}
if (responseBodyIn instanceof UnknownLengthHttpInputStream) {
return false;
}
if (responseBodyIn != null) {
return discardStream(httpEngine, responseBodyIn);
}
return true;
}