package com.example.dateplanner.utils;

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

public class InputStreamCollector {
    private InputStream inputStream;
    private long totalSize = 0;

    public InputStreamCollector collectInputStream(InputStream is) {
        try {
            int available = is.available();
            totalSize += available;
        } catch (IOException ignored) {}

        if (this.inputStream == null) {
            this.inputStream = is;
        } else {
            this.inputStream = new SequenceInputStream(this.inputStream, is);
        }
        return this;
    }

    public InputStream getStream() {
        return inputStream;
    }

    public long getTotalSize() {
        return totalSize;
    }

    public void closeStream() throws IOException {
        if (inputStream != null) {
            inputStream.close();
        }
    }
}
