All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fr.faylixe.googlecodejam.client.common.Resources Maven / Gradle / Ivy

There is a newer version: 1.4.11
Show newest version
package fr.faylixe.googlecodejam.client.common;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 

Static toolbox that exposes methods for internal resources managment.

* * @author fv */ public final class Resources { /** Normalization pattern used for creating project and file name. **/ private static final String PATTERN = "[^A-Za-z0-9]"; /** Bundle relative path of the HTML template file. **/ private static final String HTML_TEMPLATE_PATH = "problem.template.html"; /** * Private constructor for avoiding instantiation. */ private Resources() { // Do nothing. } /** * Normalizes the given name by removing * all non alphanumeric character. * * @param name Name to normalize. * @return Normalized name. */ public static String normalize(final String name) { return name.replaceAll(PATTERN, ""); } /** * Reads and returns resources content denoted by the * given path. * * @param path Paht of the resources to read. * @return Resource content as {@link String}. */ public static String getResource(final String path) { final InputStream stream = getResourceStream(path); final BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); final Stream lines = reader.lines(); return lines.collect(Collectors.joining("\n")); } /** * Reads and returns resources content denoted by the * given path. * * @param path Path of the resources to read. * @return Resource content as {@link InputStream}. */ public static InputStream getResourceStream(final String path) { final ClassLoader loader = Resources.class.getClassLoader(); return loader.getResourceAsStream(path); } /** * Getter for the HTML template content. * * @return HTML page template. * @throws IOException If any error occurs while reading template content. */ public static String getHTMLTemplate() throws IOException { return getResource(HTML_TEMPLATE_PATH); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy