gpt4 book ai didi

java - 获取 BufferedReader 读取的文件中的偏移量?

转载 作者:行者123 更新时间:2023-11-29 08:07:28 26 4
gpt4 key购买 nike

我正在逐行读取文件。该文件由 CipherOutputStream 编码,然后由 DeflaterOutputStream 压缩。该文件可以包含 UTF-8 字符,如俄语字母等。

我想获取实际读取文件中的偏移量,或者br.ReadLine()命令读取的字节数。问题是文件既加密又放气,因此读取字符串的长度大于文件中读取的字节数。

            InputStream fis=tempURL.openStream();                       //in tempURL I've got an URL to download
CipherInputStream cis=new CipherInputStream(fis,pbeCipher); //CipherStream
InflaterInputStream iis=new InflaterInputStream(cis); //InflaterInputStream
BufferedReader br = new BufferedReader(
new InputStreamReader(iis, "UTF8")); //BufferedReader
br.readLine();

int fSize=tempURL.openConnection().getContentLength(); //Catch FileSize

最佳答案

使用 CountingInputStream来自 Apache Commons IO项目:

InputStream fis=tempURL.openStream();
CountingInputStream countStream = new CountingInputStream(fis);
CipherInputStream cis=new CipherInputStream(countStream,pbeCipher);
...

稍后您可以使用 countStream.getByteCount() 获取文件位置。

关于java - 获取 BufferedReader 读取的文件中的偏移量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10189034/

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