mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-25 17:18:50 -05:00
Fixed EOLConvertingOutputStream.
write('\r');flush();write('\n'); would lead to "\r\n\r\n" instead of simply "\r\n";
This commit is contained in:
parent
0422cae33e
commit
14ee970b18
@ -6,7 +6,8 @@ import java.io.OutputStream;
|
||||
|
||||
public class EOLConvertingOutputStream extends FilterOutputStream
|
||||
{
|
||||
int lastChar;
|
||||
private int lastChar;
|
||||
private boolean ignoreNextIfLF = false;
|
||||
|
||||
public EOLConvertingOutputStream(OutputStream out)
|
||||
{
|
||||
@ -16,16 +17,17 @@ public class EOLConvertingOutputStream extends FilterOutputStream
|
||||
@Override
|
||||
public void write(int oneByte) throws IOException
|
||||
{
|
||||
if (oneByte == '\n')
|
||||
if (!ignoreNextIfLF)
|
||||
{
|
||||
if (lastChar != '\r')
|
||||
if ((oneByte == '\n') && (lastChar != '\r'))
|
||||
{
|
||||
super.write('\r');
|
||||
}
|
||||
}
|
||||
super.write(oneByte);
|
||||
lastChar = oneByte;
|
||||
}
|
||||
ignoreNextIfLF = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws IOException
|
||||
@ -34,6 +36,11 @@ public class EOLConvertingOutputStream extends FilterOutputStream
|
||||
{
|
||||
super.write('\n');
|
||||
lastChar = '\n';
|
||||
|
||||
// We have to ignore the next character if it is <LF>. Otherwise it
|
||||
// will be expanded to an additional <CR><LF> sequence although it
|
||||
// belongs to the one just completed.
|
||||
ignoreNextIfLF = true;
|
||||
}
|
||||
super.flush();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user