Search in sources :

Example 1 with PosterOutputStream

use of sun.net.www.http.PosterOutputStream in project jdk8u_jdk by JetBrains.

the class EmptyInputStream method getOutputStream0.

private synchronized OutputStream getOutputStream0() throws IOException {
    try {
        if (!doOutput) {
            throw new ProtocolException("cannot write to a URLConnection" + " if doOutput=false - call setDoOutput(true)");
        }
        if (method.equals("GET")) {
            // Backward compatibility
            method = "POST";
        }
        if ("TRACE".equals(method) && "http".equals(url.getProtocol())) {
            throw new ProtocolException("HTTP method TRACE" + " doesn't support output");
        }
        // if there's already an input stream open, throw an exception
        if (inputStream != null) {
            throw new ProtocolException("Cannot write output after reading input.");
        }
        if (!checkReuseConnection())
            connect();
        boolean expectContinue = false;
        String expects = requests.findValue("Expect");
        if ("100-Continue".equalsIgnoreCase(expects) && streaming()) {
            http.setIgnoreContinue(false);
            expectContinue = true;
        }
        if (streaming() && strOutputStream == null) {
            writeRequests();
        }
        if (expectContinue) {
            expect100Continue();
        }
        ps = (PrintStream) http.getOutputStream();
        if (streaming()) {
            if (strOutputStream == null) {
                if (chunkLength != -1) {
                    /* chunked */
                    strOutputStream = new StreamingOutputStream(new ChunkedOutputStream(ps, chunkLength), -1L);
                } else {
                    /* must be fixed content length */
                    long length = 0L;
                    if (fixedContentLengthLong != -1) {
                        length = fixedContentLengthLong;
                    } else if (fixedContentLength != -1) {
                        length = fixedContentLength;
                    }
                    strOutputStream = new StreamingOutputStream(ps, length);
                }
            }
            return strOutputStream;
        } else {
            if (poster == null) {
                poster = new PosterOutputStream();
            }
            return poster;
        }
    } catch (RuntimeException e) {
        disconnectInternal();
        throw e;
    } catch (ProtocolException e) {
        // Save the response code which may have been set while enforcing
        // the 100-continue. disconnectInternal() forces it to -1
        int i = responseCode;
        disconnectInternal();
        responseCode = i;
        throw e;
    } catch (IOException e) {
        disconnectInternal();
        throw e;
    }
}
Also used : ProtocolException(java.net.ProtocolException) ChunkedOutputStream(sun.net.www.http.ChunkedOutputStream) PosterOutputStream(sun.net.www.http.PosterOutputStream)

Aggregations

ProtocolException (java.net.ProtocolException)1 ChunkedOutputStream (sun.net.www.http.ChunkedOutputStream)1 PosterOutputStream (sun.net.www.http.PosterOutputStream)1