mark method

void mark(
  1. int readAheadLimit
)

Marks the present position in the stream.

Subsequent calls to reset() will attempt to reposition the stream to this point.

Parameters

  • readAheadLimit: Limit on the number of characters that may be read while still preserving the mark

Example

final reader = BufferedReader(FileReader('config.txt'));
if (reader.markSupported()) {
  reader.mark(1024); // Allow up to 1024 characters to be read
  
  // Try to detect file format
  final firstLine = await reader.readLine();
  
  if (firstLine?.startsWith('<?xml') == true) {
    // Reset and process as XML
    await reader.reset();
    processXml(reader);
  } else {
    // Reset and process as plain text
    await reader.reset();
    processText(reader);
  }
}

Throws IOException if the stream does not support mark, or if some other I/O error occurs.

Implementation

void mark(int readAheadLimit) {
  // Default implementation does nothing
}