Better handling of extensions in PiPipeconf

Now built using a URL, while input streams are generated on-demand.
Before it could happen that the input stream was completelly read by
someone, leaving it unusable by others.

Change-Id: I61a76bf8b8c1d2f6e2d987661025e0323d59e1c7
diff --git a/incubator/bmv2/model/src/main/java/org/onosproject/bmv2/model/Bmv2PipelineModelParser.java b/incubator/bmv2/model/src/main/java/org/onosproject/bmv2/model/Bmv2PipelineModelParser.java
index b7a1f15c..470ea78 100644
--- a/incubator/bmv2/model/src/main/java/org/onosproject/bmv2/model/Bmv2PipelineModelParser.java
+++ b/incubator/bmv2/model/src/main/java/org/onosproject/bmv2/model/Bmv2PipelineModelParser.java
@@ -30,10 +30,13 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.net.URL;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
 import static org.slf4j.LoggerFactory.getLogger;
 
 /**
@@ -75,13 +78,16 @@
     /**
      * Parse the input stream pointing to a BMv2 JSON configuration, to a Bmv2PipelineModel object.
      *
-     * @param jsonInputStream input stream pointing to a BMv2 JSON configuration
+     * @param url URL pointing to a BMv2 JSON configuration
      * @return Bmv2PipelineModel BMv2 pipeline model object
      */
-    public static Bmv2PipelineModel parse(InputStream jsonInputStream) {
+    public static Bmv2PipelineModel parse(URL url) {
+        checkNotNull(url, "Url cannot be null");
         try {
+            InputStream inputStream = url.openStream();
+            checkArgument(inputStream.available() > 0, "Empty or non-existent JSON at " + url.toString());
             return parse(Json.parse(new BufferedReader(
-                    new InputStreamReader(jsonInputStream))).asObject());
+                    new InputStreamReader(inputStream))).asObject());
         } catch (IOException e) {
             throw new RuntimeException(e);
         }