
// ----------------------------------------------------------------------
// This code is developed as part of the Java CoG Kit project
// The terms of the license can be found at http://www.cogkit.org/license
// This message may not be removed or altered.
// ----------------------------------------------------------------------

    
package org.globus.cog.util;

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

/**
 *  Loads a text file from a resource or file loadFromResource() tries to
 *  portably load from both if one fails
 */
public class TextFileLoader {

	/**
	 * Loads text from a file
	 * @param fileName the file name to be loaded
	 * @return a String with the contents of the file
	 * @throws IOException
	 */
	public String loadFromFile(String fileName) throws IOException {
		return loadFromStream(new FileInputStream(fileName));
	}

	/**
	 * Reads text from an input stream
	 * @param is the input stream to read the text from
	 * @return a String with the loaded text
	 * @throws IOException
	 */
	public String loadFromStream(InputStream is) throws IOException {
		String Text = "";

		BufferedReader bis = new BufferedReader(new InputStreamReader(is));
		String line = "";

		while (line != null) {
			line = bis.readLine();
			if (line != null) {
				Text = Text + line + "\n";
			}
		}
		is.close();
		return Text;
	}

	/**
	 * Reads text from a resource
	 * @param resName the name of the resource
	 * @return a String with the loaded text
	 */
	public String loadFromResource(String resName) {
		//return loadFromStream(ResName.getClass().getResourceAsStream(ResName));

		URL FileURL = getClass().getClassLoader().getResource(resName);
		try {
			if (FileURL != null) {
				return loadFromStream(FileURL.openStream());
			}
			else {
				return loadFromFile(resName);
			}
		}
		catch (IOException e) {
			return "-- Resource not found --";
		}
	}
	
	public boolean exists(String resName) {
		URL FileURL = getClass().getClassLoader().getResource(resName);
		if (FileURL != null) {
			return true;
		}
		if (new File(resName).exists()) {
			return true;
		}
		return false;
	}
}

@@ -329,11 +329,8 @@
 ---%0A
-%0A  
   %0Ap
@@ -867,32 +867,39 @@
 on%0A%09 */%0A%09public 
+static 
 String loadFromF
@@ -996,24 +996,298 @@
 Name));%0A%09%7D%0A%0A
+%09/**%0A%09 * Loads text from a file%0A%09 * @param file the file to be loaded%0A%09 * @return a String with the contents of the file%0A%09 * @throws IOException%0A%09 */%0A%09public static String loadFromFile(File file) throws IOException %7B%0A%09%09return loadFromStream(new FileInputStream(file));%0A%09%7D%0A%09%0A
 %09/**%0A%09 * Rea
@@ -1439,32 +1439,39 @@
 on%0A%09 */%0A%09public 
+static 
 String loadFromS
@@ -1907,16 +1907,23 @@
 %09public 
+static 
 String l
@@ -2032,16 +2032,18 @@
 Name));%0A
+%09%09
 %0A%09%09URL F
@@ -2047,34 +2047,44 @@
 L FileURL = 
-getC
+TextFileLoader.c
 lass
-()
 .getClassLoa
@@ -2333,16 +2333,23 @@
 %09public 
+static 
 boolean 
@@ -2389,26 +2389,36 @@
 leURL = 
-getC
+TextFileLoader.c
 lass
-()
 .getClas

Make these methods static