/** * {@link SlaEventKeys} have a prefix of {@link SlaEventKeys#EVENT_GOBBLIN_STATE_PREFIX} to keep properties organized * in state. This method removes the prefix before submitting an Sla event. */ private String withoutPropertiesPrefix(String key) { return StringUtils.removeStart(key, SlaEventKeys.EVENT_GOBBLIN_STATE_PREFIX); }
private JsonNode resolveFromClasspath(URI uri) { String path = removeStart(removeStart(uri.toString(), uri.getScheme() + ":"), "/"); InputStream contentAsStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(path); if (contentAsStream == null) { throw new IllegalArgumentException("Couldn't read content from the classpath, file not found: " + uri); } try { return objectMapper.readTree(contentAsStream); } catch (JsonProcessingException e) { throw new IllegalArgumentException("Error parsing document: " + uri, e); } catch (IOException e) { throw new IllegalArgumentException("Unrecognised URI, can't resolve this: " + uri, e); } }
public static String subtractPath(File rootPath, File file) { String fullPath = FilenameUtils.separatorsToUnix(file.getParentFile().getPath()); String basePath = FilenameUtils.separatorsToUnix(rootPath.getPath()); return StringUtils.removeStart(StringUtils.removeStart(fullPath, basePath), "/"); }
private String removeLeadingSlash(File artifactDest) { return removeStart(FilenameUtils.separatorsToUnix(artifactDest.getPath()), "/"); } }
private String removeLeadingSlash(File artifactDest) { return removeStart(FilenameUtils.separatorsToUnix(artifactDest.getPath()), "/"); }
private Properties computeChecksumForContentsOfDirectory(File directory, String destPath) throws IOException { Collection<File> fileStructure = FileUtils.listFiles(directory, null, true); Properties checksumProperties = new Properties(); for (File file : fileStructure) { String filePath = removeStart(file.getAbsolutePath(), directory.getParentFile().getAbsolutePath()); try (FileInputStream inputStream = new FileInputStream(file)) { checksumProperties.setProperty(getEffectiveFileName(destPath, FilenameUtils.separatorsToUnix(filePath)), md5Hex(inputStream)); } } return checksumProperties; }
private Properties computeChecksumForContentsOfDirectory(File directory, String destPath) throws IOException { Collection<File> fileStructure = FileUtils.listFiles(directory, null, true); Properties checksumProperties = new Properties(); for (File file : fileStructure) { String filePath = removeStart(file.getAbsolutePath(), directory.getParentFile().getAbsolutePath()); try (FileInputStream inputStream = new FileInputStream(file)) { checksumProperties.setProperty(getEffectiveFileName(destPath, FilenameUtils.separatorsToUnix(filePath)), md5Hex(inputStream)); } } return checksumProperties; }
@Override public void onDelete(String key, String value) throws Exception { String domKey = StringUtils.removeStart(key, UtilsAndCommons.DOMAINS_DATA_ID_PRE); String namespace = domKey.split(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)[0]; String name = domKey.split(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)[1]; Domain dom = chooseDomMap(namespace).remove(name); Loggers.RAFT.info("[RAFT-NOTIFIER] datum is deleted, key: {}, value: {}", key, value); if (dom != null) { dom.destroy(); Loggers.SRV_LOG.info("[DEAD-DOM] {}", dom.toJSON()); } } };
/*** * 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; }
private static String stripIndentation(String description) { if (description == null || description.isEmpty()) { return ""; } String stripped = StringUtils.stripStart(description, "\n\r"); stripped = StringUtils.stripEnd(stripped, "\n\r "); int indentation = 0; int strLen = stripped.length(); while (Character.isWhitespace(stripped.charAt(indentation)) && indentation < strLen) { indentation++; } String[] lines = stripped.split("\\n"); String prefix = StringUtils.repeat(' ', indentation); StringBuilder result = new StringBuilder(stripped.length()); if (StringUtils.isNotEmpty(prefix)) { for (int i = 0; i < lines.length; i++) { String line = lines[i]; if (i > 0) { result.append(StringUtils.LF); } result.append(StringUtils.removeStart(line, prefix)); } } else { result.append(stripped); } return result.toString(); }
protected String destURL(File rootPath, File file, String src, String dest) { String trimmedPattern = rtrimStandardrizedWildcardTokens(src); if (StringUtils.equals(FilenameUtils.separatorsToUnix(trimmedPattern), FilenameUtils.separatorsToUnix(src))) { return dest; } String trimmedPath = removeStart(subtractPath(rootPath, file), FilenameUtils.separatorsToUnix(trimmedPattern)); if (!StringUtils.startsWith(trimmedPath, "/") && StringUtils.isNotEmpty(trimmedPath)) { trimmedPath = "/" + trimmedPath; } return dest + trimmedPath; }
protected String destinationURL(File rootPath, File file, String src, String dest) { String trimmedPattern = rtrimStandardrizedWildcardTokens(src); if (StringUtils.equals(FilenameUtils.separatorsToUnix(trimmedPattern), FilenameUtils.separatorsToUnix(src))) { return dest; } String trimmedPath = removeStart(subtractPath(rootPath, file), FilenameUtils.separatorsToUnix(trimmedPattern)); if (!StringUtils.startsWith(trimmedPath, "/") && StringUtils.isNotEmpty(trimmedPath)) { trimmedPath = "/" + trimmedPath; } return dest + trimmedPath; }
for (Entry<Object, Object> entry : props.entrySet()) { if (StringUtils.startsWith(entry.getKey().toString(), SlaEventKeys.EVENT_ADDITIONAL_METADATA_PREFIX)) { this.additionalMetadata.put(StringUtils.removeStart(entry.getKey().toString(), SlaEventKeys.EVENT_ADDITIONAL_METADATA_PREFIX), entry.getValue().toString());
JarEntry entry = em.nextElement(); if (entry.getName().startsWith(jarConnection.getEntryName())) { String fileName = StringUtils.removeStart(entry.getName(), jarConnection.getEntryName()); if (!fileName.equals("/")) { // exclude the directory InputStream entryInputStream = null;
JarEntry entry = em.nextElement(); if (entry.getName().startsWith(jarConnection.getEntryName())) { String fileName = StringUtils.removeStart(entry.getName(), jarConnection.getEntryName()); if (!fileName.equals("/")) { // exclude the directory InputStream entryInputStream = null;
@Test public void testRemoveStart() { // StringUtils.removeStart("", *) = "" assertNull(StringUtils.removeStart(null, null)); assertNull(StringUtils.removeStart(null, "")); assertNull(StringUtils.removeStart(null, "a")); // StringUtils.removeStart(*, null) = * assertEquals(StringUtils.removeStart("", null), ""); assertEquals(StringUtils.removeStart("", ""), ""); assertEquals(StringUtils.removeStart("", "a"), ""); // All others: assertEquals(StringUtils.removeStart("www.domain.com", "www."), "domain.com"); assertEquals(StringUtils.removeStart("domain.com", "www."), "domain.com"); assertEquals(StringUtils.removeStart("domain.com", ""), "domain.com"); assertEquals(StringUtils.removeStart("domain.com", null), "domain.com"); }
if ((ss = StringUtils.removeStart(url, "resource:")) != url) { return baseDirectory.get(ss);
@Before public void setUp() throws Exception { Configuration c = TEST_UTIL.getConfiguration(); c.setBoolean("dfs.support.append", true); TEST_UTIL.startMiniCluster(1); table = TEST_UTIL.createMultiRegionTable(TABLE_NAME, FAMILY); TEST_UTIL.loadTable(table, FAMILY); // setup the hdfssnapshots client = new DFSClient(TEST_UTIL.getDFSCluster().getURI(), TEST_UTIL.getConfiguration()); String fullUrIPath = TEST_UTIL.getDefaultRootDirPath().toString(); String uriString = TEST_UTIL.getTestFileSystem().getUri().toString(); baseDir = StringUtils.removeStart(fullUrIPath, uriString); client.allowSnapshot(baseDir); }
public String decrypt(String str) { if (StringUtils.isNotBlank(str)) { if (StringUtils.startsWith(str, CIPHER_PREFIX)) { str = StringUtils.removeStart(str, CIPHER_PREFIX); } return encryptor.decrypt(str); } else { return str; } }
private String getModuleName(final String pomDirectory) { final String normalisedRootPath = FileUtils.ensureTrailingSeparator(projectRootDirectory); final String normalisedPomDirectory = FileUtils.ensureTrailingSeparator(pomDirectory); final String moduleDirectory = StringUtils.removeStart(normalisedPomDirectory, normalisedRootPath); return FilenameUtils.getBaseName(StringUtils.stripEnd(moduleDirectory, SEPARATOR)); }