src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/URLReader.java

Print this page




  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.nashorn.api.scripting;
  27 
  28 import java.io.CharArrayReader;
  29 import java.io.IOException;
  30 import java.io.Reader;
  31 import java.net.URL;
  32 import java.nio.charset.Charset;
  33 import jdk.nashorn.internal.runtime.Source;
  34 
  35 /**
  36  * A Reader that reads from a URL. Used to make sure that the reader
  37  * reads content from given URL and can be trusted to do so.


  38  */

  39 public final class URLReader extends Reader {
  40     // underlying URL
  41     private final URL url;
  42     // Charset used to convert
  43     private final Charset cs;
  44 
  45     // lazily initialized underlying reader for URL
  46     private Reader reader;
  47 
  48     /**
  49      * Constructor
  50      *
  51      * @param url URL for this URLReader
  52      * @throws NullPointerException if url is null
  53      */
  54     public URLReader(final URL url) {
  55         this(url, (Charset)null);
  56     }
  57 
  58     /**




  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.nashorn.api.scripting;
  27 
  28 import java.io.CharArrayReader;
  29 import java.io.IOException;
  30 import java.io.Reader;
  31 import java.net.URL;
  32 import java.nio.charset.Charset;
  33 import jdk.nashorn.internal.runtime.Source;
  34 
  35 /**
  36  * A Reader that reads from a URL. Used to make sure that the reader
  37  * reads content from given URL and can be trusted to do so.
  38  *
  39  * @since 1.8u40
  40  */
  41 @jdk.Exported
  42 public final class URLReader extends Reader {
  43     // underlying URL
  44     private final URL url;
  45     // Charset used to convert
  46     private final Charset cs;
  47 
  48     // lazily initialized underlying reader for URL
  49     private Reader reader;
  50 
  51     /**
  52      * Constructor
  53      *
  54      * @param url URL for this URLReader
  55      * @throws NullPointerException if url is null
  56      */
  57     public URLReader(final URL url) {
  58         this(url, (Charset)null);
  59     }
  60 
  61     /**