gpt4 book ai didi

java - 更改 InputStream 中的索引定位

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:52:45 26 4
gpt4 key购买 nike

我有一个包含 key 的二进制文件,在每个 key 之后都有一个与之关联的图像。我想跳出不同的键,但找不到任何改变输入流中索引定位的方法。我见过 mark() 方法,但它不会跳到不同的地方。

有人知道怎么做吗?

最佳答案

有一个 long skip(long n)您可以使用的方法:

Skips over and discards n bytes of data from this input stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. This may result from any of a number of conditions; reaching end of file before n bytes have been skipped is only one possibility. The actual number of bytes skipped is returned. If n is negative, no bytes are skipped.

如文档所述,您不能保证 n 字节会被跳过,因此请始终仔细检查返回值。请注意,这不允许您“向后跳过”,但如果它是 markSupported() , 你可以 reset() first and then skip 如果必须的话,前进到更早的位置。


其他选项

您也可以使用 java.io.RandomAccessFile ,顾名思义,允许使用其 seek(long pos) 进行随机访问方法。

你提到了图像,所以如果你使用 Java Advanced Imaging , 另一个可能的选项是 com.sun.media.jai.codec.FileSeekableStream ,这是一个 SeekableStreamFileRandomAccessFile 获取输入。请注意,此类不是 JAI API 的已提交部分。它可能会在 JAI 的 future 版本中被删除或更改。

关于java - 更改 InputStream 中的索引定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3474911/

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