import java.io.IOException;
import java.io.OutputStream;
public class CharTerminatedOutputStream extends OutputStream {
private OutputStream out;
private byte[] match;
public CharTerminatedOutputStream(OutputStream os, byte[] terminator) {
if (terminator == null) {
throw new IllegalArgumentException("The terminating character array cannot be null.");
}
if (terminator.length == 0) {
throw new IllegalArgumentException("The terminating character array cannot be of zero length.");
}
match = new byte[terminator.length];
for (int i = 0; i < terminator.length; i++) {
match[i] = terminator[i];
}
this.out = os;
}
public void write(int b) throws IOException {
out.write(b);
}
public void flush() throws IOException {
out.write(match);
out.flush();
}
}