add toOutputStream(InputStream is, OutputStream os, long start, long end)
This commit is contained in:
@ -643,6 +643,24 @@ public class IO implements OS.FileSystem {
|
|||||||
return !interrupt;
|
return !interrupt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void toOutputStream(InputStream is, OutputStream os, long start, long end) throws IOException {
|
||||||
|
long skip = is.skip(start);
|
||||||
|
if (skip != start) {
|
||||||
|
throw new TimiException(TimiCode.ERROR, "skip fail");
|
||||||
|
}
|
||||||
|
byte[] buffer = new byte[8192];
|
||||||
|
long remaining = end - start + 1;
|
||||||
|
while (0 < remaining) {
|
||||||
|
int toRead = (int) Math.min(buffer.length, remaining);
|
||||||
|
int read = is.read(buffer, 0, toRead);
|
||||||
|
if (read == -1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
os.write(buffer, 0, read);
|
||||||
|
remaining -= read;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 写入字节到文件随机访问对象,此操作不会关闭流
|
* 写入字节到文件随机访问对象,此操作不会关闭流
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user