2008-12-16 18:34:01 -05:00
|
|
|
package com.android.email.mail.transport;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
|
|
|
import java.io.FilterOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
|
|
|
public class EOLConvertingOutputStream extends FilterOutputStream {
|
|
|
|
int lastChar;
|
|
|
|
|
|
|
|
public EOLConvertingOutputStream(OutputStream out) {
|
|
|
|
super(out);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void write(int oneByte) throws IOException {
|
|
|
|
if (oneByte == '\n') {
|
|
|
|
if (lastChar != '\r') {
|
|
|
|
super.write('\r');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
super.write(oneByte);
|
|
|
|
lastChar = oneByte;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void flush() throws IOException {
|
|
|
|
if (lastChar == '\r') {
|
|
|
|
super.write('\n');
|
|
|
|
lastChar = '\n';
|
|
|
|
}
|
|
|
|
super.flush();
|
|
|
|
}
|
|
|
|
}
|