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

org.springframework.content.commons.io.ObservableOutputStream Maven / Gradle / Ivy

There is a newer version: 3.0.15
Show newest version
package org.springframework.content.commons.io;

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class ObservableOutputStream extends OutputStream {

    private final OutputStream delegate;
    private List observers;

    public ObservableOutputStream(OutputStream delegate) {
        this.delegate = delegate;
        this.observers = new ArrayList<>();
    }

    @Override
    public void write(int b) throws IOException {
        this.delegate.write(b);
    }

    @Override
    public void close() throws IOException {
        try {
            this.delegate.close();
        } finally {
            for (CloseableObserver observer : this.observers) {
                observer.closed();
            }
        }
    }

    public void addObservers(OutputStreamObserver... observers) {
        this.observers.addAll(Arrays.asList(observers));
    }

    public List getObservers() {
        return Collections.unmodifiableList(observers);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy