Java tutorial
/* * Copyright 2017. ThoughtWorks, Inc. * * 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 cd.go.notification.gitter.utils; import cd.go.notification.gitter.executors.GetViewRequestExecutor; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import java.io.IOException; import java.io.InputStream; import java.io.StringReader; import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Properties; public class Util { public static String readResource(String resourceFile) { try (InputStream reader = GetViewRequestExecutor.class.getResourceAsStream(resourceFile)) { return IOUtils.toString(reader, StandardCharsets.UTF_8); } catch (IOException e) { throw new RuntimeException("Could not find resource " + resourceFile, e); } } public static String pluginId() { String s = readResource("/plugin.properties"); try { Properties properties = new Properties(); properties.load(new StringReader(s)); return (String) properties.get("pluginId"); } catch (IOException e) { throw new RuntimeException(e); } } public static List<String> listFromCommaSeparatedString(String str) { if (StringUtils.isBlank(str)) { return Collections.emptyList(); } return Arrays.asList(str.split("\\s*,\\s*")); } }