/** * Throws {@link NullPointerException} if the parameter <code>o</code> is * <code>null</code>. * * @param o * check if the object is <code>null</code>. * @param param * name of the parameter to check for <code>null</code>. * @throws NullPointerException * if <code>o</code> is <code>null</code> and constructs a * message with the name of the parameter. */ public static void nullCheck(Object o, String param) { assert StringUtil.isNotBlank(param); if (o == null) { throw new NullPointerException(String.format(NULL_FORMAT, param)); } }
/** * Throws {@link NullPointerException} if the parameter <code>o</code> is * <code>null</code>. * * @param o * check if the object is <code>null</code>. * @param param * name of the parameter to check for <code>null</code>. * @throws NullPointerException * if <code>o</code> is <code>null</code> and constructs a * message with the name of the parameter. */ public static void nullCheck(final Object o, final String param) { assert StringUtil.isNotBlank(param); if (o == null) { throw new NullPointerException(String.format(NULL_FORMAT, param)); } }
/** * Throws {@link NullPointerException} if the parameter <code>o</code> is * <code>null</code>. * * @param o * check if the object is <code>null</code>. * @param param * name of the parameter to check for <code>null</code>. * @throws NullPointerException * if <code>o</code> is <code>null</code> and constructs a * message with the name of the parameter. */ public static void nullCheck(final Object o, final String param) { assert StringUtil.isNotBlank(param); if (o == null) { throw new NullPointerException(String.format(NULL_FORMAT, param)); } }
/** * Read the entire stream into a String and return it. * * @param clazz * @param res * @return */ public static String getResourceAsString(final Class<?> clazz, final String res) { assert clazz != null && StringUtil.isNotBlank(res); return getResourceAsString(clazz, res, Charset.forName("UTF-8")); }
/** * Read the entire stream into a String and return it. * * @param clazz * @param res * @return */ public static String getResourceAsString(final Class<?> clazz, final String res) { assert clazz != null && StringUtil.isNotBlank(res); return getResourceAsString(clazz, res, Charset.forName("UTF-8")); }
/** * Read the entire stream into a String and return it. */ public static String getResourceAsString(Class<?> clazz, String res) { assert clazz != null && StringUtil.isNotBlank(res); return getResourceAsString(clazz, res, Charset.forName("UTF-8")); }
private static void addFactories(URL configFile, List<String> result) throws IOException { try (InputStream input = configFile.openStream(); // Encoding as per JAR file spec. BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))) { String line = reader.readLine(); while (line != null) { int comment = line.indexOf('#'); if (comment >= 0) { line = line.substring(0, comment); } line = line.trim(); if (StringUtil.isNotBlank(line)) { result.add(line); } line = reader.readLine(); } } }
private static void addFactories(URL configFile, List<String> result) throws IOException { try (InputStream input = configFile.openStream(); // Encoding as per JAR file spec. BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))) { String line = reader.readLine(); while (line != null) { int comment = line.indexOf('#'); if (comment >= 0) { line = line.substring(0, comment); } line = line.trim(); if (StringUtil.isNotBlank(line)) { result.add(line); } line = reader.readLine(); } } }
/** * Throws {@link IllegalArgumentException} if the parameter <code>o</code> * is <code>null</code> or blank. * * @param o * value to test for blank. * @param param * name of the parameter to check. */ public static void blankCheck(final String o, final String param) { assert StringUtil.isNotBlank(param); if (StringUtil.isBlank(o)) { throw new IllegalArgumentException(String.format(BLANK_FORMAT, param)); } }
/** * Throws {@link IllegalArgumentException} if the parameter <code>o</code> * is <code>null</code> or blank. * * @param o * value to test for blank. * @param param * name of the parameter to check. */ public static void blankCheck(String o, String param) { assert StringUtil.isNotBlank(param); if (StringUtil.isBlank(o)) { throw new IllegalArgumentException(String.format(BLANK_FORMAT, param)); } }
/** * Throws {@link IllegalArgumentException} if the parameter <code>o</code> * is <code>null</code> or blank. * * @param o * value to test for blank. * @param param * name of the parameter to check. */ public static void blankCheck(final String o, final String param) { assert StringUtil.isNotBlank(param); if (StringUtil.isBlank(o)) { throw new IllegalArgumentException(String.format(BLANK_FORMAT, param)); } }
/** * Returns an input stream of the resource specified. * * @return Returns an InputStream to the resource. */ public static InputStream getResourceAsStream(Class<?> clazz, String res) { assert clazz != null && StringUtil.isNotBlank(res); InputStream ret = null; ClassLoader classLoader = clazz.getClassLoader(); String name[] = { res, getResourcePath(clazz, res), "/" + getResourcePath(clazz, res) }; for (int i = 0; ret == null && i < name.length; i++) { ret = classLoader.getResourceAsStream(name[i]); } return ret; }
/** * Returns an input stream of the resource specified. * * @param clazz * @param res * @return Returns an InputStream to the resource. */ public static InputStream getResourceAsStream(final Class<?> clazz, final String res) { assert clazz != null && StringUtil.isNotBlank(res); InputStream ret = null; final ClassLoader classLoader = clazz.getClassLoader(); final String name[] = { res, getResourcePath(clazz, res), "/" + getResourcePath(clazz, res) }; for (int i = 0; ret == null && i < name.length; i++) { ret = classLoader.getResourceAsStream(name[i]); } return ret; }
/** * Returns an input stream of the resource specified. * * @param clazz * @param res * @return Returns an InputStream to the resource. */ public static InputStream getResourceAsStream(final Class<?> clazz, final String res) { assert clazz != null && StringUtil.isNotBlank(res); InputStream ret = null; final ClassLoader classLoader = clazz.getClassLoader(); final String name[] = { res, getResourcePath(clazz, res), "/" + getResourcePath(clazz, res) }; for (int i = 0; ret == null && i < name.length; i++) { ret = classLoader.getResourceAsStream(name[i]); } return ret; }
private void initSnapshot() { // get snapshot output file, if provided String pOut = System.getProperty(PARAM_PROPERTY_OUT_FILE); if (StringUtil.isNotBlank(pOut)) { try { _propertyOutFile = new File(pOut); if (!_propertyOutFile.exists()) { _propertyOutFile.createNewFile(); } if (!_propertyOutFile.canWrite()) { _propertyOutFile = null; LOG.warn("Unable to write to ''{0}'' file, the test parameters will not be stored", pOut); } else { LOG.info("Storing parameter values to ''{0}'', you can rerun the test with the same parameters later", pOut); } } catch (IOException iOException) { LOG.warn("Unable to create ''{0}'' file, the test parameters will not be stored", pOut); } } }
private void initSnapshot() { // get snapshot output file, if provided String pOut = System.getProperty(PARAM_PROPERTY_OUT_FILE); if (StringUtil.isNotBlank(pOut)) { try { _propertyOutFile = new File(pOut); if (!_propertyOutFile.exists()) { _propertyOutFile.createNewFile(); } if (!_propertyOutFile.canWrite()) { _propertyOutFile = null; LOG.warn("Unable to write to ''{0}'' file, the test parameters will not be stored", pOut); } else { LOG.info("Storing parameter values to ''{0}'', you can rerun the test with the same parameters later", pOut); } } catch (IOException iOException) { LOG.warn("Unable to create ''{0}'' file, the test parameters will not be stored", pOut); } } }
/** * Get the resource as a byte array. */ public static byte[] getResourceAsBytes(Class<?> clazz, String res) { assert clazz != null && StringUtil.isNotBlank(res); // copy bytes from the stream to an array.. InputStream ins = getResourceAsStream(clazz, res); if (ins == null) { throw new IllegalStateException("Resource not found: " + res); } byte[] ret = inputStreamToBytes(ins); quietClose(ins); return ret; }
/** * Get the resource as a byte array. * * @param clazz * @param res * @return */ public static byte[] getResourceAsBytes(final Class<?> clazz, final String res) { assert clazz != null && StringUtil.isNotBlank(res); // copy bytes from the stream to an array.. final InputStream ins = getResourceAsStream(clazz, res); if (ins == null) { throw new IllegalStateException("Resource not found: " + res); } final byte[] ret = inputStreamToBytes(ins); quietClose(ins); return ret; }
/** * Read the entire stream into a String and return it. */ public static String getResourceAsString(Class<?> clazz, String res, Charset charset) { assert clazz != null && StringUtil.isNotBlank(res); String ret = null; InputStream ins = getResourceAsStream(clazz, res); if (ins != null) { try { InputStreamReader rdr = new InputStreamReader(ins, charset); ret = readerToString(rdr); } finally { quietClose(ins); } } return ret; }
@Test public void testIsNotBlank() { assertFalse(StringUtil.isNotBlank(null)); assertFalse(StringUtil.isNotBlank("")); assertFalse(StringUtil.isNotBlank(" ")); assertTrue(StringUtil.isNotBlank("bob")); assertTrue(StringUtil.isNotBlank(" bob ")); }