add toOutputStream(InputStream is, OutputStream os, long start, long end)

This commit is contained in:
Timi
2026-01-05 01:51:58 +08:00
parent 77979be5fe
commit d0d4e0e633

View File

@ -643,6 +643,24 @@ public class IO implements OS.FileSystem {
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;
}
}
/**
* 写入字节到文件随机访问对象,此操作不会关闭流
*