/*
  File: ReadUtils.java

  Copyright (c) 2006, The Cytoscape Consortium (www.cytoscape.org)

  The Cytoscape Consortium is:
  - Institute for Systems Biology
  - University of California San Diego
  - Memorial Sloan-Kettering Cancer Center
  - Institut Pasteur
  - Agilent Technologies

  This library is free software; you can redistribute it and/or modify it
  under the terms of the GNU Lesser General Public License as published
  by the Free Software Foundation; either version 2.1 of the License, or
  any later version.

  This library is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
  documentation provided hereunder is on an "as is" basis, and the
  Institute for Systems Biology and the Whitehead Institute
  have no obligations to provide maintenance, support,
  updates, enhancements or modifications.  In no event shall the
  Institute for Systems Biology and the Whitehead Institute
  be liable to any party for direct, indirect, special,
  incidental or consequential damages, including lost profits, arising
  out of the use of this software and its documentation, even if the
  Institute for Systems Biology and the Whitehead Institute
  have been advised of the possibility of such damage.  See
  the GNU Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public License
  along with this library; if not, write to the Free Software Foundation,
  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 */
package org.cytoscape.io.internal.util;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;

import org.cytoscape.io.util.StreamUtil;
import org.cytoscape.work.TaskMonitor;

/**
 */
public class ReadUtils {

	private static final String LINE_SEP = System.getProperty("line.separator");

	private StreamUtil streamUtil;

	public ReadUtils(StreamUtil streamUtil) {
		this.streamUtil = streamUtil;
	}

	/**
	 * A string that defines a simplified java regular expression for a URL.
	 * This may need to be updated to be more precise.
	 */
	public static final String urlPattern = "^(jar\\:)?(\\w+\\:\\/+\\S+)(\\!\\/\\S*)?$";

	/**
	 * DOCUMENT ME!
	 * 
	 * @param name
	 *            DOCUMENT ME!
	 * 
	 * @return DOCUMENT ME!
	 */
	public InputStream getInputStream(String name) {
		return getInputStream(name, null);
	}

	/**
	 * DOCUMENT ME!
	 * 
	 * @param name
	 *            DOCUMENT ME!
	 * @param monitor
	 *            DOCUMENT ME!
	 * 
	 * @return DOCUMENT ME!
	 */
	public InputStream getInputStream(String name, TaskMonitor monitor) {
		InputStream in = null;

		try {
			if (name.matches(urlPattern)) {
				URL u = new URL(name);
				// in = u.openStream();
				// Use URLUtil to get the InputStream since we might be using a
				// proxy server
				// and because pages may be cached:
				in = streamUtil.getInputStream(u);
			} else
				in = new FileInputStream(name);
		} catch (IOException ioe) {
			ioe.printStackTrace();
		}

		return in;
	}

	/**
	 * 
	 * @param filename
	 *            File to read in
	 * 
	 * @return The contents of the given file as a string.
	 */
	public String getInputString(String filename) {
		try {
			InputStream stream = getInputStream(filename);
			return getInputString(stream);
		} catch (IOException ioe) {
			ioe.printStackTrace();
		}

		System.out.println("couldn't create string from '" + filename + "'");

		return null;
	}

	/**
	 * 
	 * @param inputStream
	 *            An InputStream
	 * 
	 * @return The contents of the given file as a string.
	 */
	public String getInputString(InputStream inputStream) throws IOException {

		final StringBuilder sb = new StringBuilder();
		String line;
		final BufferedReader br = new BufferedReader(new InputStreamReader(
				inputStream));

		while ((line = br.readLine()) != null)
			sb.append(line + LINE_SEP);

		br.close();

		return sb.toString();
	}
}

@@ -1839,16 +1839,42 @@
 net.URL;
+%0Aimport java.util.HashMap;
 %0A%0Aimport
@@ -1908,16 +1908,212 @@
 amUtil;%0A
+import org.cytoscape.model.CyNetwork;%0Aimport org.cytoscape.model.CyNetworkManager;%0Aimport org.cytoscape.model.subnetwork.CyRootNetwork;%0Aimport org.cytoscape.model.subnetwork.CyRootNetworkManager;%0A
 import o
@@ -4323,10 +4323,550 @@
 g();%0A%09%7D%0A
+%09%0A%09public static HashMap%3CString, CyRootNetwork%3E getRootNetworkMap(CyNetworkManager cyNetworkManager, CyRootNetworkManager cyRootNetworkManager) %7B%0A%0A%09%09HashMap%3CString, CyRootNetwork%3E name2RootMap = new HashMap%3CString, CyRootNetwork%3E();%0A%0A%09%09for (CyNetwork net : cyNetworkManager.getNetworkSet())%7B%0A%09%09%09final CyRootNetwork rootNet = cyRootNetworkManager.getRootNetwork(net);%0A%09%09%09if (!name2RootMap.containsValue(rootNet ) )%0A%09%09%09%09name2RootMap.put(rootNet.getRow(rootNet).get(CyRootNetwork.NAME, String.class), rootNet);%0A%09%09%7D%0A%0A%09%09return name2RootMap;%0A%09%7D%0A%0A
 %7D%0A

Add a new method