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

com.heroku.sdk.deploy.util.io.UploadProgressHttpEntity Maven / Gradle / Ivy

There is a newer version: 3.0.7
Show newest version
package com.heroku.sdk.deploy.util.io;

import org.apache.http.Header;
import org.apache.http.HttpEntity;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.function.Consumer;

public class UploadProgressHttpEntity implements HttpEntity {
    private HttpEntity wrappedEntity;
    private Consumer progressConsumer;

    public UploadProgressHttpEntity(HttpEntity wrappedEntity, Consumer progressConsumer) {
        this.wrappedEntity = wrappedEntity;
        this.progressConsumer = progressConsumer;
    }

    @Override
    public boolean isRepeatable() {
        return wrappedEntity.isRepeatable();
    }

    @Override
    public boolean isChunked() {
        return wrappedEntity.isChunked();
    }

    @Override
    public long getContentLength() {
        return wrappedEntity.getContentLength();
    }

    @Override
    public Header getContentType() {
        return wrappedEntity.getContentType();
    }

    @Override
    public Header getContentEncoding() {
        return wrappedEntity.getContentEncoding();
    }

    @Override
    public InputStream getContent() throws IOException, UnsupportedOperationException {
        return wrappedEntity.getContent();
    }

    @Override
    public void writeTo(OutputStream outputStream) throws IOException {
        CountingOutputStream countingOutputStream = new CountingOutputStream(outputStream, progressConsumer);
        wrappedEntity.writeTo(countingOutputStream);
    }

    @Override
    public boolean isStreaming() {
        return wrappedEntity.isStreaming();
    }

    @Override
    @SuppressWarnings("deprecation")
    public void consumeContent() throws IOException {
        wrappedEntity.consumeContent();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy