IT. Expert System.

Android Reference

Reader


java.io

Class Reader

  • All Implemented Interfaces:
    Closeable, AutoCloseable, Readable
    Direct Known Subclasses:
    BufferedReader, CharArrayReader, FilterReader, InputStreamReader, PipedReader, StringReader


    public abstract class Reader
    extends Object
    implements Readable, Closeable
    The base class for all readers. A reader is a means of reading data from a source in a character-wise manner. Some readers also support marking a position in the input and returning to this position later.

    This abstract class does not provide a fully working implementation, so it needs to be subclassed, and at least the read(char[], int, int) and close() methods needs to be overridden. Overriding some of the non-abstract methods is also often advised, since it might result in higher efficiency.

    Many specialized readers for purposes like reading from a file already exist in this package.

    See Also:
    Writer
    • Field Summary

      Fields
      Modifier and Type Field and Description
      protected Object lock
      The object used to synchronize access to the reader.
    • Constructor Summary

      Constructors
      Modifier Constructor and Description
      protected Reader()
      Constructs a new Reader with this as the object used to synchronize critical sections.
      protected Reader(Object lock)
      Constructs a new Reader with lock used to synchronize critical sections.
    • Method Summary

      Methods
      Modifier and Type Method and Description
      abstract void close()
      Closes this reader.
      void mark(int readLimit)
      Sets a mark position in this reader.
      boolean markSupported()
      Indicates whether this reader supports the mark() and reset() methods.
      int read()
      Reads a single character from this reader and returns it as an integer with the two higher-order bytes set to 0.
      int read(char[] buf)
      Reads characters from this reader and stores them in the character array buf starting at offset 0.
      abstract int read(char[] buf, int offset, int count)
      Reads at most count characters from this reader and stores them at offset in the character array buf.
      int read(CharBuffer target)
      Reads characters and puts them into the target character buffer.
      boolean ready()
      Indicates whether this reader is ready to be read without blocking.
      void reset()
      Resets this reader's position to the last mark() location.
      long skip(long charCount)
      Skips charCount characters in this reader.
    • Field Detail

      • lock

        protected Object lock
        The object used to synchronize access to the reader.
    • Constructor Detail

      • Reader

        protected Reader()
        Constructs a new Reader with this as the object used to synchronize critical sections.
      • Reader

        protected Reader(Object lock)
        Constructs a new Reader with lock used to synchronize critical sections.
        Parameters:
        lock - the Object used to synchronize critical sections.
        Throws:
        NullPointerException - if lock is null.
    • Method Detail

      • close

        public abstract void close()
                            throws IOException
        Closes this reader. Implementations of this method should free any resources associated with the reader.
        Specified by:
        close in interface Closeable
        Specified by:
        close in interface AutoCloseable
        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 characters can be read before the mark is invalidated. Calling reset() will reposition the reader back to the marked position if readLimit has not been surpassed.

        This default implementation simply throws an IOException; subclasses must provide their own implementation.

        Parameters:
        readLimit - the number of characters that can be read before the mark is invalidated.
        Throws:
        IllegalArgumentException - if readLimit < 0.
        IOException - if an error occurs while setting a mark in this reader.
        See Also:
        markSupported(), reset()
      • markSupported

        public boolean markSupported()
        Indicates whether this reader supports the mark() and reset() methods. This default implementation returns false.
        Returns:
        always false.
      • read

        public int read()
                 throws IOException
        Reads a single character from this reader and returns it as an integer with the two higher-order bytes set to 0. Returns -1 if the end of the reader has been reached.
        Returns:
        the character read or -1 if the end of the reader has been reached.
        Throws:
        IOException - if this reader is closed or some other I/O error occurs.
      • read

        public int read(char[] buf)
                 throws IOException
        Reads characters from this reader and stores them in the character array buf starting at offset 0. Returns the number of characters actually read or -1 if the end of the reader has been reached.
        Parameters:
        buf - character array to store the characters read.
        Returns:
        the number of characters read or -1 if the end of the reader has been reached.
        Throws:
        IOException - if this reader is closed or some other I/O error occurs.
      • read

        public abstract int read(char[] buf,
               int offset,
               int count)
                          throws IOException
        Reads at most count characters from this reader and stores them at offset in the character array buf. Returns the number of characters actually read or -1 if the end of the reader has been reached.
        Parameters:
        buf - the character array 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 read.
        Returns:
        the number of characters read or -1 if the end of the reader has been reached.
        Throws:
        IOException - if this reader is closed or some other I/O error occurs.
      • ready

        public boolean ready()
                      throws IOException
        Indicates whether this reader is ready to be read without blocking. Returns true if this reader will not block when read is called, false if unknown or blocking will occur. This default implementation always returns false.
        Returns:
        always false.
        Throws:
        IOException - if this reader is closed or some other I/O error occurs.
        See Also:
        read(), read(char[]), read(char[], int, int)
      • reset

        public void reset()
                   throws IOException
        Resets this reader's position to the last mark() location. Invocations of read() and skip() will occur from this new location. If this reader has not been marked, the behavior of reset() is implementation specific. This default implementation throws an IOException.
        Throws:
        IOException - always thrown in this default implementation.
        See Also:
        mark(int), markSupported()
      • skip

        public long skip(long charCount)
                  throws IOException
        Skips charCount characters in this reader. Subsequent calls of read methods will not return these characters unless reset is used. This method may perform multiple reads to read charCount characters.
        Returns:
        the number of characters actually skipped.
        Throws:
        IllegalArgumentException - if charCount < 0.
        IOException - if this reader is closed or some other I/O error occurs.
        See Also:
        mark(int), markSupported(), reset()
      • read

        public int read(CharBuffer target)
                 throws IOException
        Reads characters and puts them into the target character buffer.
        Specified by:
        read in interface Readable
        Parameters:
        target - the destination character buffer.
        Returns:
        the number of characters put into target or -1 if the end of this reader has been reached before a character has been read.
        Throws:
        IOException - if any I/O error occurs while reading from this reader.
        NullPointerException - if target is null.
        ReadOnlyBufferException - if target is read-only.


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 52 / 158670280. Delta: 0.03830 с