List of usage examples for org.apache.commons.lang StringUtils remove
public static String remove(String str, char remove)
Removes all occurrences of a character from within the source string.
From source file:org.red5.io.utils.PropertyConverter.java
/** * Converts a string denoting an amount of bytes into an integer value. * Strings are expected to follow this form where # equals a digit: #M The * following are permitted for denoting binary size: K = kilobytes, M = * megabytes, G = gigabytes/*from w w w . j ava 2 s .co m*/ * * @param memSize memory * @return size as an integer */ public static int convertStringToMemorySizeInt(String memSize) { int result = 0; if (memSize.endsWith("K")) { result = Integer.valueOf(StringUtils.remove(memSize, 'K')) * 1000; } else if (memSize.endsWith("M")) { result = Integer.valueOf(StringUtils.remove(memSize, 'M')) * 1000 * 1000; } else if (memSize.endsWith("G")) { result = Integer.valueOf(StringUtils.remove(memSize, 'G')) * 1000 * 1000 * 1000; } return result; }
From source file:org.red5.io.utils.PropertyConverter.java
/** * Converts a string denoting an amount of bytes into an long value. Strings * are expected to follow this form where # equals a digit: #M The following * are permitted for denoting binary size: K = kilobytes, M = megabytes, G = * gigabytes// ww w. j av a 2 s. c om * * @param memSize memory size * @return size as an long */ public static long convertStringToMemorySizeLong(String memSize) { long result = 0; if (memSize.endsWith("K")) { result = Long.valueOf(StringUtils.remove(memSize, 'K')) * 1000; } else if (memSize.endsWith("M")) { result = Long.valueOf(StringUtils.remove(memSize, 'M')) * 1000 * 1000; } else if (memSize.endsWith("G")) { result = Long.valueOf(StringUtils.remove(memSize, 'G')) * 1000 * 1000 * 1000; } return result; }
From source file:org.sakaiproject.site.tool.SiteAction.java
private String setMoreInfoPath(ServletContext ctx) { String rpath = ctx.getRealPath(""); String ctxPath = ctx.getServletContextName(); String rserve = StringUtils.remove(rpath, ctxPath); return rserve; }
From source file:org.sakuli.services.forwarder.gearman.model.builder.NagiosOutputBuilder.java
/** * Generates the displayed overview data for the nagios server as an {@link String}. * * @param testSuite finshed {@link TestSuite} * @return formatted payload string//from ww w . java 2 s .c o m */ protected String getStatusSummary(TestSuite testSuite, GearmanProperties properties) { StringBuilder sb = new StringBuilder(); sb.append(StringUtils .remove(formatTestSuiteSummaryStateMessage(testSuite, properties.getTemplateSuiteSummary()), "\n")) .append(NagiosOutput.DETAILS_SEPARATOR) .append(String.format(ScreenshotDiv.STYLE_TEMPLATE, getOutputScreenshotDivWidth())) .append(TABLE_HEADER).append(StringUtils.remove( formatTestSuiteTableStateMessage(testSuite, properties.getTemplateSuiteTable()), "\n")); for (TestCase tc : testSuite.getTestCasesAsSortedSet()) { sb.append(formatTestCaseTableStateMessage(tc, properties.lookUpTemplate(tc.getState()))); } sb.append(TABLE_FOOTER); return sb.toString(); }
From source file:org.sakuli.services.forwarder.ScreenshotDivConverter.java
protected String extractScreenshotAsBase64(Throwable exception) { if (exception instanceof SakuliExceptionWithScreenshot) { Path screenshotPath = ((SakuliExceptionWithScreenshot) exception).getScreenshot(); if (screenshotPath != null) { try { byte[] binaryScreenshot = Files.readAllBytes(screenshotPath); String base64String = new BASE64Encoder().encode(binaryScreenshot); for (String newLine : Arrays.asList("\n", "\r")) { base64String = StringUtils.remove(base64String, newLine); }//from w w w . j av a 2 s . com return base64String; } catch (IOException e) { exceptionHandler.handleException(new SakuliForwarderException(e, String.format( "error during the BASE64 encoding of the screenshot '%s'", screenshotPath.toString()))); } } } return null; }
From source file:org.sakuli.services.receiver.gearman.model.builder.OutputBuilder.java
/** * Generates the displayed overview data for the nagios server as an {@link String}. * * @param testSuite finshed {@link TestSuite} * @return formatted payload string/* w w w. j ava2s . com*/ */ protected String getStatusSummary(TestSuite testSuite, GearmanProperties properties) { OutputState outputState = OutputState.lookupSakuliState(testSuite.getState()); StringBuilder sb = new StringBuilder(); sb.append(outputState.name()).append(" - ") .append(StringUtils.remove(formatTestSuiteSummaryStateMessage(testSuite, properties), "\n")) .append(NagiosOutput.DETAILS_SEPARATOR).append(TABLE_HEADER) .append(StringUtils.remove(formatTestSuiteTableStateMessage(testSuite, properties), "\n")); for (TestCase tc : testSuite.getTestCasesAsSortedSet()) { sb.append(formatTestCaseTableStateMessage(tc, properties)); } sb.append(TABLE_FOOTER); return sb.toString(); }
From source file:org.sakuli.services.receiver.gearman.model.builder.ScreenshotDivConverter.java
protected String extractScreenshotAsBase64(Throwable exception) { if (exception instanceof SakuliExceptionWithScreenshot) { Path screenshotPath = ((SakuliExceptionWithScreenshot) exception).getScreenshot(); if (screenshotPath != null) { try { byte[] binaryScreenshot = Files.readAllBytes(screenshotPath); String base64String = new BASE64Encoder().encode(binaryScreenshot); for (String newLine : Arrays.asList("\n", "\r")) { base64String = StringUtils.remove(base64String, newLine); }/*from w w w . jav a2 s. c o m*/ return base64String; } catch (IOException e) { exceptionHandler.handleException(new SakuliReceiverException(e, String.format( "error during the BASE64 encoding of the screenshot '%s'", screenshotPath.toString()))); } } } return null; }
From source file:org.sakuli.starter.helper.SakuliFolderHelper.java
/** * Method remove some not valid windows escape chars like ' or " . To prevent a {@link InvalidPathException}. * <p/>//from w w w .j av a 2 s . c o m * {@code 'C:\PROGRA~1\.' => C:\PROGRA~1\.} * <br/> * {@code "C:\PROGRA~1\." => C:\PROGRA~1\. } * * @param path as {@link String} * @return modified path as {@link String} */ public static Path normalizePath(String path) { String oldPath = path; for (char c : Arrays.asList('\'', '\"')) { path = StringUtils.remove(path, c); } if (!StringUtils.equals(oldPath, path)) { LOGGER.debug("Path [{}] modified to [{}]", oldPath, path); } return path == null ? null : Paths.get(path).toAbsolutePath().normalize(); }
From source file:org.sipfoundry.sipxconfig.admin.monitoring.MRTGConfigTest.java
public void testMRTGConfigToString() { String eol = System.getProperty("line.separator"); List<MRTGTarget> targets = new ArrayList<MRTGTarget>(); targets.add(m_mrtgConfig.getTargets().get(0)); m_mrtgConfig.setTargets(targets);//from w w w . java 2 s . c om String m_mrtgConfigString = StringUtils.remove(m_mrtgConfig.toString(), eol); String outputToCompare = "RunAsDaemon: Yes" + "NoDetach: Yes" + "Interval: 5" + "workdir: /mrtg" + "threshdir: /mrtg/thresh" + "LoadMibs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt, /usr/share/snmp/mibs/TCP-MIB.txt" + "EnableIPv6: no" + "LogFormat: rrdtool" + "PathAdd: /usr/bin" + "## Server CPU Load#target[cpuutil_localhost]: ssCpuRawUser.0&ssCpuRawUser.0:sipxtest@localhosttitle[cpuutil_localhost]: Server CPU Loadpagetop[cpuutil_localhost]: <H1>Server CPU Load</H1>maxbytes[cpuutil_localhost]: 100shortlegend[cpuutil_localhost]: %ylegend[cpuutil_localhost]: CPU Utilizationlegendi[cpuutil_localhost]: Usedlegend1[cpuutil_localhost]: Current CPU percentage loadunscaled[cpuutil_localhost]: ymwdoptions[cpuutil_localhost]: growright,nopercent"; assertEquals(m_mrtgConfigString, outputToCompare); }
From source file:org.sipfoundry.sipxconfig.admin.monitoring.MRTGConfigTest.java
public void testMRTGConfigToStringHeader() { List<MRTGTarget> targets = new ArrayList<MRTGTarget>(); targets.add(new MRTGTarget()); m_mrtgConfig.setTargets(targets);//from w w w .java 2 s . co m String m_mrtgConfigString = StringUtils.remove(m_mrtgConfig.toString(), System.getProperty("line.separator")); String outputToCompare = "RunAsDaemon: Yes" + "NoDetach: Yes" + "Interval: 5" + "workdir: /mrtg" + "threshdir: /mrtg/thresh" + "LoadMibs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt, /usr/share/snmp/mibs/TCP-MIB.txt" + "EnableIPv6: no" + "LogFormat: rrdtool" + "PathAdd: /usr/bin" + "## #maxbytes[]: 10000000000"; assertEquals(m_mrtgConfigString, outputToCompare); }