/** * Removes starting and ending single or double quotes. */ public static String removeQuotes(String string) { if ( (startsWithChar(string, '\'') && endsWithChar(string, '\'')) || (startsWithChar(string, '"') && endsWithChar(string, '"')) ) { return substring(string, 1, -1); } return string; }
/** * Adds child map to the props on given prefix. */ public void addInnerMap(String prefix, final Map<?, ?> map, final String profile) { if (!StringUtil.endsWithChar(prefix, '.')) { prefix += StringPool.DOT; } for (Map.Entry<?, ?> entry : map.entrySet()) { String key = entry.getKey().toString(); key = prefix + key; setValue(key, entry.getValue().toString(), profile); } }
/** * Removes starting and ending single or double quotes. */ public static String removeQuotes(final String string) { if ( (startsWithChar(string, '\'') && endsWithChar(string, '\'')) || (startsWithChar(string, '"') && endsWithChar(string, '"')) || (startsWithChar(string, '`') && endsWithChar(string, '`')) ) { return substring(string, 1, -1); } return string; }
public static void addFolderToZip(ZipOutputStream zos, String path, String comment) throws IOException { while (path.length() != 0 && path.charAt(0) == '/') { path = path.substring(1); } // add folder record if (!StringUtil.endsWithChar(path, '/')) { path += '/'; } ZipEntry zipEntry = new ZipEntry(path); zipEntry.setTime(System.currentTimeMillis()); if (comment != null) { zipEntry.setComment(comment); } zipEntry.setSize(0); zipEntry.setCrc(0); zos.putNextEntry(zipEntry); zos.closeEntry(); }
/** * Adds byte content into the zip as a file. */ public static void addToZip(ZipOutputStream zos, byte[] content, String path, String comment) throws IOException { while (path.length() != 0 && path.charAt(0) == '/') { path = path.substring(1); } if (StringUtil.endsWithChar(path, '/')) { path = path.substring(0, path.length() - 1); } ZipEntry zipEntry = new ZipEntry(path); zipEntry.setTime(System.currentTimeMillis()); if (comment != null) { zipEntry.setComment(comment); } zos.putNextEntry(zipEntry); InputStream is = new ByteArrayInputStream(content); try { StreamUtil.copy(is, zos); } finally { StreamUtil.close(is); } zos.closeEntry(); }
/** * Creates new address by specifying one of the following: * <ul> * <li>{@code "foo@bar.com" - only email address.}</li> * <li>{@code "Jenny Doe <foo@bar.com>" - first part of the string is personal name, * and the other part is email, surrounded with < and >.}</li> * </ul> * * @param address {@link String} containing address to convert. */ public static EmailAddress of(String address) { address = address.trim(); if (!StringUtil.endsWithChar(address, '>')) { return new EmailAddress(null, address); } final int ndx = address.lastIndexOf('<'); if (ndx == -1) { return new EmailAddress(null, address); } String email = address.substring(ndx + 1, address.length() - 1); String personalName = address.substring(0, ndx).trim(); return new EmailAddress(personalName, email); }
public static void addFolderToZip(final ZipOutputStream zos, String path, final String comment) throws IOException { while (path.length() != 0 && path.charAt(0) == '/') { path = path.substring(1); } // add folder record if (!StringUtil.endsWithChar(path, '/')) { path += '/'; } ZipEntry zipEntry = new ZipEntry(path); zipEntry.setTime(System.currentTimeMillis()); if (comment != null) { zipEntry.setComment(comment); } zipEntry.setSize(0); zipEntry.setCrc(0); zos.putNextEntry(zipEntry); zos.closeEntry(); }
/** * Adds byte content into the zip as a file. */ public static void addToZip(final ZipOutputStream zos, final byte[] content, String path, final String comment) throws IOException { while (path.length() != 0 && path.charAt(0) == '/') { path = path.substring(1); } if (StringUtil.endsWithChar(path, '/')) { path = path.substring(0, path.length() - 1); } ZipEntry zipEntry = new ZipEntry(path); zipEntry.setTime(System.currentTimeMillis()); if (comment != null) { zipEntry.setComment(comment); } zos.putNextEntry(zipEntry); InputStream is = new ByteArrayInputStream(content); try { StreamUtil.copy(is, zos); } finally { StreamUtil.close(is); } zos.closeEntry(); }
if (!StringUtil.endsWithChar(prefix, '.')) { prefix += StringPool.DOT;
if (!StringUtil.endsWithChar(path, '/')) { path += '/';
} else { if (value.length() > 0) { if (StringUtil.endsWithChar(path, '/')) { path += value; } else {
if (!StringUtil.endsWithChar(path, '/')) { path += '/';
@Test void testStartWith() { assertTrue(StringUtil.startsWithChar("asd", 'a')); assertFalse(StringUtil.startsWithChar("asd", 's')); assertFalse(StringUtil.startsWithChar("", 'a')); assertTrue(StringUtil.endsWithChar("asd", 'd')); assertFalse(StringUtil.endsWithChar("asd", 's')); assertFalse(StringUtil.endsWithChar("", 'd')); assertEquals(3, StringUtil.startsWithOne("qwe123", "Qwe", null, ".", "qwe")); assertEquals(-1, StringUtil.startsWithOne("qwe123", "Qwe", null, ".", "we")); assertEquals(0, StringUtil.startsWithOneIgnoreCase("qwe123", "Qwe", null, ".", "qwe")); assertEquals(-1, StringUtil.startsWithOneIgnoreCase("qwe123", "we", null, ".", "we")); assertEquals(3, StringUtil.endsWithOne("qwezxc", "Zxc", null, ".", "zxc")); assertEquals(-1, StringUtil.endsWithOne("qwezxc", "Zxc", null, ".", "zx")); assertEquals(0, StringUtil.endsWithOneIgnoreCase("qweZXC", "Zxc", null, ".", "zxc")); assertEquals(-1, StringUtil.endsWithOneIgnoreCase("qweZXC", "zx", null, ".", "zx")); }
/** * Returns url that can be used for further construction of the full url. */ public static String url(String url) { while (StringUtil.endsWithChar(url, '/')) { url = url.substring(0, url.length() - 1); } return url; }
/** * Adds child map to the props on given prefix. */ public void addInnerMap(String prefix, final Map<?, ?> map, final String profile) { if (!StringUtil.endsWithChar(prefix, '.')) { prefix += StringPool.DOT; } for (Map.Entry<?, ?> entry : map.entrySet()) { String key = entry.getKey().toString(); key = prefix + key; setValue(key, entry.getValue().toString(), profile); } }
/** * Normalizes paths. Returned path will always start with a slash separator. * However, it never ends with a slash, unless it is a root path. * Therefore, the root path is the only one with the size 1. */ public static String normalizePath(String path) { if (path.length() > 1 && StringUtil.endsWithChar(path, '/')) { path = path.substring(0, path.length() - 1); } if (!StringUtil.startsWithChar(path, '/')) { path = StringPool.SLASH + path; } return path; }
@Override public void render(ActionRequest actionRequest, Object resultObject, String resultValue, String resultPath) throws Exception { HttpServletResponse response = actionRequest.getHttpServletResponse(); boolean isError = false; if (StringUtil.endsWithChar(resultValue, '!')) { isError = true; resultValue = resultValue.substring(0, resultValue.length() - 1); } if (isError) { response.sendError(Integer.parseInt(resultValue)); } else { response.setStatus(Integer.parseInt(resultValue)); } } }
/** * Removes starting and ending single or double quotes. */ public static String removeQuotes(final String string) { if ( (startsWithChar(string, '\'') && endsWithChar(string, '\'')) || (startsWithChar(string, '"') && endsWithChar(string, '"')) || (startsWithChar(string, '`') && endsWithChar(string, '`')) ) { return substring(string, 1, -1); } return string; }
/** * Creates new address by specifying one of the following: * <ul> * <li>{@code "foo@bar.com" - only email address.}</li> * <li>{@code "Jenny Doe <foo@bar.com>" - first part of the string is personal name, * and the other part is email, surrounded with < and >.}</li> * </ul> * * @param address {@link String} containing address to convert. */ public static EmailAddress of(String address) { address = address.trim(); if (!StringUtil.endsWithChar(address, '>')) { return new EmailAddress(null, address); } final int ndx = address.lastIndexOf('<'); if (ndx == -1) { return new EmailAddress(null, address); } String email = address.substring(ndx + 1, address.length() - 1); String personalName = address.substring(0, ndx).trim(); return new EmailAddress(personalName, email); }
public static void addFolderToZip(final ZipOutputStream zos, String path, final String comment) throws IOException { while (path.length() != 0 && path.charAt(0) == '/') { path = path.substring(1); } // add folder record if (!StringUtil.endsWithChar(path, '/')) { path += '/'; } ZipEntry zipEntry = new ZipEntry(path); zipEntry.setTime(System.currentTimeMillis()); if (comment != null) { zipEntry.setComment(comment); } zipEntry.setSize(0); zipEntry.setCrc(0); zos.putNextEntry(zipEntry); zos.closeEntry(); }