EOLConvertingInputStreampublic class EOLConvertingInputStream extends InputStream InputStream which converts \r
bytes not followed by \n and \n not
preceded by \r to \r\n . |
Fields Summary |
---|
public static final int | CONVERT_CRConverts single '\r' to '\r\n' | public static final int | CONVERT_LFConverts single '\n' to '\r\n' | public static final int | CONVERT_BOTHConverts single '\r' and '\n' to '\r\n' | private PushbackInputStream | in | private int | previous | private int | flags |
Constructors Summary |
---|
public EOLConvertingInputStream(InputStream in)Creates a new EOLConvertingInputStream
instance converting bytes in the given InputStream .
The flag CONVERT_BOTH is the default.
this(in, CONVERT_BOTH);
| public EOLConvertingInputStream(InputStream in, int flags)Creates a new EOLConvertingInputStream
instance converting bytes in the given InputStream .
super();
this.in = new PushbackInputStream(in, 2);
this.flags = flags;
|
Methods Summary |
---|
public void | close()Closes the underlying stream.
in.close();
| public int | read()
int b = in.read();
if (b == -1) {
return -1;
}
if ((flags & CONVERT_CR) != 0 && b == '\r") {
int c = in.read();
if (c != -1) {
in.unread(c);
}
if (c != '\n") {
in.unread('\n");
}
} else if ((flags & CONVERT_LF) != 0 && b == '\n" && previous != '\r") {
b = '\r";
in.unread('\n");
}
previous = b;
return b;
|
|