gpt4 book ai didi

java - 如何访问谷歌云数据流中压缩源的每个条目?并获取每个子文件的Byte[]

转载 作者:行者123 更新时间:2023-11-30 07:13:22 24 4
gpt4 key购买 nike

我有一个压缩文件,它是由谷歌存储上的多个文本文件组成的 gzip 文件。我需要访问每个子文件并执行一些操作,例如正则表达式。我可以像这样在本地计算机上执行相同的操作。

pubic static void untarFile( String filepath ) throw IOException {
try {
FileInputStream fin = new FileInputStream(filepath);
BufferedInputStream in = new BufferedInputStream(fin);
GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in);
TarArchiveInputStream tarInput = new TarArchiveInputStream(gzIn);
TarArchiveEntry entry = null;
while ((entry = (TarArchiveEntry) tarInput.getNextTarEntry() ) != null) {
byte[] fileContent = new byte (int)entry.getSize() ];
tarInput.read(fileContent, 0, fileContent.length);
}
}
}

因此,我可以对 fileContent(一个 byte[ ])进行一些其他操作。所以我用了CompressedSource在google cloud dataflow上并引用其test code看来我只能从文件中获取每个字节,而不是子文件的整个 byet[],所以我想知道是否有任何解决方案可以在谷歌云数据流上执行此操作。

最佳答案

TextIO 不直接支持此功能,但您可以创建 FileBasedSource 的新子类去做这个。您需要重写 isSplittable() 以始终返回 false,然后让 readNextRecord() 读取整个文件。

关于java - 如何访问谷歌云数据流中压缩源的每个条目?并获取每个子文件的Byte[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38809620/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com