Proper reply on XDAEMON GROUPADD if group already existing (#551).
3 * see AUTHORS for the list of contributors
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package org.sonews.util.io;
21 import java.io.BufferedReader;
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.io.InputStreamReader;
26 import java.nio.charset.Charset;
29 * Provides method for loading of resources.
30 * @author Christian Lins
33 public final class Resource
37 * Loads a resource and returns it as URL reference.
38 * The Resource's classloader is used to load the resource, not
39 * the System's ClassLoader so it may be safe to use this method
40 * in a sandboxed environment.
43 public static URL getAsURL(final String name)
50 return Resource.class.getClassLoader().getResource(name);
54 * Loads a resource and returns an InputStream to it.
58 public static InputStream getAsStream(String name)
62 URL url = getAsURL(name);
69 return url.openStream();
80 * Loads a plain text resource.
81 * @param withNewline If false all newlines are removed from the
84 public static String getAsString(String name, boolean withNewline)
89 BufferedReader in = null;
92 InputStream ins = getAsStream(name);
96 in = new BufferedReader(
97 new InputStreamReader(ins, Charset.forName("UTF-8")));
98 StringBuffer buf = new StringBuffer();
102 String line = in.readLine();
111 return buf.toString();
125 catch(IOException ex)
127 ex.printStackTrace();