/** * Convert a {@link Path} to a {@link String} and make sure it is properly formatted to be recognized as a file * by {@link TarArchiveEntry}. */ private static String formatPathToFile(Path path) { return StringUtils.removeEnd(path.toString(), Path.SEPARATOR); }
private static String removeEscape(String str) { String result = StringUtils.removeEnd(str, "`"); result = StringUtils.removeStart(result, "`"); return result; }
/** * <p>Repeat a String <code>repeat</code> 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</code> if null String input * @since 2.5 */ public static String repeat(String str, String separator, int repeat) { if(str == null || separator == null) { return repeat(str, repeat); } else { // given that repeat(String, int) is quite optimized, better to rely on it than try and splice this into it String result = repeat(str + separator, repeat); return removeEnd(result, separator); } }
public String getServerBaseURL() { return config.get(SERVER_BASE_URL) .map(t -> StringUtils.removeEnd(t, "/")) .orElse(SERVER_BASE_URL_DEFAULT_VALUE); }
/** * Returns true if specified value matches this pattern. */ public boolean match(String value) { value = StringUtils.removeStart(value, "/"); value = StringUtils.removeEnd(value, "/"); return pattern.matcher(value).matches(); }
@Override public String getURL() { return StringUtils.removeEnd(client.baseUrl(), "/"); }
public String getBaseUrl() { String url = config.get(SERVER_BASE_URL).orElse(""); if (isEmpty(url)) { url = computeBaseUrl(); } // Remove trailing slashes return StringUtils.removeEnd(url, "/"); }
private Path simplifyOutputPath() { Path simplifiedPath = new Path(StringUtils.removeEnd(this.outputPath.toString(), this.jobProps().getProp(MRCompactor.COMPACTION_JOB_DEST_PARTITION, StringUtils.EMPTY))); simplifiedPath = new Path(StringUtils.removeEnd(simplifiedPath.toString(), this.jobProps().getProp(MRCompactor.COMPACTION_DEST_SUBDIR, MRCompactor.DEFAULT_COMPACTION_DEST_SUBDIR))); return simplifiedPath; }
@Override public String getPublicRootUrl() { String baseUrl = trimToEmpty(settings.get(CoreProperties.SERVER_BASE_URL).orElse("")); if (baseUrl.isEmpty()) { // If server base URL was not configured in Sonar server then is is better to take URL configured on batch side baseUrl = client.baseUrl(); } return StringUtils.removeEnd(baseUrl, "/"); }
protected String findAttributeValueGroup(String pattern, int groupNumber, CharSequence cs) { Matcher m = TextUtils.getMatcher(pattern, cs); try { if(m.find()) { String value = m.group(groupNumber); /* * In a case like this <input name="foo"/> the group here will * be "foo"/ ... it's difficult to adjust the regex to avoid * slurping that trailing slash, so handle it here */ value = StringUtils.removeEnd(value, "'/"); value = StringUtils.removeEnd(value, "\"/"); value = StringUtils.strip(value, "\'\""); // strip quotes if present return value; } else { return null; } } finally { TextUtils.recycleMatcher(m); } } }
/** * Retrieves all the children of the given {@link ConfigKeyPath} using {@link Files#walk} to list files */ @Override public Collection<ConfigKeyPath> getChildren(ConfigKeyPath configKey, String version) throws VersionDoesNotExistException { Preconditions.checkNotNull(configKey, "configKey cannot be null!"); Preconditions.checkArgument(version.equals(getCurrentVersion())); List<ConfigKeyPath> children = new ArrayList<>(); Path datasetDir = getDatasetDirForKey(configKey); try { if (!Files.exists(this.fs.getPath(datasetDir.toString()))) { return children; } Stream<Path> files = Files.walk(datasetDir, 1); for (Iterator<Path> it = files.iterator(); it.hasNext();) { Path path = it.next(); if (Files.isDirectory(path) && !path.equals(datasetDir)) { children.add(configKey.createChild(StringUtils.removeEnd(path.getName(path.getNameCount() - 1).toString(), SingleLinkedListConfigKeyPath.PATH_DELIMETER))); } } return children; } catch (IOException e) { throw new RuntimeException(String.format("Error while getting children for configKey: \"%s\"", configKey), e); } }
private void parseTimeAndDatasetName (FileSystemDataset dataset, CompactionParserResult rst) { String commonBase = rst.getSrcBaseDir(); String fullPath = dataset.datasetURN(); int startPos = fullPath.indexOf(commonBase) + commonBase.length(); String relative = StringUtils.removeStart(fullPath.substring(startPos), "/"); int delimiterStart = StringUtils.indexOf(relative, rst.getSrcSubDir()); if (delimiterStart == -1) { throw new StringIndexOutOfBoundsException(); } int delimiterEnd = relative.indexOf("/", delimiterStart); String datasetName = StringUtils.removeEnd(relative.substring(0, delimiterStart), "/"); String timeString = StringUtils.removeEnd(relative.substring(delimiterEnd + 1), "/"); rst.datasetName = datasetName; rst.timeString = timeString; rst.time = getTime (timeString); }
/*** * Download a S3 object to local directory * * @param s3ObjectSummary S3 object summary for the object to download * @param targetDirectory Local target directory to download the object to * @throws IOException If any errors were encountered in downloading the object */ public void downloadS3Object(S3ObjectSummary s3ObjectSummary, String targetDirectory) throws IOException { final AmazonS3 amazonS3 = getS3Client(); final GetObjectRequest getObjectRequest = new GetObjectRequest( s3ObjectSummary.getBucketName(), s3ObjectSummary.getKey()); final S3Object s3Object = amazonS3.getObject(getObjectRequest); final String targetFile = StringUtils.removeEnd(targetDirectory, File.separator) + File.separator + s3Object.getKey(); FileUtils.copyInputStreamToFile(s3Object.getObjectContent(), new File(targetFile)); LOGGER.info("S3 object downloaded to file: " + targetFile); }
private static DdlResult parseTableName(String matchString, String schmeaName) { Perl5Matcher tableMatcher = new Perl5Matcher(); matchString = matchString + " "; if (tableMatcher.matches(matchString, PatternUtils.getPattern(TABLE_PATTERN))) { String tableString = tableMatcher.getMatch().group(3); if (StringUtils.isEmpty(tableString)) { return null; } tableString = StringUtils.removeEnd(tableString, ";"); tableString = StringUtils.removeEnd(tableString, "("); tableString = StringUtils.trim(tableString); // 特殊处理引号` tableString = removeEscape(tableString); // 处理schema.table的写法 String names[] = StringUtils.split(tableString, "."); if (names.length == 0) { return null; } if (names != null && names.length > 1) { return new DdlResult(removeEscape(names[0]), removeEscape(names[1])); } else { return new DdlResult(schmeaName, removeEscape(names[0])); } } return null; }
@Override @SneakyThrows(IOException.class) public void copyFileToContainer(Transferable transferable, String containerPath) { if (!isCreated()) { throw new IllegalStateException("copyFileToContainer can only be used with created / running container"); } try ( ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); TarArchiveOutputStream tarArchive = new TarArchiveOutputStream(byteArrayOutputStream) ) { tarArchive.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX); int lastSlashIndex = StringUtils.removeEnd(containerPath, "/").lastIndexOf("/"); String extractArchiveTo = containerPath.substring(0, lastSlashIndex + 1); String pathInArchive = containerPath.substring(lastSlashIndex + 1); transferable.transferTo(tarArchive, pathInArchive); tarArchive.finish(); dockerClient .copyArchiveToContainerCmd(containerId) .withTarInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())) .withRemotePath(extractArchiveTo) .exec(); } }
(MutableJobCatalog) GobblinConstructorUtils.invokeFirstConstructor(Class.forName(jobCatalogClassName), ImmutableList.of(config .getConfig(StringUtils.removeEnd(GobblinClusterConfigurationKeys.GOBBLIN_CLUSTER_PREFIX, ".")) .withFallback(this.config))); } else {
@Test public void support_base_url_ending_with_slash() throws Exception { assertThat(serverUrl).endsWith("/"); underTest = HttpConnector.newBuilder().url(StringUtils.removeEnd(serverUrl, "/")).build(); GetRequest request = new GetRequest("api/issues/search"); answerHelloWorld(); WsResponse response = underTest.call(request); assertThat(response.hasContent()).isTrue(); }
outputFilename = StringUtils.removeEnd(originalFilename, codec.getDefaultExtension()); } else { outputFilename = originalFilename;
outputFilename = StringUtils.removeEnd(originalFilename, codec.getDefaultExtension()); } else { outputFilename = originalFilename;