Как использовать markSupported функцию inputstream Java

Да, это

Из документации:

'linear': игнорировать индекс и рассматривать значения как одинаково расположенные

. Поэтому , если ваш индекс расположен на одинаковом расстоянии и вы используете правильный метод (метод time для индекса времени в вашем примере, но он также может быть методом index для числового индекса с одинаково расположенными значениями), вы действительно получите тот же результат.

6
задан 22 April 2009 в 14:08
поделиться

2 ответа

You could use a BufferedInputStream around whatever other stream you've got. That's guaranteed to support mark/reset, so long as you don't try to read beyond the buffer size after marking.

9
ответ дан 8 December 2019 в 13:02
поделиться

Take a look at PushbackInputStream, which looks like it's designed to do what you want.

It'll wrap an existing input stream and allow you to read a byte, and then put it back. From the Javadoc:

A PushbackInputStream adds functionality to another input stream, namely the ability to "push back" or "unread" one byte. This is useful in situations where it is convenient for a fragment of code to read an indefinite number of data bytes that are delimited by a particular byte value; after reading the terminating byte, the code fragment can "unread" it, so that the next read operation on the input stream will reread the byte that was pushed back. For example, bytes representing the characters constituting an identifier might be terminated by a byte representing an operator character; a method whose job is to read just an identifier can read until it sees the operator and then push the operator back to be re-read.

9
ответ дан 8 December 2019 в 13:02
поделиться
Другие вопросы по тегам:

Похожие вопросы: