I have a program which has a wrapper on the OutputStream and inside the wrapper I a list of streams. Take a look code below
private static final class SomeWrapper extends OutputStream {
private final List<OutputStream> dest;
@Override
public void write(int b) throws IOException {
for (OutputStream destination : dest) {
destination.write(b);
}
}
@Override
public void write(byte[] bytes, int off, int len) throws IOException {
for (OutputStream destination : dest) {
destination.write(bytes, off, len);
}
}
@Override
@SneakyThrows
public void close() {
super.close();
for (OutputStream destination : dest) {
destination.close();
}
dest.clear();
}
}
So, if wrapper contains a lot of OutputStreams - application crashes with OOM. What pattern or approach would be better here, to control how much streams I can use based on the system resources(for example Xmx could be 512Mb and 2Gb). dest - is a list of BufferedOutputStream. So inside I have a buffer