下面列出了org.apache.commons.lang3.StringUtils#remove ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void deleteFile(String storePath) {
String accessKey = options.getValue(oss_key);
String secretKey = options.getValue(oss_secret);
String domain = options.getValue(oss_domain);
String bucket = options.getValue(oss_bucket);
if (StringUtils.isAnyBlank(accessKey, secretKey, domain, bucket)) {
throw new MtonsException("请先在后台设置阿里云配置信息");
}
String path = StringUtils.remove(storePath, domain.trim());
Zone z = Zone.autoZone();
Configuration configuration = new Configuration(z);
Auth auth = Auth.create(accessKey, secretKey);
BucketManager bucketManager = new BucketManager(auth, configuration);
try {
bucketManager.delete(bucket, path);
} catch (QiniuException e) {
Response r = e.response;
log.error(e.getMessage(), r.toString());
}
}
Integer extractArrayPosition(final String pathElement) {
if (StringUtils.isBlank(pathElement)) {
return null;
}
final String s1 = StringUtils.remove(pathElement, "[");
final String s2 = StringUtils.remove(s1, "]");
final int result = NumberUtils.toInt(s2, -1);
return (result != -1) ? result : null;
}
public static String getOuputFilenameSuggestion(AudioBookInfo bookInfo) {
String filenameFormat = AppProperties.getProperty("filename_format");
if (filenameFormat == null) {
filenameFormat = "<WRITER> <if(SERIES)>- [<SERIES><if(BOOK_NUMBER)> -<BOOK_NUMBER><endif>] <endif>- <TITLE><if(NARRATOR)> (<NARRATOR>)<endif>";
AppProperties.setProperty("filename_format", filenameFormat);
}
ST filenameTemplate = new ST(filenameFormat);
filenameTemplate.add("WRITER", bookInfo.writer().trimToNull());
filenameTemplate.add("TITLE", bookInfo.title().trimToNull());
filenameTemplate.add("SERIES", bookInfo.series().trimToNull());
filenameTemplate.add("NARRATOR", bookInfo.narrator().trimToNull());
filenameTemplate.add("BOOK_NUMBER", bookInfo.bookNumber().zeroToNull());
String result = filenameTemplate.render();
char[] toRemove = new char[]{':', '\\', '/', '>', '<', '|', '?', '*', '"'};
for (char c : toRemove) {
result = StringUtils.remove(result, c);
}
String mp3Filename;
if (StringUtils.isBlank(result)) {
mp3Filename = "NewBook";
} else {
mp3Filename = result;
}
return mp3Filename;
// return mp3Filename.replaceFirst("\\.\\w*$", ".m4b");
}
public static String removeNewlinesFromString(String inputString) {
if ((inputString == null) || inputString.isEmpty()) {
return inputString;
}
String cleanedString = StringUtils.remove(inputString, '\r');
cleanedString = StringUtils.remove(cleanedString, '\n');
return cleanedString;
}
private void unlockFile(File fileToUnlock) {
if (!StringUtils.endsWith(fileToUnlock.getAbsolutePath(), "_LOCK")) {
LOG.info("File to unlock is already unlocked.");
}
File unlockedFile = new File(StringUtils.remove(fileToUnlock.getAbsolutePath(), "_LOCK"));
boolean successfullyUnlocked = fileToUnlock.renameTo(unlockedFile);
if (!successfullyUnlocked) {
LOG.error("Problem with unlocking file.");
} else {
LOG.info("File successfully unlocked.");
}
}
public static void unlockLockedFilesOnQueue() {
PropertyHandler propertyHandler = PropertyHandler.getInstance();
if (propertyHandler.hasProperty("MESSAGE_QUEUE_FOLDER")) {
String messageQueueFolderPath = propertyHandler.getProperty("MESSAGE_QUEUE_FOLDER");
File messageQueueFolder = new File(messageQueueFolderPath);
if (messageQueueFolder.exists()) {
String lockedFileSuffix = "_LOCK";
SuffixFileFilter suffixFileFilter = new SuffixFileFilter(lockedFileSuffix);
Integer numberOfMinutes = propertyHandler.getIntegerProperty("locked.file.retention", "2");
AgeFileFilter ageFileFilter = new AgeFileFilter(System.currentTimeMillis() - (long)(numberOfMinutes.intValue() * 60 * 1000));
Collection<File> lockedFiles = FileUtils.listFiles(messageQueueFolder, FileFilterUtils.and(suffixFileFilter, ageFileFilter), TrueFileFilter.INSTANCE);
Iterator var9 = lockedFiles.iterator();
while(var9.hasNext()) {
File file = (File)var9.next();
String lockedFileName = file.getAbsolutePath();
File unlockedFile = new File(StringUtils.remove(lockedFileName, lockedFileSuffix));
file.setLastModified((new Date()).getTime());
Boolean succesFullyUnlocked = file.renameTo(unlockedFile);
if (succesFullyUnlocked.booleanValue()) {
LOG.info("File: " + lockedFileName + " successfully unlocked.");
}
}
} else {
LOG.info("No directory found on location: " + messageQueueFolderPath + ". No files unlocked");
}
} else {
LOG.info("No MESSAGE_QUEUE_FOLDER property in properties file. No files unlocked.");
}
}
public static void unlockLockedFilesOnQueue() {
final PropertyHandler propertyHandler = PropertyHandler.getInstance();
if (propertyHandler.hasProperty("MESSAGE_QUEUE_FOLDER")) {
String messageQueueFolderPath = propertyHandler.getProperty("MESSAGE_QUEUE_FOLDER");
File messageQueueFolder = new File(messageQueueFolderPath);
if (messageQueueFolder.exists()) {
String lockedFileSuffix = "_LOCK";
SuffixFileFilter suffixFileFilter = new SuffixFileFilter(lockedFileSuffix);
Integer numberOfMinutes = propertyHandler.getIntegerProperty("locked.file.retention", "2");
AgeFileFilter ageFileFilter = new AgeFileFilter(System.currentTimeMillis() - (numberOfMinutes * 60 * 1000));
Collection<File> lockedFiles = FileUtils.listFiles(messageQueueFolder, FileFilterUtils.and(suffixFileFilter, ageFileFilter), TrueFileFilter.INSTANCE);
for (File file : lockedFiles) {
String lockedFileName = file.getAbsolutePath();
File unlockedFile = new File(StringUtils.remove(lockedFileName, lockedFileSuffix));
file.setLastModified(new Date().getTime());
Boolean succesFullyUnlocked = file.renameTo(unlockedFile);
if (succesFullyUnlocked) {
LOG.info("File: " + lockedFileName + " successfully unlocked.");
}
}
} else {
LOG.info("No directory found on location: " + messageQueueFolderPath + ". No files unlocked");
}
} else {
LOG.info("No MESSAGE_QUEUE_FOLDER property in properties file. No files unlocked.");
}
}
private String escapeEntities (String input) {
String output = formattedText.escapeHtml(input);
// Avoid Javacript injection as commandLink params
output = StringUtils.remove(output, ";");
output = StringUtils.remove(output, "'");
return output;
}
@Override
public By buildBy() {
By by = super.buildBy();
String param = by.toString();
// replace by using localization pattern
Matcher matcher = L10N_PATTERN.matcher(param);
while (matcher.find()) {
int start = param.indexOf(SpecialKeywords.L10N + ":") + 5;
int end = param.indexOf("}");
String key = param.substring(start, end);
param = StringUtils.replace(param, matcher.group(), L10N.getText(key));
}
if (getField().isAnnotationPresent(Predicate.class)) {
// TODO: analyze howto determine iOS or Android predicate
param = StringUtils.remove(param, "By.xpath: ");
by = MobileBy.iOSNsPredicateString(param);
// by = MobileBy.AndroidUIAutomator(param);
} else if (getField().isAnnotationPresent(ClassChain.class)) {
param = StringUtils.remove(param, "By.xpath: ");
by = MobileBy.iOSClassChain(param);
} else if (getField().isAnnotationPresent(AccessibilityId.class)) {
param = StringUtils.remove(param, "By.name: ");
by = MobileBy.AccessibilityId(param);
} else if (getField().isAnnotationPresent(ExtendedFindBy.class)) {
if (param.startsWith("By.AndroidUIAutomator: ")) {
param = StringUtils.remove(param, "By.AndroidUIAutomator: ");
by = MobileBy.AndroidUIAutomator(param);
}
LOGGER.debug("Annotation ExtendedFindBy has been detected. Returning locator : " + by);
} else {
by = createBy(param);
}
return by;
}
private String getInputDirStructurePath(Swagger2MarkupConverter converter) {
/*
* When the Swagger input is a local folder (e.g. /Users/foo/) you'll want to group the generated output in the
* configured output directory. The most obvious approach is to replicate the folder structure from the input
* folder to the output folder. Example:
* - swaggerInput is set to /Users/foo
* - there's a single Swagger file at /Users/foo/bar-service/v1/bar.yaml
* - outputDir is set to /tmp/asciidoc
* -> markdown files from bar.yaml are generated to /tmp/asciidoc/bar-service/v1
*/
String swaggerFilePath = new File(converter.getContext().getSwaggerLocation()).getAbsolutePath(); // /Users/foo/bar-service/v1/bar.yaml
String swaggerFileFolder = StringUtils.substringBeforeLast(swaggerFilePath, File.separator); // /Users/foo/bar-service/v1
return StringUtils.remove(swaggerFileFolder, getSwaggerInputAbsolutePath()); // /bar-service/v1
}
public static String getRelativePath(String pathPrefix, String path) {
String remove = StringUtils.remove(path, pathPrefix + File.separator);
log.info("remove={}, index={}", remove, remove.lastIndexOf(java.io.File.separator));
String relativePath = StringUtils.substring(remove, 0, remove.lastIndexOf(java.io.File.separator));
return relativePath;
}
/**
* Removes all periods from a token's text
* @param t the token
* @return the new token with periods removed
*/
private Token transform(Token t) {
String s = StringUtils.remove(t.getText(), '.');
return new Token.Builder(t)
.text(s)
.build();
}
@Async
public void createTransmission(DownloadList download) {
String link = download.getUri();
String path = download.getDownloadPath();
long currentId = download.getId();
try {
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
URIBuilder builder = new URIBuilder(link);
HttpGet httpGet = new HttpGet(builder.build());
CloseableHttpResponse response = httpClient.execute(httpGet);
Header[] header = response.getHeaders("Content-Disposition");
String content = header[0].getValue();
for(String str: StringUtils.split(content, ";")) {
if(StringUtils.containsIgnoreCase(str, "filename=")) {
log.debug(str);
String[] attachment = StringUtils.split(str, "=");
File directory = new File(path);
if(!directory.isDirectory()) {
FileUtils.forceMkdir(directory);
}
String filename = StringUtils.remove(attachment[1], "\"");
HttpVo vo = new HttpVo();
vo.setId(currentId);
vo.setName(download.getName());
vo.setFilename(filename);
vo.setPath(download.getDownloadPath());
jobs.put(currentId, vo);
download.setFileName(filename);
download.setDbid("http_" + vo.getId());
downloadListRepository.save(download);
BufferedInputStream bis = new BufferedInputStream(response.getEntity().getContent());
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(path, filename)));
int inByte;
while((inByte = bis.read()) != -1) bos.write(inByte);
bis.close();
bos.close();
vo.setDone(true);
vo.setPercentDone(100);
jobs.put(currentId, vo);
downloadListRepository.save(download);
// if(StringUtils.equalsIgnoreCase(FilenameUtils.getExtension(attachment[1]), "torrent")) {
if(StringUtils.containsIgnoreCase(filename, ".torrent")) {
long ret = transmissionService.torrentAdd(path + File.separator + filename, path);
if(ret > 0L) {
download.setId(ret);
downloadListRepository.save(download);
simpMessagingTemplate.convertAndSend("/topic/feed/download", download);
}
}
}
}
response.close();
httpClient.close();
} catch (Exception e) {
log.error(e.getMessage());
}
}
private String cleanCharacters(final String value) {
return StringUtils.remove(value, Character.MIN_VALUE); // unicode null character
}
@Override
public String nextId() {
return StringUtils.remove(UUID.randomUUID().toString(), '-');
}
public String getId() {
String id = packageName + name;
return StringUtils.remove(id, '.');
}
private String toNonRelativePath(String resourceName) {
return StringUtils.remove(StringUtils.remove(resourceName, "../"), "./");
}
@Test
public void remove_char_from_string_apache_commons() {
String parsedTelephoneNumber = StringUtils.remove("920-867-5309", '-');
assertEquals("9208675309", parsedTelephoneNumber);
}
private String extractObjectField(final String objectField) {
if (StringUtils.startsWith(objectField, ".")) {
return StringUtils.remove(objectField, ".");
} else if (StringUtils.startsWith(objectField, "[")) {
final String objectFieldP1 = StringUtils.remove(objectField, "['");
return StringUtils.remove(objectFieldP1, "']");
}
return null;
}
String sanitiseArgName(String argName) {
argName = StringUtils.remove(argName, "'");
return StringUtils.remove(argName, "\"");
}