把做工程过程经常用到的代码做个备份,如下的代码是关于Android下InputStream发生网络中断时的解决办法的代码,应该对小伙伴有较大用途。
static class FlushedInputStream extends FilterInputStream {
public FlushedInputStream(InputStream inputStream) {
super(inputStream);
}
@Override
public long skip(long n) throws IOException {
long totalBytesSkipped = 0L;
while (totalBytesSkipped < n) {
long bytesSkipped = in.skip(n - totalBytesSkipped);
if (bytesSkipped == 0L) {
int byte = read();
if (byte < 0) {
} else {
}
}
totalBytesSkipped += bytesSkipped;
}
return totalBytesSkipped;
}
复制代码
}