src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Source.java

Print this page

        

@@ -482,10 +482,34 @@
 
     /**
      * Constructor
      *
      * @param name  source name
+     * @param path  path from which source can be loaded
+     *
+     * @return source instance
+     *
+     * @throws IOException if source cannot be loaded
+     */
+    public static Source sourceFor(final String name, final Path path) throws IOException {
+        File file = null;
+        try {
+            file = path.toFile();
+        } catch (final UnsupportedOperationException uoe) {
+        } 
+        
+        if (file != null) {
+            return sourceFor(name, file);
+        } else {
+            return sourceFor(name, Files.newBufferedReader(path));
+        }
+    }
+    
+    /**
+     * Constructor
+     *
+     * @param name  source name
      * @param file  file from which source can be loaded
      * @param cs    Charset used to convert bytes to chars
      *
      * @return source instance
      *

@@ -599,11 +623,11 @@
         return data.url();
     }
 
     /**
      * Get explicit source URL.
-     * @return URL set vial sourceURL directive
+     * @return URL set via sourceURL directive
      */
     public String getExplicitURL() {
         return explicitURL;
     }