Class URLReader

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.lang.Readable

    public final class URLReader
    extends java.io.Reader
    A Reader that reads from a URL. Used to make sure that the reader reads content from given URL and can be trusted to do so.
    Since:
    1.8u40
    • Field Summary

      • Fields inherited from class java.io.Reader

        lock
    • Constructor Summary

      Constructors 
      Constructor Description
      URLReader​(java.net.URL url)
      Constructor
      URLReader​(java.net.URL url, java.lang.String charsetName)
      Constructor
      URLReader​(java.net.URL url, java.nio.charset.Charset cs)
      Constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      java.nio.charset.Charset getCharset()
      Charset used by this reader
      java.net.URL getURL()
      URL of this reader
      int read​(char[] cbuf, int off, int len)  
      • Methods inherited from class java.io.Reader

        mark, markSupported, nullReader, read, read, read, ready, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • URLReader

        public URLReader​(java.net.URL url)
        Constructor
        Parameters:
        url - URL for this URLReader
        Throws:
        java.lang.NullPointerException - if url is null
      • URLReader

        public URLReader​(java.net.URL url,
                         java.lang.String charsetName)
        Constructor
        Parameters:
        url - URL for this URLReader
        charsetName - Name of the Charset used to convert bytes to chars
        Throws:
        java.lang.NullPointerException - if url is null
      • URLReader

        public URLReader​(java.net.URL url,
                         java.nio.charset.Charset cs)
        Constructor
        Parameters:
        url - URL for this URLReader
        cs - Charset used to convert bytes to chars
        Throws:
        java.lang.NullPointerException - if url is null
    • Method Detail

      • read

        public int read​(char[] cbuf,
                        int off,
                        int len)
                 throws java.io.IOException
        Specified by:
        read in class java.io.Reader
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in class java.io.Reader
        Throws:
        java.io.IOException
      • getURL

        public java.net.URL getURL()
        URL of this reader
        Returns:
        the URL from which this reader reads.
      • getCharset

        public java.nio.charset.Charset getCharset()
        Charset used by this reader
        Returns:
        the Charset used to convert bytes to chars