All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.offbytwo.jenkins.client.util.RequestReleasingInputStream Maven / Gradle / Ivy

package com.offbytwo.jenkins.client.util;

import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.http.client.methods.HttpRequestBase;

/**
 * Releases the http request method if it is closed
 */
public class RequestReleasingInputStream extends FilterInputStream {
    private final HttpRequestBase httpRequestBase;

    /**
     * Creates a FilterInputStream by assigning the argument
     * in to the field this.in so as to remember it
     * for later use.
     *
     * @param in
     *            the underlying input stream, or null if this
     *            instance is to be created without an underlying stream.
     * @param httpRequestBase
     *            The request object that should be released if the stream
     *            closed
     */
    public RequestReleasingInputStream(InputStream in, HttpRequestBase httpRequestBase) {
        super(in);
        this.httpRequestBase = httpRequestBase;
    }

    /**
     * Closes this input stream and releases any system resources associated
     * with the stream. This method simply performs in.close().
     *
     * @throws IOException
     *             if an I/O error occurs.
     * @see FilterInputStream#in
     */
    @Override
    public void close() throws IOException {
        super.close();
        httpRequestBase.releaseConnection();

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy