Class MarkableSequenceReader

java.lang.Object
java.io.Reader
org.postgresql.pljava.internal.MarkableSequenceReader
All Implemented Interfaces:
Closeable, AutoCloseable, Readable

public class MarkableSequenceReader extends Reader
Like a MarkableSequenceInputStream but for characters.

This class implements mark and reset by calling the corresponding methods on the underlying readers; it does not add buffering or have any means of providing mark and reset support if the underlying readers do not.

As with SequenceInputStream, each underlying reader, when completely read and no longer needed, is closed to free resources. This instance itself will remain in "open at EOF" condition until explicitly closed, but does not prevent reclamation of the underlying readers.

Unlike SequenceInputStream, this class can keep underlying readers open, after fully reading them, if a mark has been set, so that reset will be possible. When a mark is no longer needed, it can be canceled (by calling mark with a readlimit of 0) to again allow the underlying readers to be reclaimed as soon as possible.

  • Constructor Details

    • MarkableSequenceReader

      public MarkableSequenceReader(Reader... streams)
      Create a MarkableSequenceReader from one or more existing readers.
      Parameters:
      streams - Sequence of Readers that will be read from in order.
      Throws:
      NullPointerException - if streams is null, or contains null for any stream.
  • Method Details

    • read

      public int read() throws IOException
      Overrides:
      read in class Reader
      Throws:
      IOException
    • read

      public int read(char[] b, int off, int len) throws IOException
      Specified by:
      read in class Reader
      Throws:
      IOException
    • skip

      public long skip(long n) throws IOException
      Overrides:
      skip in class Reader
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class Reader
      Throws:
      IOException
    • mark

      public void mark(int readlimit) throws IOException
      Marks the current position in this reader. In this implementation, it is possible to 'cancel' a mark, by passing this method a readlimit of zero, returning the reader immediately to the state of having no mark.
      Overrides:
      mark in class Reader
      Throws:
      IOException
    • reset

      public void reset() throws IOException
      Overrides:
      reset in class Reader
      Throws:
      IOException
    • markSupported

      public boolean markSupported()
      Tests if this reader supports the mark and reset methods.

      For any instance of this class, the result is determined by the first call to this method, and does not change thereafter. At the first call, the result is determined only by the underlying readers remaining to be read (or, if a mark has been set, which is possible before checking this method, then by the underlying readers including and following the one that was current when the mark was set). The result will be true unless any of those underlying readers reports it as false.

      Overrides:
      markSupported in class Reader