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

com.github.dockerjava.jaxrs.util.WrappedResponseInputStream Maven / Gradle / Ivy

There is a newer version: 3.4.0_1
Show newest version
package com.github.dockerjava.jaxrs.util;

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

import javax.ws.rs.core.Response;

/**
 * This is a wrapper around {@link Response} that acts as a {@link InputStream}. When this {@link WrappedResponseInputStream} is closed it
 * closes the underlying {@link Response} object also to prevent blocking/hanging connections.
 *
 * @author Marcus Linke
 */
public class WrappedResponseInputStream extends InputStream {

    private Response response;

    private InputStream delegate;

    private boolean closed = false;

    public WrappedResponseInputStream(Response response) {
        this.response = response;
        this.delegate = response.readEntity(InputStream.class);
    }

    public int read() throws IOException {
        return delegate.read();
    }

    public int hashCode() {
        return delegate.hashCode();
    }

    public int read(byte[] b) throws IOException {
        return delegate.read(b);
    }

    public boolean equals(Object obj) {
        return delegate.equals(obj);
    }

    public int read(byte[] b, int off, int len) throws IOException {
        return delegate.read(b, off, len);
    }

    public long skip(long n) throws IOException {
        return delegate.skip(n);
    }

    public int available() throws IOException {
        return delegate.available();
    }

    public void close() throws IOException {
        if (closed) {
            return;
        }
        closed = true;
        delegate.close();
        response.close();
    }

    public void mark(int readlimit) {
        delegate.mark(readlimit);
    }

    public void reset() throws IOException {
        delegate.reset();
    }

    public boolean markSupported() {
        return delegate.markSupported();
    }

    public boolean isClosed() {
        return closed;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy