Search in sources :

Example 1 with ChunkedInputStream

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

the class EmptyInputStream method reset.

/**
     * Reset (without disconnecting the TCP conn) in order to do another transaction with this instance
     */
private void reset() throws IOException {
    http.reuse = true;
    /* must save before calling close */
    reuseClient = http;
    InputStream is = http.getInputStream();
    if (!method.equals("HEAD")) {
        try {
            /* we want to read the rest of the response without using the
                 * hurry mechanism, because that would close the connection
                 * if everything is not available immediately
                 */
            if ((is instanceof ChunkedInputStream) || (is instanceof MeteredStream)) {
                /* reading until eof will not block */
                while (is.read(cdata) > 0) {
                }
            } else {
                /* raw stream, which will block on read, so only read
                     * the expected number of bytes, probably 0
                     */
                long cl = 0;
                int n = 0;
                String cls = responses.findValue("Content-Length");
                if (cls != null) {
                    try {
                        cl = Long.parseLong(cls);
                    } catch (NumberFormatException e) {
                        cl = 0;
                    }
                }
                for (long i = 0; i < cl; ) {
                    if ((n = is.read(cdata)) == -1) {
                        break;
                    } else {
                        i += n;
                    }
                }
            }
        } catch (IOException e) {
            http.reuse = false;
            reuseClient = null;
            disconnectInternal();
            return;
        }
        try {
            if (is instanceof MeteredStream) {
                is.close();
            }
        } catch (IOException e) {
        }
    }
    responseCode = -1;
    responses = new MessageHeader();
    connected = false;
}
Also used : ChunkedInputStream(sun.net.www.http.ChunkedInputStream) ChunkedInputStream(sun.net.www.http.ChunkedInputStream)

Example 2 with ChunkedInputStream

use of sun.net.www.http.ChunkedInputStream in project Bytecoder by mirkosertic.

the class EmptyInputStream method reset.

/**
 * Reset (without disconnecting the TCP conn) in order to do another transaction with this instance
 */
private void reset() throws IOException {
    http.reuse = true;
    /* must save before calling close */
    reuseClient = http;
    InputStream is = http.getInputStream();
    if (!method.equals("HEAD")) {
        try {
            /* we want to read the rest of the response without using the
                 * hurry mechanism, because that would close the connection
                 * if everything is not available immediately
                 */
            if ((is instanceof ChunkedInputStream) || (is instanceof MeteredStream)) {
                /* reading until eof will not block */
                while (is.read(cdata) > 0) {
                }
            } else {
                /* raw stream, which will block on read, so only read
                     * the expected number of bytes, probably 0
                     */
                long cl = 0;
                int n = 0;
                String cls = responses.findValue("Content-Length");
                if (cls != null) {
                    try {
                        cl = Long.parseLong(cls);
                    } catch (NumberFormatException e) {
                        cl = 0;
                    }
                }
                for (long i = 0; i < cl; ) {
                    if ((n = is.read(cdata)) == -1) {
                        break;
                    } else {
                        i += n;
                    }
                }
            }
        } catch (IOException e) {
            http.reuse = false;
            reuseClient = null;
            disconnectInternal();
            return;
        }
        try {
            if (is instanceof MeteredStream) {
                is.close();
            }
        } catch (IOException e) {
        }
    }
    responseCode = -1;
    responses = new MessageHeader();
    connected = false;
}
Also used : ChunkedInputStream(sun.net.www.http.ChunkedInputStream) ChunkedInputStream(sun.net.www.http.ChunkedInputStream)

Aggregations

ChunkedInputStream (sun.net.www.http.ChunkedInputStream)2