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

com.documents4j.job.InputStreamSourceFromInputStream Maven / Gradle / Ivy

There is a newer version: 1.1.12
Show newest version
package com.documents4j.job;

import com.documents4j.api.IInputStreamSource;
import com.documents4j.throwables.FileSystemInteractionException;
import com.google.common.base.MoreObjects;
import com.google.common.io.Closeables;

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

class InputStreamSourceFromInputStream implements IInputStreamSource {

    private final InputStream inputStream;

    private final boolean close;

    public InputStreamSourceFromInputStream(InputStream inputStream, boolean close) {
        this.inputStream = inputStream;
        this.close = close;
    }

    @Override
    public InputStream getInputStream() {
        return inputStream;
    }

    @Override
    public void onConsumed(InputStream inputStream) {
        try {
            if (close) {
                Closeables.close(inputStream, false);
            }
        } catch (IOException e) {
            throw new FileSystemInteractionException("Could not close input stream", e);
        }
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(InputStreamSourceFromInputStream.class)
                .add("inputStream", inputStream)
                .add("close", close)
                .toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy