DotStuffingInputStreampublic class DotStuffingInputStream extends FilterInputStream Removes the dot-stuffing happening during the NNTP and SMTP message
transfer |
Fields Summary |
---|
protected int[] | lastAn array to hold the last two bytes read off the stream.
This allows the stream to detect '\r\n' sequences even
when they occur across read boundaries. |
Constructors Summary |
---|
public DotStuffingInputStream(InputStream in)
super(in);
last[0] = -1;
last[1] = -1;
|
Methods Summary |
---|
public int | read()Read through the stream, checking for '\r\n.'
int b = in.read();
if (b == '." && last[0] == '\r" && last[1] == '\n") {
//skip this '.' because it should have been stuffed
b = in.read();
}
last[0] = last[1];
last[1] = b;
return b;
| public int | read(byte[] b, int off, int len)Read through the stream, checking for '\r\n.'
if (b == null) {
throw new NullPointerException();
} else if ((off < 0) || (off > b.length) || (len < 0) ||
((off + len) > b.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
}
int c = read();
if (c == -1) {
return -1;
}
b[off] = (byte)c;
int i = 1;
for (; i < len ; i++) {
c = read();
if (c == -1) {
break;
}
if (b != null) {
b[off + i] = (byte)c;
}
}
return i;
|
|