List of usage examples for org.apache.commons.lang3 StringUtils remove
public static String remove(final String str, final char remove)
Removes all occurrences of a character from within the source string.
A null source string will return null .
From source file:org.dbgl.util.FileUtils.java
private static ShortFile createShortFile(File file, Set<ShortFile> curDir) { String filename = file.getName().toUpperCase(); boolean createShort = false; if (StringUtils.contains(filename, ' ')) { filename = StringUtils.remove(filename, ' '); createShort = true;// ww w . j av a2 s .c o m } int len = 0; int idx = filename.indexOf('.'); if (idx != -1) { if (filename.length() - idx - 1 > 3) { filename = StringUtils.stripStart(filename, "."); createShort = true; } idx = filename.indexOf('.'); len = (idx != -1) ? idx : filename.length(); } else { len = filename.length(); } createShort |= len > 8; ShortFile shortFile = null; if (!createShort) { shortFile = new ShortFile(file, StringUtils.removeEnd(filename, ".")); } else { int i = 1; do { String nr = String.valueOf(i++); StringBuffer sb = new StringBuffer(StringUtils.left(filename, Math.min(8 - nr.length() - 1, len))); sb.append('~').append(nr); idx = filename.lastIndexOf('.'); if (idx != -1) sb.append(StringUtils.left(filename.substring(idx), 4)); shortFile = new ShortFile(file, StringUtils.removeEnd(sb.toString(), ".")); } while (shortFile.isContainedIn(curDir)); } return shortFile; }
From source file:org.diorite.impl.auth.yggdrasil.YggdrasilSessionService.java
private GameProfileImpl getGameProfile0(final UUID uuid) throws AuthenticationException { try {/*w w w. ja v a2s .com*/ final URL url = new URL(PROFILE_URL, StringUtils.remove(uuid.toString(), '-') + "?unsigned=false"); final ProfileResponse response = this.makeRequest(url, null, ProfileResponse.class); if ((response != null) && (response.getId() != null)) { final GameProfileImpl result = new GameProfileImpl(response.getId(), response.getName()); if (response.getProperties() != null) { result.getProperties().putAll(response.getProperties()); } return result; } } catch (final MalformedURLException e) { throw new RuntimeException(e); } return null; }
From source file:org.glukit.dexcom.sync.DecodingUtils.java
/** * Takes a string like 0A 0F 05 and converts it into a byte array. * * @param hexString hex string, can contain spaces * @return the byte array// w ww. ja v a 2s . com */ public static byte[] fromHexString(String hexString) { String hexStringWithoutSpaces = StringUtils.remove(hexString, " "); return DatatypeConverter.parseHexBinary(hexStringWithoutSpaces); }
From source file:org.goko.core.common.measure.quantity.AbstractQuantity.java
protected Q parse(String value, List<Unit<Q>> lstUnit) throws GkException { // Try to extract unit String leftNumericValue = value; Unit<Q> foundUnit = null;//from www. j ava2 s. co m for (Unit<Q> existingUnit : lstUnit) { if (StringUtils.contains(value, existingUnit.getSymbol())) { leftNumericValue = StringUtils.remove(value, existingUnit.getSymbol()).trim(); foundUnit = (Unit<Q>) existingUnit; break; } } if (foundUnit == null) { throw new GkTechnicalException("No unit found in quantity [" + leftNumericValue + "]"); } return createQuantity(new BigDecimal(leftNumericValue), foundUnit); }
From source file:org.gvnix.service.roo.addon.addon.ws.export.WSExportWsdlConfigServiceImpl.java
/** * Copy package info file from generated folder to sources folder. *//*from www .j ava 2s.c o m*/ private void createPackageInfoClass() { // If schema package file exists if (schemaPackage.exists()) { try { // Schema package file absolute path String path = schemaPackage.getAbsolutePath(); // Remove sources dir folder prefix path = StringUtils.remove(path, projectOperations.getPathResolver().getIdentifier( LogicalPath.getInstance(Path.ROOT, ""), WsExportWsdl.GENERATED_CXF_SOURCES_DIR)); // Create file into sources folder at same location fileManager.createOrUpdateTextFileIfRequired( projectOperations.getPathResolver() .getIdentifier(LogicalPath.getInstance(Path.SRC_MAIN_JAVA, ""), path), IOUtils.toString(new InputStreamReader(new FileInputStream(schemaPackage))), true); } catch (FileNotFoundException e) { throw new IllegalStateException("Generated 'package-info.java' file '" + schemaPackage.getAbsolutePath() + "' doesn't exist:\n" + e.getMessage()); } catch (IOException e) { throw new IllegalStateException("Generated 'package-info.java' file '" + schemaPackage.getAbsolutePath() + "' has errors:\n" + e.getMessage()); } } }
From source file:org.ihtsdo.otf.query.implementation.JSONToReport.java
/** * Load both set cardinality reports and reports for the specific * {@link java.util.Set} values.// ww w. ja v a 2s . c o m * * @param jsonLine */ private void loadMap(String jsonLine) { try { JSONObject json = (JSONObject) new JSONParser().parse(jsonLine); for (Object key : json.keySet()) { String value = json.get(key).toString(); if (value.matches("[0-9]+")) { this.resultMap.put(key.toString(), Integer.parseInt(value)); } else if (value.matches("\\[[0-9]+.*\\]")) { Set<Long> longSet = new HashSet<>(); for (String l : value.split(",")) { l = StringUtils.remove(l, '['); l = StringUtils.remove(l, ']'); l = l.trim(); if (l.matches("[0-9]+")) { longSet.add(Long.parseLong(l)); } } this.resultMap.put(key.toString(), longSet); } } } catch (ParseException ex) { Logger.getLogger(JSONToReport.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.jamwiki.migrate.MediaWikiXmlImporter.java
/** * Convert the Wikipedia article namespace (if any) to a JAMWiki article namespace. *//*from w w w. j ava2 s .c o m*/ private String convertArticleNameFromWikipediaToJAMWiki(String fullName) { String ret = fullName; int pos = fullName.indexOf(Namespace.SEPARATOR); if (pos > 0) { String namespace = fullName.substring(0, pos); String title = fullName.substring(pos + 1); String jamwikiNamespace = mediawikiNamespaceMap.get(namespace); if (!StringUtils.isBlank(jamwikiNamespace)) { // matching JAMWiki namespace found ret = jamwikiNamespace + Namespace.SEPARATOR + title; } } // remove any characters that are valid for Mediawiki but not JAMWiki ret = StringUtils.remove(ret, '?'); return ret; }
From source file:org.jamwiki.parser.jflex.ParserTestUtils.java
/** * */ private String sanitize(String value) { return StringUtils.remove(value, '\r').trim(); }
From source file:org.jamwiki.web.utils.DiffUtil.java
/** * Return a list of WikiDiff objects that can be used to create a display of the * diff content./*from w w w . jav a 2s . com*/ * * @param newVersion The String that is to be compared to, ie the later version of a topic. * @param oldVersion The String that is to be considered as having changed, ie the earlier * version of a topic. * @return Returns a list of WikiDiff objects that correspond to the changed text. */ public static List<WikiDiff> diff(String newVersion, String oldVersion) throws DataAccessException { List<WikiDiff> result = DiffUtil.retrieveFromCache(newVersion, oldVersion); if (result != null) { return result; } String version1 = newVersion; String version2 = oldVersion; if (version2 == null) { version2 = ""; } if (version1 == null) { version1 = ""; } // remove line-feeds to avoid unnecessary noise in the diff due to // cut & paste or other issues version2 = StringUtils.remove(version2, '\r'); version1 = StringUtils.remove(version1, '\r'); result = DiffUtil.process(version1, version2); DiffUtil.addToCache(newVersion, oldVersion, result); return result; }
From source file:org.jboss.dashboard.i18n.XmlToBundleConverter.java
public Map<Locale, Properties> read() throws Exception { Map<Locale, Properties> result = new HashMap<Locale, Properties>(); File[] bundles = new DirectoriesScanner("properties").findFiles(bundleDir); for (File f : bundles) { Locale locale = extractLocale(StringUtils.remove(f.getName(), ".properties")); if (locale != null) { Properties bundle = new Properties(); bundle.load(new FileReader(f)); result.put(locale, bundle);/* ww w. j a v a 2 s. c om*/ } } return result; }