Class TFilterReader

java.lang.Object
org.teavm.classlib.java.io.TReader
org.teavm.classlib.java.io.TFilterReader
All Implemented Interfaces:
TCloseable, TAutoCloseable, TReadable
Direct Known Subclasses:
TPushbackReader

public abstract class TFilterReader extends TReader
Wraps an existing
invalid reference
Reader
and performs some transformation on the input data while it is being read. Transformations can be anything from a simple byte-wise filtering input data to an on-the-fly compression or decompression of the underlying reader. Readers that wrap another reader and provide some additional functionality on top of it usually inherit from this class.
See Also:
  • invalid reference
    FilterWriter
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected TReader
    The target Reader which is being filtered.

    Fields inherited from class org.teavm.classlib.java.io.TReader

    lock
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Constructs a new FilterReader on the Reader in.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes this reader.
    void
    mark(int readlimit)
    Sets a mark position in this reader.
    boolean
    Indicates whether this reader supports mark() and reset().
    int
    Reads a single character from the filtered reader and returns it as an integer with the two higher-order bytes set to 0.
    int
    read(char[] buffer, int offset, int count)
    Reads at most count characters from the filtered reader and stores them in the byte array buffer starting at offset.
    boolean
    Indicates whether this reader is ready to be read without blocking.
    void
    Resets this reader's position to the last marked location.
    long
    skip(long count)
    Skips count characters in this reader.

    Methods inherited from class org.teavm.classlib.java.io.TReader

    read, read

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • in

      protected TReader in
      The target Reader which is being filtered.
  • Constructor Details

    • TFilterReader

      protected TFilterReader(TReader in)
      Constructs a new FilterReader on the Reader in.
      Parameters:
      in - The non-null Reader to filter reads on.
  • Method Details

    • close

      public void close() throws IOException
      Closes this reader. This implementation closes the filtered reader.
      Throws:
      IOException - if an error occurs while closing this reader.
    • mark

      public void mark(int readlimit) throws IOException
      Sets a mark position in this reader. The parameter readlimit indicates how many bytes can be read before the mark is invalidated. Sending reset() will reposition this reader back to the marked position, provided that readlimit has not been surpassed.

      This implementation sets a mark in the filtered reader.

      Overrides:
      mark in class TReader
      Parameters:
      readlimit - the number of bytes that can be read from this reader before the mark is invalidated.
      Throws:
      IOException - if an error occurs while marking this reader.
      See Also:
    • markSupported

      public boolean markSupported()
      Indicates whether this reader supports mark() and reset(). This implementation returns whether the filtered reader supports marking.
      Overrides:
      markSupported in class TReader
      Returns:
      true if mark() and reset() are supported by the filtered reader, false otherwise.
      See Also:
    • read

      public int read() throws IOException
      Reads a single character from the filtered reader and returns it as an integer with the two higher-order bytes set to 0. Returns -1 if the end of the filtered reader has been reached.
      Overrides:
      read in class TReader
      Returns:
      The character read or -1 if the end of the filtered reader has been reached.
      Throws:
      IOException - if an error occurs while reading from this reader.
    • read

      public int read(char[] buffer, int offset, int count) throws IOException
      Reads at most count characters from the filtered reader and stores them in the byte array buffer starting at offset. Returns the number of characters actually read or -1 if no characters were read and the end of the filtered reader was encountered.
      Specified by:
      read in class TReader
      Parameters:
      buffer - the char array in which to store the characters read.
      offset - the initial position in buffer to store the characters read from this reader.
      count - the maximum number of characters to store in buffer.
      Returns:
      the number of characters actually read or -1 if the end of the filtered reader has been reached while reading.
      Throws:
      IOException - if an error occurs while reading from this reader.
    • ready

      public boolean ready() throws IOException
      Indicates whether this reader is ready to be read without blocking. If the result is true, the next read() will not block. If the result is false, this reader may or may not block when read() is sent.
      Overrides:
      ready in class TReader
      Returns:
      true if this reader will not block when read() is called, false if unknown or blocking will occur.
      Throws:
      IOException - if the reader is closed or some other I/O error occurs.
    • reset

      public void reset() throws IOException
      Resets this reader's position to the last marked location. Invocations of read() and skip() will occur from this new location. If this reader was not marked, the behavior depends on the implementation of reset() in the Reader subclass that is filtered by this reader. The default behavior for Reader is to throw an IOException.
      Overrides:
      reset in class TReader
      Throws:
      IOException - if a problem occurred or the filtered reader does not support mark() and reset().
      See Also:
    • skip

      public long skip(long count) throws IOException
      Skips count characters in this reader. Subsequent read()'s will not return these characters unless reset() is used. The default implementation is to skip characters in the filtered reader.
      Overrides:
      skip in class TReader
      Parameters:
      count - the maximum number of characters to skip.
      Returns:
      the number of characters actually skipped.
      Throws:
      IOException - if the filtered reader is closed or some other I/O error occurs.
      See Also: