用于判断字符结尾的输出流类

原创 2004年07月23日 13:46:00

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();
  }
}

收藏助手
不良信息举报
您举报文章:用于判断字符结尾的输出流类
举报原因:
原因补充:

(最多只允许输入30个字)