CRLFOutputStreampublic class CRLFOutputStream extends FilterOutputStream Convert lines into the canonical MIME format, that is,
terminate lines with CRLF.
This stream can be used with the Part.writeTo and Message.writeTo
methods to generate the canonical MIME format of the data for the
purpose of (e.g.) sending it via SMTP or computing a digital
signature. |
Fields Summary |
---|
protected int | lastb | protected static byte[] | newline |
Constructors Summary |
---|
public CRLFOutputStream(OutputStream os)
newline = new byte[2];
newline[0] = (byte)'\r";
newline[1] = (byte)'\n";
super(os);
|
Methods Summary |
---|
public void | write(int b)
if (b == '\r") {
out.write(newline);
} else if (b == '\n") {
if (lastb != '\r")
out.write(newline);
} else {
out.write(b);
}
lastb = b;
| public void | write(byte[] b)
write(b, 0, b.length);
| public void | write(byte[] b, int off, int len)
int start = off;
len += off;
for (int i = start; i < len ; i++) {
if (b[i] == '\r") {
out.write(b, start, i - start);
out.write(newline);
start = i + 1;
} else if (b[i] == '\n") {
if (lastb != '\r") {
out.write(b, start, i - start);
out.write(newline);
}
start = i + 1;
}
lastb = b[i];
}
if ((len - start) > 0)
out.write(b, start, len - start);
|
|