/*
 * Copyright 2014 Christophe Pollet
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.cpollet.jixture.utils;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * @author Christophe Pollet
 */
public class InputStreamUtils {
	private static final String CLASSPATH_MARKER = "classpath:";

	public static InputStream getInputStream(String filePath) {
		if (filePath.startsWith(CLASSPATH_MARKER)) {
			return openFileFromClasspath(filePath);
		}

		return openFileFromPath(filePath);
	}

	private static InputStream openFileFromPath(String filePath) {
		try {
			return new FileInputStream(filePath);
		}
		catch (FileNotFoundException e) {
			throw ExceptionUtils.wrapInRuntimeException(e);
		}
	}

	private static InputStream openFileFromClasspath(String classpath) {
		InputStream fileInputStream = InputStreamUtils.class.getClassLoader().getResourceAsStream(removeClasspathMarker(classpath));

		if (null == fileInputStream) {
			throw new RuntimeException("Unable to load file " + classpath);
		}

		return fileInputStream;
	}

	private static String removeClasspathMarker(String classpath) {
		return classpath.replaceFirst(CLASSPATH_MARKER, "");
	}


}

@@ -1341,16 +1341,102 @@
 path) %7B%0A
+%09%09String path = removeClasspathMarker(classpath);%0A%09%09path = removeLeadingSlash(path);%0A%0A
 %09%09InputS
@@ -1523,40 +1523,12 @@
 eam(
-removeClasspathMarker(classpath)
+path
 );%0A%0A
@@ -1658,24 +1658,164 @@
 Stream;%0A%09%7D%0A%0A
+%09private static String removeLeadingSlash(String path) %7B%0A%09%09if (path.startsWith(%22/%22)) %7B%0A%09%09%09return path.substring(1);%0A%09%09%7D%0A%0A%09%09return path;%0A%09%7D%0A%0A
 %09private sta

Allow leading "/" in "classpath:" paths