我想知道是否有人可以帮助使用 ScatterZipOutputStream 实现并行 Zip 创建。我已经搜索了很多,但没有找到相同的示例。
https://commons.apache.org/proper/commons-compress/zip.html
我尝试使用 ZipArchiveOutputStream 制作 Zip、压缩目录等。现在,我正在尝试同时做到这一点。
public static void makeZip(String filename) throws IOException,
ArchiveException {
File sourceFile = new File(filename);
final OutputStream out = new FileOutputStream(filename.substring(0, filename.lastIndexOf('.')) + ".zip");
ZipArchiveOutputStream os = new ZipArchiveOutputStream(out);
os.setUseZip64(Zip64Mode.AsNeeded);
os.putArchiveEntry(new ZipArchiveEntry(sourceFile.getName()));
IOUtils.copy(new FileInputStream(sourceFile), os);
os.closeArchiveEntry();
os.close();
}
Run Code Online (Sandbox Code Playgroud)
它应该能够作为线程处理单个文件,然后将其组合起来写入结果 zip。
def fib_gen():
a, b = 0, 1
while True:
yield a
a, b = b, a + b
print(next(fib_gen()))
print(next(fib_gen()))
print(next(fib_gen()))
print(next(fib_gen()))
Output: 0
0
0
0
Run Code Online (Sandbox Code Playgroud)
我试图在python中创建一个无限的Fibonacci生成器.请帮忙......我哪里做错了?