return removeEnd(str,separator);
/** * <p>Repeat a String {@code repeat} times to form a * new String, with a String separator injected each time. </p> * * <pre> * StringUtils.repeat(null, null, 2) = null * StringUtils.repeat(null, "x", 2) = null * StringUtils.repeat("", null, 0) = "" * StringUtils.repeat("", "", 2) = "" * StringUtils.repeat("", "x", 3) = "xxx" * StringUtils.repeat("?", ", ", 3) = "?, ?, ?" * </pre> * * @param str the String to repeat, may be null * @param separator the String to inject, may be null * @param repeat number of times to repeat str, negative treated as zero * @return a new String consisting of the original String repeated, * {@code null} if null String input * @since 2.5 */ public static String repeat(final String str, final String separator, final int repeat) { if(str == null || separator == null) { return repeat(str, repeat); } // given that repeat(String, int) is quite optimized, better to rely on it than try and splice this into it final String result = repeat(str + separator, repeat); return removeEnd(result, separator); }
private String processedPattern() { if (this.processedPattern == null) { String[] parts = FilenameUtils.separatorsToUnix(pattern).split("/"); StringBuilder sb = new StringBuilder(); for (String part : parts) { part = escape(part); if ("**".equals(part)) { sb.append(part.replace("**", "([^/]*/)*")); } else if (part.contains("*")) { sb.append(part.replace("*", "[^/]*")); sb.append("/"); } else { sb.append(part); sb.append("/"); } } this.processedPattern = StringUtils.removeEnd(sb.toString(), "/"); } return this.processedPattern; }
String nsKey(String... nsValues) { String rootNamespace = config.getProperty("workflow.namespace.prefix", null); StringBuilder namespacedKey = new StringBuilder(); if (StringUtils.isNotBlank(rootNamespace)) { namespacedKey.append(rootNamespace).append(NAMESPACE_SEP); } String stack = config.getStack(); if (StringUtils.isNotBlank(stack)) { namespacedKey.append(stack).append(NAMESPACE_SEP); } if (StringUtils.isNotBlank(domain)) { namespacedKey.append(domain).append(NAMESPACE_SEP); } for (int i = 0; i < nsValues.length; i++) { namespacedKey.append(nsValues[i]).append(NAMESPACE_SEP); } return StringUtils.removeEnd(namespacedKey.toString(), NAMESPACE_SEP); }
/*** * Extract token value from source entity, where token value is represented by a token in the source entity. * * Eg. * Source Entity : prod_tableName_avro * Source Template: prod_$LOGICAL_TABLE_avro * Token : $LOGICAL_TABLE * Extracted Value: tableName * * @param sourceEntity Source entity (typically a table or database name). * @param sourceTemplate Source template representing the source entity. * @param token Token representing the value to extract from the source entity using the template. * @return Extracted token value from the source entity. */ @VisibleForTesting protected static String extractTokenValueFromEntity(String sourceEntity, String sourceTemplate, String token) { Preconditions.checkArgument(StringUtils.isNotBlank(sourceEntity), "Source entity should not be blank"); Preconditions.checkArgument(StringUtils.isNotBlank(sourceTemplate), "Source template should not be blank"); Preconditions.checkArgument(sourceTemplate.contains(token), String.format("Source template: %s should contain token: %s", sourceTemplate, token)); String extractedValue = sourceEntity; List<String> preAndPostFix = Lists.newArrayList(Splitter.on(token).trimResults().split(sourceTemplate)); extractedValue = StringUtils.removeStart(extractedValue, preAndPostFix.get(0)); extractedValue = StringUtils.removeEnd(extractedValue, preAndPostFix.get(1)); return extractedValue; }
public static String getNodeName(String filePath, GenerationConfig config) { try { String fileName = FilenameUtils.getName(URLDecoder.decode(filePath, "UTF-8")); String[] extensions = config.getFileExtensions() == null ? new String[] {} : config.getFileExtensions(); boolean extensionRemoved = false; for (int i = 0; i < extensions.length; i++) { String extension = extensions[i]; if (extension.length() == 0) { continue; } if (!extension.startsWith(".")) { extension = "." + extension; } if (fileName.endsWith(extension)) { fileName = removeEnd(fileName, extension); extensionRemoved = true; break; } } if (!extensionRemoved) { fileName = FilenameUtils.getBaseName(fileName); } return fileName; } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException(String.format("Unable to generate node name from URL: %s", filePath), e); } }
public static String readQueryFromFile(String directory, String filename) throws IOException { InputStream is = ConversionHiveTestUtils.class.getClassLoader() .getResourceAsStream(StringUtils.removeEnd(directory, Path.SEPARATOR) + Path.SEPARATOR + filename); return IOUtils.toString(is, "UTF-8"); }
public static Schema readSchemaFromJsonFile(String directory, String filename) throws IOException { return new Schema.Parser() .parse(ConversionHiveTestUtils.class.getClassLoader() .getResourceAsStream(StringUtils.removeEnd(directory, Path.SEPARATOR) + Path.SEPARATOR + filename)); }
@Test public void testRemoveEnd() { // StringUtils.removeEnd("", *) = "" assertNull(StringUtils.removeEnd(null, null)); assertNull(StringUtils.removeEnd(null, "")); assertNull(StringUtils.removeEnd(null, "a")); // StringUtils.removeEnd(*, null) = * assertEquals(StringUtils.removeEnd("", null), ""); assertEquals(StringUtils.removeEnd("", ""), ""); assertEquals(StringUtils.removeEnd("", "a"), ""); // All others: assertEquals(StringUtils.removeEnd("www.domain.com.", ".com"), "www.domain.com."); assertEquals(StringUtils.removeEnd("www.domain.com", ".com"), "www.domain"); assertEquals(StringUtils.removeEnd("www.domain", ".com"), "www.domain"); assertEquals(StringUtils.removeEnd("domain.com", ""), "domain.com"); assertEquals(StringUtils.removeEnd("domain.com", null), "domain.com"); }
final String logString = StringUtils.removeEnd(builder.toString(), SystemUtils.LINE_SEPARATOR); stream.println(logString); return logString;
/** * Returns the given file system path minus its last element * * @param fileIdentifier * @return * @since 1.2.0 */ public static String backOneDirectory(String fileIdentifier) { fileIdentifier = StringUtils.removeEnd(fileIdentifier, File.separator); fileIdentifier = fileIdentifier.substring(0, fileIdentifier.lastIndexOf(File.separator)); return StringUtils.removeEnd(fileIdentifier, File.separator); }
private String convertToFullyQualifiedPackageName(final Pom module, final String text) { final String normalisedText = StringUtils.removeEnd(text, ".").toLowerCase(); if (normalisedText.startsWith(TOP_LEVEL_PACKAGE_SYMBOL)) { return replaceTopLevelPackageSymbol(module, normalisedText); } return normalisedText; }
/** * Copies a given app archive with a given target name to the apps folder for deployment * * @throws URISyntaxException */ private void addAppArchive(URL url, String targetFile) throws IOException, URISyntaxException { // copy is not atomic, copy to a temp file and rename instead (rename is atomic) final String tempFileName = (targetFile == null ? new File(url.toURI()) : new File(targetFile)).getPath() + ".part"; final File tempFile = new File(appsDir, tempFileName); copyURLToFile(url, tempFile); boolean renamed = tempFile.renameTo(new File(removeEnd(tempFile.getAbsolutePath(), ".part"))); if (!renamed) { throw new IllegalStateException("Unable to add application archive"); } }
/** * * @param clazz Controller class * @param resourceName resource Name * @param resourceKey key containing the controller package, class controller class name, and controller-level @RequestMapping#value * @param description description of the contrroller */ public SpringResource(Class<?> clazz, String resourceName, String resourceKey, String description) { this.controllerClass = clazz; this.resourceName = resourceName; this.resourceKey = resourceKey; this.description = description; methods = new ArrayList<Method>(); String[] controllerRequestMappingValues = SpringUtils.getControllerResquestMapping(controllerClass); this.controllerMapping = StringUtils.removeEnd(controllerRequestMappingValues[0], "/"); }
private String getParentPath(final JavaType javaType) { final String relativePath = javaType.getRelativeFileName(); for (final String typePath : discoverTypes()) { if (typePath.endsWith(relativePath)) { return StringUtils.removeEnd(typePath, relativePath); } } return null; }
private String resolveRelativePath(String relativeTo, final String relativePath) { relativeTo = StringUtils.removeEnd(relativeTo, File.separator); while (new File(relativeTo).isFile()) { relativeTo = relativeTo.substring(0, relativeTo.lastIndexOf(File.separator));
public Pom getModuleForFileIdentifier(final String fileIdentifier) { updatePomCache(); String startingPoint = FileUtils.getFirstDirectory(fileIdentifier); String pomPath = FileUtils.ensureTrailingSeparator(startingPoint) + DEFAULT_POM_NAME; File pom = new File(pomPath); while (!pom.exists()) { if (startingPoint.equals(SEPARATOR)) { break; } startingPoint = StringUtils.removeEnd(startingPoint, SEPARATOR); if (startingPoint.lastIndexOf(SEPARATOR) < 0) { break; } startingPoint = startingPoint.substring(0, startingPoint.lastIndexOf(SEPARATOR)); startingPoint = StringUtils.removeEnd(startingPoint, SEPARATOR); pomPath = FileUtils.ensureTrailingSeparator(startingPoint) + DEFAULT_POM_NAME; pom = new File(pomPath); } return getPomFromPath(pomPath); }
@Override public List<String> getApplicationProfiles(String moduleName) { List<String> profiles = new ArrayList<String>(); final String applicationConfigFilename = StringUtils.removeEnd(getSpringConfigLocation(moduleName), DEFAULT_APPLICATION_CONFIG_FILE_EXTENSION); // Find application config files for (final FileDetails applicationConfig : fileManager .findMatchingAntPath(applicationConfigFilename + "*" + DEFAULT_APPLICATION_CONFIG_FILE_EXTENSION)) { final String applicationConfigPath = applicationConfig.getCanonicalPath(); if (!fileManager.exists(applicationConfigPath)) { continue; } // Extract profile String profile = StringUtils.substringBetween(applicationConfigPath, applicationConfigFilename, ".properties"); profiles.add(StringUtils.removeStart(profile, "-")); } return profiles; }
protected void addArchive(File outputDir, URI uri, String targetFile) throws Exception { ReentrantLock lock = deploymentService.getLock(); lock.lock(); try { // copy is not atomic, copy to a temp file and rename instead (rename is atomic) final String tempFileName = (targetFile == null ? new File(uri) : new File(targetFile)).getName() + ".part"; final File tempFile = new File(outputDir, tempFileName); copyFile(new File(uri), tempFile); final File destFile = new File(removeEnd(tempFile.getAbsolutePath(), ".part")); File deployFolder = new File(destFile.getAbsolutePath().replace(JAR_FILE_SUFFIX, "")); if (deployFolder.exists()) { // Delete META-INF folder so maven file do not get duplicated during redeployment testing. deleteDirectory(new File(deployFolder, Paths.get("META-INF", "maven").toString())); } tempFile.renameTo(destFile); assertThat("File does not exists: " + destFile.getAbsolutePath(), destFile.exists(), is(true)); } finally { lock.unlock(); } }