private void extractNetworks(InputStream is, String entryName) throws Exception {
    CyNetworkReader reader = networkReaderMgr.getReader(is, entryName);
    reader.run(taskMonitor);
    final CyNetwork[] netArray = reader.getNetworks();

    for (final CyNetwork net : netArray) {
      // Add its root-network to the lookup map first
      final CyRootNetwork rootNet = rootNetworkManager.getRootNetwork(net);

      if (!networkLookup.containsKey(rootNet.getSUID())) ;
      networkLookup.put(rootNet.getSUID(), rootNet);

      networkLookup.put(net.getSUID(), net);
      networks.add(net); // Note: do NOT add the root-network to this set!
    }
  }
  /** Executes Task. */
  public void run(TaskMonitor taskMonitor) throws Exception {
    taskMonitor.setTitle("Loading Network");
    taskMonitor.setProgress(0);
    taskMonitor.setStatusMessage("Reading in Network Data...");

    try {
      CyNetworkReaderManager readerManager = factory.getCyNetworkViewReaderManager();
      CyNetworkReader reader = readerManager.getReader(url.toURI(), url.getFile());

      if (reader == null) {
        JOptionPane.showMessageDialog(
            factory.getCySwingApplication().getJFrame(),
            "Unable to connect to URL " + url,
            "URL Connect Error",
            JOptionPane.ERROR_MESSAGE);
        return;
      }
      taskMonitor.setStatusMessage("Creating Cytoscape Network...");
      reader.run(taskMonitor);
      CyNetwork[] networks = reader.getNetworks();
      CyNetwork cyNetwork = networks[0];

      // TODO: Does CPath2 listen for this?
      //			Object[] ret_val = new Object[2];
      //			ret_val[0] = cyNetwork;
      //			ret_val[1] = url.toString();
      //
      //			Cytoscape.firePropertyChange(Cytoscape.NETWORK_LOADED, null, ret_val);

      if (cyNetwork != null) {
        informUserOfGraphStats(cyNetwork, taskMonitor);
      } else {
        StringBuffer sb = new StringBuffer();
        sb.append("Could not read network from: ");
        sb.append(url);
        sb.append("\nThis file may not be a valid file format.");
        throw new IOException(sb.toString());
      }
      taskMonitor.setProgress(1.0);
    } catch (Exception e) {
      throw new Exception("Unable to load network.", e);
    }
  }
  private void extractNetworkView(InputStream is, String entryName) throws Exception {
    // Get the token which identifies the network
    Matcher matcher = NETWORK_VIEW_PATTERN.matcher(entryName);
    Long oldNetId = null;

    if (matcher.matches()) {
      String netViewToken = matcher.group(2);
      matcher = NETWORK_VIEW_NAME_PATTERN.matcher(netViewToken);

      if (matcher.matches()) {
        try {
          oldNetId = Long.valueOf(matcher.group(1));
        } catch (NumberFormatException nfe) {
          logger.error("Cannot extract network view SUID from: " + netViewToken);
        }
      }
    }

    if (oldNetId != null) {
      final CyNetwork network = cache.getNetwork(oldNetId);

      if (network != null && !cancelled) {
        // Create the view
        final CyNetworkReader reader = networkReaderMgr.getReader(is, entryName);
        reader.run(taskMonitor);

        final CyNetworkView view = reader.buildCyNetworkView(network);
        networkViews.add(view);

        // Get its visual style name
        if (reader instanceof SessionXGMMLNetworkViewReader) {
          final String vsName = ((SessionXGMMLNetworkViewReader) reader).getVisualStyleName();

          if (vsName != null && !vsName.isEmpty()) this.visualStyleMap.put(view, vsName);
        }
      }
    } else {
      logger.error(
          "The network view will cannot be recreated. The network view entry is invalid: "
              + entryName);
    }
  }
  /*
   * (non-Javadoc)
   *
   * @see cytoscape.util.SwingWorker#construct()
   */
  @Override
  public Object construct() {
    progress = 0;
    for (final File inputFile : inputFiles) {

      // Make a new network in cytoscape from a filename in
      // the network-directory
      CyNetwork network = null;
      try {
        write(Messages.SM_LOADING + inputFile.getName() + " ... ");
        if (!inputFile.isFile()) {
          throw new RuntimeException();
        }
        CyNetworkReader reader =
            cyNetworkViewReaderMgr.getReader(inputFile.toURI(), inputFile.getName());
        try {
          // TODO Use the Task's task monitor
          reader.run(new SampleTaskMonitor());
        } catch (Exception ex) {
          return null;
        }
        network = reader.getNetworks()[0];
        network.getRow(network).set(CyNetwork.NAME, inputFile.getName());
      } catch (RuntimeException e) {
        writeLine(Messages.SM_READERROR);
        reports.add(new NetworkAnalysisReport(inputFile, null, AnalysisError.NETWORK_NOT_OPENED));
        progress += PROGRESS_PER_NET;
        continue;
      }

      // Get all possible interpretations for the network
      NetworkInspection inspection = null;
      try {
        inspection = CyNetworkUtils.inspectNetwork(network);
      } catch (IllegalArgumentException e) {
        writeLine(Messages.SM_DONE);
        reports.add(new NetworkAnalysisReport(inputFile, null, AnalysisError.NETWORK_EMPTY));
        unloadNetwork(inputFile, network);
        continue;
      } catch (NullPointerException e) {
        reports.add(new NetworkAnalysisReport(inputFile, null, AnalysisError.NETWORK_FILE_INVALID));
        progress += PROGRESS_PER_NET;
        continue;
      }

      final NetworkInterpretation[] interprs =
          filterInterpretations(getInterpretations(inspection));
      final int intCount = interprs.length;
      final int advance = PROGRESS_PER_NET / intCount;

      // Run NetworkAnalyzer on all accepted interpretations
      writeLine(Messages.SM_DONE);
      for (int j = 0; j < intCount; progress += advance, ++j) {
        if (cancelled) {
          writeLine(Messages.SM_ANALYSISC);
          return null;
        }

        // Run the analysis for an interpretation
        final NetworkInterpretation interpretation = interprs[j];
        try {
          if (interpretation.isDirected()) {
            analyzer = new DirNetworkAnalyzer(network, null, interpretation);
          } else {
            analyzer = new UndirNetworkAnalyzer(network, null, interpretation);
          }
          writeLine(
              Messages.DI_ANALYZINGINTERP1 + (j + 1) + Messages.DI_ANALYZINGINTERP2 + intCount);
          final int maxProgress = analyzer.getMaxProgress();
          scale = (double) advance / (double) maxProgress;
          analyzing = true;
          subProgress = 0;
          analyzer.computeAll();
          analyzing = false;
          if (cancelled) {
            writeLine(Messages.SM_ANALYSISC);
            return null;
          }
          final NetworkStats stats = analyzer.getStats();
          synchronized (this) {
            analyzer = null;
          }

          final String networkName = network.getRow(network).get("name", String.class);
          stats.setTitle(networkName + interpretation.getInterpretSuffix());
          final String extendedName = networkName + createID(interpretation);
          try {
            if (SettingsSerializer.getPluginSettings().getUseNodeAttributes()) {
              if (!saveNodeAttributes(
                  network, interpretation.isDirected(), outputDir, extendedName)) {
                writeLine(Messages.SM_ATTRIBUTESNOTSAVED);
              }
            }
            File netstatFile = new File(outputDir, extendedName + ".netstats");
            StatsSerializer.save(stats, netstatFile);
            writeLine(Messages.SM_RESULTSSAVED);
            reports.add(new NetworkAnalysisReport(inputFile, interpretation, netstatFile));
          } catch (SecurityException ex) {
            writeError(Messages.SM_SAVEERROR);
            reports.add(
                new NetworkAnalysisReport(
                    inputFile, interpretation, AnalysisError.OUTPUT_NOT_CREATED));
          } catch (FileNotFoundException ex) {
            writeError(Messages.SM_SAVEERROR);
            reports.add(
                new NetworkAnalysisReport(
                    inputFile, interpretation, AnalysisError.OUTPUT_NOT_CREATED));
          } catch (IOException e) {
            writeError(Messages.SM_SAVEERROR);
            reports.add(
                new NetworkAnalysisReport(
                    inputFile, interpretation, AnalysisError.OUTPUT_IO_ERROR));
          }

          if (cancelled) {
            writeLine(Messages.SM_ANALYSISC);
            return null;
          }
        } catch (Exception e) {
          reports.add(
              new NetworkAnalysisReport(inputFile, interpretation, AnalysisError.INTERNAL_ERROR));
        }
      }

      unloadNetwork(inputFile, network);
    }
    return null;
  }