com.squareup.okhttp.internal.AbstractOutputStream Java Examples

The following examples show how to use com.squareup.okhttp.internal.AbstractOutputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpTransport.java    From L.TileLayer.Cordova with MIT License 5 votes vote down vote up
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;
}
 
Example #2
Source File: HttpTransport.java    From IoTgo_Android_App with MIT License 5 votes vote down vote up
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;
}
 
Example #3
Source File: HttpTransport.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #4
Source File: HttpTransport.java    From bluemix-parking-meter with MIT License 5 votes vote down vote up
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;
}
 
Example #5
Source File: HttpTransport.java    From reader with MIT License 5 votes vote down vote up
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;
}
 
Example #6
Source File: HttpTransport.java    From reader with MIT License 5 votes vote down vote up
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;
}
 
Example #7
Source File: HttpTransport.java    From cordova-amazon-fireos with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #8
Source File: HttpTransport.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
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;
}
 
Example #9
Source File: HttpTransport.java    From CordovaYoutubeVideoPlayer with MIT License 5 votes vote down vote up
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;
}
 
Example #10
Source File: HttpURLConnectionImpl.java    From cordova-android-chromeview with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #11
Source File: HttpTransport.java    From cordova-android-chromeview with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #12
Source File: HttpTransport.java    From wildfly-samples with MIT License 5 votes vote down vote up
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;
}
 
Example #13
Source File: HttpURLConnectionImpl.java    From phonegap-plugin-loading-spinner with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #14
Source File: HttpTransport.java    From phonegap-plugin-loading-spinner with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #15
Source File: HttpTransport.java    From crosswalk-cordova-android with Apache License 2.0 5 votes vote down vote up
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;
}