2009-12-14 21:50:53 -05:00
|
|
|
package com.fsck.k9.mail.transport;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
|
|
|
import java.io.FilterOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public class EOLConvertingOutputStream extends FilterOutputStream
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
int lastChar;
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public EOLConvertingOutputStream(OutputStream out)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
super(out);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2009-11-24 19:40:29 -05:00
|
|
|
public void write(int oneByte) throws IOException
|
|
|
|
{
|
|
|
|
if (oneByte == '\n')
|
|
|
|
{
|
|
|
|
if (lastChar != '\r')
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
super.write('\r');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
super.write(oneByte);
|
|
|
|
lastChar = oneByte;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2009-11-24 19:40:29 -05:00
|
|
|
public void flush() throws IOException
|
|
|
|
{
|
|
|
|
if (lastChar == '\r')
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
super.write('\n');
|
|
|
|
lastChar = '\n';
|
|
|
|
}
|
|
|
|
super.flush();
|
|
|
|
}
|
|
|
|
}
|