Search in sources :

Example 1 with AbstractOutputStream

use of com.squareup.okhttp.internal.AbstractOutputStream in project cordova-android-chromeview by thedracle.

the class HttpURLConnectionImpl method getOutputStream.

@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()) {
                    // Don't recover once the underlying stream has been closed.
                    return null;
                }
                if (handleFailure(e)) {
                    return httpEngine.getRequestBody();
                }
                // This is a permanent failure.
                return null;
            }
        };
    }
    return faultRecoveringRequestBody;
}
Also used : ProtocolException(java.net.ProtocolException) FaultRecoveringOutputStream(com.squareup.okhttp.internal.FaultRecoveringOutputStream) OutputStream(java.io.OutputStream) AbstractOutputStream(com.squareup.okhttp.internal.AbstractOutputStream) AbstractOutputStream(com.squareup.okhttp.internal.AbstractOutputStream) IOException(java.io.IOException) FaultRecoveringOutputStream(com.squareup.okhttp.internal.FaultRecoveringOutputStream)

Example 2 with AbstractOutputStream

use of com.squareup.okhttp.internal.AbstractOutputStream in project phonegap-facebook-plugin by Wizcorp.

the class HttpURLConnectionImpl method getOutputStream.

@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()) {
                    // Don't recover once the underlying stream has been closed.
                    return null;
                }
                if (handleFailure(e)) {
                    return httpEngine.getRequestBody();
                }
                // This is a permanent failure.
                return null;
            }
        };
    }
    return faultRecoveringRequestBody;
}
Also used : ProtocolException(java.net.ProtocolException) FaultRecoveringOutputStream(com.squareup.okhttp.internal.FaultRecoveringOutputStream) OutputStream(java.io.OutputStream) AbstractOutputStream(com.squareup.okhttp.internal.AbstractOutputStream) AbstractOutputStream(com.squareup.okhttp.internal.AbstractOutputStream) IOException(java.io.IOException) FaultRecoveringOutputStream(com.squareup.okhttp.internal.FaultRecoveringOutputStream)

Aggregations

AbstractOutputStream (com.squareup.okhttp.internal.AbstractOutputStream)2 FaultRecoveringOutputStream (com.squareup.okhttp.internal.FaultRecoveringOutputStream)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 ProtocolException (java.net.ProtocolException)2