You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.4 KiB
60 lines
1.4 KiB
16 years ago
|
/**
|
||
|
* MultiOutputStream.java
|
||
|
* @since 26.08.2008
|
||
|
*/
|
||
12 years ago
|
package net.yacy.server.http;
|
||
16 years ago
|
|
||
|
import java.io.IOException;
|
||
|
import java.io.OutputStream;
|
||
|
|
||
|
/**
|
||
|
* writes to multiple {link OutputStream}s (parallel)
|
||
|
*
|
||
|
* @author daniel
|
||
|
*
|
||
|
*/
|
||
16 years ago
|
public class MultiOutputStream extends OutputStream {
|
||
16 years ago
|
|
||
|
private final OutputStream[] streams;
|
||
|
|
||
|
/**
|
||
|
* creates a new MultiOutputStream
|
||
|
*
|
||
|
* @param streams
|
||
|
*/
|
||
|
public MultiOutputStream(final OutputStream[] streams) {
|
||
|
super();
|
||
|
// make a copy to avoid external modifications
|
||
|
this.streams = new OutputStream[streams.length];
|
||
|
System.arraycopy(streams, 0, this.streams, 0, streams.length);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* writes the byte to each of the streams
|
||
|
*
|
||
|
* @see java.io.OutputStream#write(int)
|
||
|
*/
|
||
|
@Override
|
||
|
public void write(int b) throws IOException {
|
||
16 years ago
|
for (OutputStream stream: streams) {
|
||
16 years ago
|
stream.write(b);
|
||
|
}
|
||
|
}
|
||
16 years ago
|
|
||
|
/**
|
||
|
* writes the byte[] to each of the streams
|
||
|
* overriding this high-level method causes less overhead
|
||
|
* than overriding only the low-level write method:
|
||
|
* it causes (a large number) less 'for' loops
|
||
|
*
|
||
|
* @see java.io.OutputStream#write(int)
|
||
|
*/
|
||
|
@Override
|
||
|
public void write(byte[] b, int start, int len) throws IOException {
|
||
|
for (OutputStream stream: streams) {
|
||
|
stream.write(b, start, len);
|
||
|
}
|
||
|
}
|
||
16 years ago
|
|
||
|
}
|