很难在InputStream上附加剥离器,因为流是面向字节的。在一个特定的时间做这件事可能更有意义
Reader
public class StripReader extends Reader
{
private Reader in;
public StripReader(Reader in)
{
this.in = in;
}
public boolean markSupported()
{
return false;
}
public void mark(int readLimit)
{
throw new UnsupportedOperationException("Mark not supported");
}
public void reset()
{
throw new UnsupportedOperationException("Reset not supported");
}
public int read() throws IOException
{
int next;
do
{
next = in.read();
} while(!(next == -1 || Character.isValidCodePoint(next)));
return next;
}
public void close() throws IOException
{
in.close();
}
public int read(char[] cbuf, int off, int len) throws IOException
{
int i, next = 0;
for(i = 0; i < len; i++)
{
next = read();
if(next == -1)
break;
cbuf[off + i] = (char)next;
}
if(i == 0 && next == -1)
return -1;
else
return i;
}
public int read(char[] cbuf) throws IOException
{
return read(cbuf, 0, cbuf.length);
}
}
然后构建一个
InputSource