2 Replies Latest reply: Apr 16, 2013 3:00 AM by EJP RSS

    BufferedInputStream - size of buffer, mark, reset, skip - how it works?

    Rafal Z
      Hallo,
      I don't fully understand the relations of buffersize, mark and marklimit and skip of the class BufferedInptutStream. With the constructor BufferedInputStream(InputStream in, int size) I can set the size of Buffer. But what happens if I invoke the method mark(int n) where n is greater then the size of buffer used in the constructor? Does mark use own buffer, or it resizes the existing buffer?
      Does skip() work without using mark(), or I have to invoke mark() before I invoke skip()? Is it possibble to skip forward beyond the given buffersize/marklimit?

      With best regards

      Rafal Ziolkowski
        • 1. Re: BufferedInputStream - size of buffer, mark, reset, skip - how it works?
          EJP
          what happens if I invoke the method mark(int n) where n is greater then the size of buffer used in the constructor?
          It's supposed to work.
          Does mark use own buffer, or it resizes the existing buffer?
          It isn't specified.

          However:

          "The general contract of mark is that, if the method markSupported returns true, the stream somehow remembers all the bytes read after the call to mark and stands ready to supply those same bytes again if and whenever the method reset is called. However, the stream is not required to remember any data at all if more than readlimit bytes are read from the stream before reset is called."
          Does skip() work without using mark(), or I have to invoke mark() before I invoke skip()? Is it possibble to skip forward beyond the given buffersize/marklimit?
          skip() has nothing to do with mark. It just reads ahead without returning the skipped data.
          • 2. Re: BufferedInputStream - size of buffer, mark, reset, skip - how it works?
            Kayaman
            It's all explained in the javadocs. See InputStream's mark().