更改索引定位于为InputStream [英] changing the index positioning in InputStream
问题描述
我有一个二进制文件,其中包含密钥和之后每键有与之相关联的图像。我想跳下去不同的密钥,但没有找到任何这改变了指数定位于输入流的方法。我已经看到了标记()
方法,但它不能在不同的地方往下跳。
I have a binary file which contains keys and after every key there is an image associated with it. I want to jump off different keys but could not find any method which changes the index positioning in input stream. I have seen the mark()
method but it does not jump on different places.
没有任何人有任何想法如何做到这一点?
Does anybody have any idea how to do that?
推荐答案
有一个的 长跳(N久)
,你可能能够使用方法:
There's a long skip(long n)
method that you may be able to use:
跳过和放弃从输入流中数据的n
字节。该跳
方法,可由于种种原因,最终跳过的字节一些数量较少,可能是 0
。这可能是由于任意数量的条件; 前N到达文件结尾
字节被跳过只是一种可能性。的实际字节数目返回跳过。如果 N
为负,则不跳过任何字节。
Skips over and discards
n
bytes of data from this input stream. Theskip
method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly0
. This may result from any of a number of conditions; reaching end of file beforen
bytes have been skipped is only one possibility. The actual number of bytes skipped is returned. Ifn
is negative, no bytes are skipped.
由于记录的,你不能保证 N
字节将被跳过,所以总是doublecheck返回值。请注意,这不会让你快退,但如果它的 的markSupported()
,你可以的 复位()
第一和那么的跳
前进到一个较早的位置,如果你必须这样做。
As documented, you're not guaranteed that n
bytes will be skipped, so doublecheck the returned value always. Note that this does not allow you to "skip backward", but if it's markSupported()
, you can reset()
first and then skip
forward to an earlier position if you must.
您也可以使用 java.io.RandomAccessFile中的
,该顾名思义,允许其的 求(长POS)
的方法。
You may also use java.io.RandomAccessFile
, which as the name implies, permits random access with its seek(long pos)
method.
您提到的图像,因此,如果您使用的是 Java高级图像,另一种可能的选择是<一个href="http://download.oracle.com/docs/cd/E17802_01/products/products/java-media/jai/forDevelopers/jai-apidocs/com/sun/media/jai/$c$cc/FileSeekableStream.html"相对=nofollow> com.sun.media.jai。codec.FileSeekableStream
,这是一个<一个href="http://download.oracle.com/docs/cd/E17802_01/products/products/java-media/jai/forDevelopers/jai-apidocs/com/sun/media/jai/$c$cc/SeekableStream.html"相对=nofollow> SeekableStream
这需要从文件
或 RandomAccessFile的
。注意,这个类不是JAI API的承诺的一部分。它可能会被删除或JAI的未来版本中改变。
You mentioned images, so if you are using Java Advanced Imaging, another possible option is com.sun.media.jai.codec.FileSeekableStream
, which is a SeekableStream
that takes its input from a File
or RandomAccessFile
. Note that this class is not a committed part of the JAI API. It may be removed or changed in future releases of JAI.
这篇关于更改索引定位于为InputStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!