Use InputStream's marksupported, Mark, and reset

Source: Internet
Author: User

Use InputStream's marksupported, Mark, and reset


Mark is used to mark the place, and then you can return to this mark's place when you call reset later.

The Mark method has an integer parameter that means to keep mark valid until so many characters are read.

For example, Mark (10), then the reset () operation can re-read the data that has been read after reading () 10 characters or less.

If you have read more than 10 data, the reset () operation will not read the previous data correctly, because the mark tag is invalidated at this time.


Marks the current position in this input stream.

A subsequent call to the Reset method repositions this stream at the last marked position so, subsequent reads re-read The same bytes.


The readlimit arguments tells this input stream to allow that many bytes to be read before the mark position gets Invalida Ted.

The general contract of Mark is,

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 I F and whenever the method, reset is called.

However, the stream is not required to remember any data @ all if more than Readlimit bytes was read from the stream befo Re Reset is called.


Marking a closed stream should not has any effect on the stream.


The mark method of InputStream does nothing.


@param readlimit The maximum limit of bytes that can be read before the mark position becomes invalid.

@see Java.io.inputstream#reset ()


Public synchronized void mark (int readlimit) {}



Repositions this stream to the position at the time the mark method is last called on the This input stream.


The general contract of Reset is:


If the method marksupported returnstrue, then:


If The method mark has not been called since the stream is created, or the number of bytes read from the stream

Since Mark was last called are larger than the argument to mark on that last call and then an IOException might being thrown.


If such an IOException was not thrown and then the stream was reset to a state such so all the bytes read since the

Most recent call to mark (or since the start of the file, if Mark have not been called) would be resupplied

To subsequent callers of the Read method, followed by any bytes that otherwise would has been the next input data as of

The time of the call to reset.


If the method marksupported returns false, then:


The call to reset could throw an IOException.


If an IOException isn't thrown, then the stream

is, reset to a, fixed state, depends on the particular type of the

Input stream and how it is created. The bytes that'll be supplied

To subsequent callers of the Read method depend on the

Particular type of the input stream.


The method of reset for class InputStream does nothing except throw a ioexception.

@exception IOException If this stream had not been marked or if the mark had been invalidated.

@see Java.io.inputstream#mark (int)

@see java.io.IOException

Public synchronized void Reset () throws IOException {

throw new IOException ("Mark/reset not supported");

}



Tests if this input stream supports the mark and reset methods.

Whether or not, mark and reset are supported was an invariant property of a particular input stream instance.

The marksupported methodof InputStream returns FALSE.


@return true if this stream instance supports the mark and reset methods; False otherwise.

@see Java.io.inputstream#mark (int)

@see Java.io.inputstream#reset ()

public boolean marksupported () {

return false;

}


Use InputStream's marksupported, Mark, and reset

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.