List of usage examples for org.apache.commons.lang3.math NumberUtils toInt
public static int toInt(final String str)
Convert a String
to an int
, returning zero
if the conversion fails.
If the string is null
, zero
is returned.
NumberUtils.toInt(null) = 0 NumberUtils.toInt("") = 0 NumberUtils.toInt("1") = 1
From source file:jease.site.Streams.java
/** * Write given file to response./*w ww. j ava 2 s . co m*/ * * If the given content type denotes a browser supported image, the image * will be automatically scaled if either "scale" is present as request * paramter or JEASE_IMAGE_LIMIT is set in Registry. */ public static void write(HttpServletRequest request, HttpServletResponse response, File file, String contentType) throws IOException { if (Images.isBrowserCompatible(contentType)) { int scale = NumberUtils.toInt(request.getParameter("scale")); if (scale > 0) { java.io.File scaledImage = Images.scale(file, scale); scaledImage.deleteOnExit(); response.setContentType(contentType); response.setContentLength((int) scaledImage.length()); Files.copy(scaledImage.toPath(), response.getOutputStream()); return; } int limit = NumberUtils.toInt(Registry.getParameter(Names.JEASE_IMAGE_LIMIT)); if (limit > 0) { java.io.File scaledImage = Images.limit(file, limit); scaledImage.deleteOnExit(); response.setContentType(contentType); response.setContentLength((int) scaledImage.length()); Files.copy(scaledImage.toPath(), response.getOutputStream()); return; } } response.setContentType(contentType); response.setContentLength((int) file.length()); Files.copy(file.toPath(), response.getOutputStream()); }
From source file:com.yahoo.parsec.filters.ProfilingFormatter.java
@Override public String format(Request req, Response resp, Map<String, Object> additionalArgs) { int requestCount = NumberUtils .toInt(req.getHeaders().getFirstValue(ParsecClientDefine.HEADER_PROFILING_REQUEST_COUNT)); int lastRespCode = NumberUtils .toInt(req.getHeaders().getFirstValue(ParsecClientDefine.HEADER_PROFILING_LAST_RESPONSE_CODE), 0); ParsecAsyncProgress progress = (ParsecAsyncProgress) additionalArgs .get(ParsecClientDefine.PROFILING_ASYNC_PROGRESS); String requestStatus = ParsecClientDefine.REQUEST_SINGLE; if (requestCount > 1) { requestStatus = ParsecClientDefine.REQUEST_SINGLE_RETRY + ":" + lastRespCode; }//from w ww .j a v a 2s . c o m return ParsecClientProfilingLogUtil.formatMessage(req, resp, requestStatus, progress, null); }
From source file:com.mirth.connect.connectors.tcp.TcpSenderService.java
public Object invoke(String channelId, String method, Object object, String sessionsId) throws Exception { if (method.equals("testConnection")) { TcpDispatcherProperties connectorProperties = (TcpDispatcherProperties) object; String host = replacer.replaceValues(connectorProperties.getRemoteAddress(), channelId); int port = NumberUtils.toInt(replacer.replaceValues(connectorProperties.getRemotePort(), channelId)); int timeout = NumberUtils .toInt(replacer.replaceValues(connectorProperties.getResponseTimeout(), channelId)); if (!connectorProperties.isOverrideLocalBinding()) { return ConnectorUtil.testConnection(host, port, timeout); } else {//from w w w.j ava2 s . c o m String localAddr = replacer.replaceValues(connectorProperties.getLocalAddress(), channelId); int localPort = NumberUtils .toInt(replacer.replaceValues(connectorProperties.getLocalPort(), channelId)); return ConnectorUtil.testConnection(host, port, timeout, localAddr, localPort); } } return null; }
From source file:com.autonomy.nonaci.indexing.impl.AbstractExportCommand.java
public int getBatchSize() { return NumberUtils.toInt(get(PARAM_BATCH_SIZE)); }
From source file:com.tacitknowledge.flip.aspectj.converters.IntegerConverter.java
/** {@inheritDoc } */ public Object convert(String expression, Class outputClass) { return NumberUtils.toInt(expression); }
From source file:com.kegare.bedrocklayer.client.config.CycleIntegerEntry.java
public CycleIntegerEntry(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement configElement) {// w w w .j a v a 2s.c om super(owningScreen, owningEntryList, configElement); this.beforeValue = NumberUtils.toInt(configElement.get().toString()); this.defaultValue = NumberUtils.toInt(configElement.getDefault().toString()); this.currentValue = beforeValue; this.btnValue.enabled = enabled(); updateValueButtonText(); }
From source file:com.ctrip.infosec.rule.util.Emitter.java
public static void emit(RiskFact fact, String riskLevelTxt, String riskMessage) { if (!StringUtils.isNumeric(riskLevelTxt)) { throw new IllegalArgumentException("\"riskLevel\""); }/*from w w w .j a va 2 s.c o m*/ int riskLevel = NumberUtils.toInt(riskLevelTxt); emit(fact, riskLevel, riskMessage); }
From source file:com.mirth.connect.connectors.tcp.TcpConnectorServlet.java
@Override public ConnectionTestResponse testConnection(String channelId, String channelName, TcpDispatcherProperties properties) { try {//ww w . ja va2s . c o m String host = replacer.replaceValues(properties.getRemoteAddress(), channelId, channelName); int port = NumberUtils .toInt(replacer.replaceValues(properties.getRemotePort(), channelId, channelName)); int timeout = NumberUtils .toInt(replacer.replaceValues(properties.getResponseTimeout(), channelId, channelName)); if (!properties.isOverrideLocalBinding()) { return ConnectorUtil.testConnection(host, port, timeout); } else { String localAddr = replacer.replaceValues(properties.getLocalAddress(), channelId, channelName); int localPort = NumberUtils .toInt(replacer.replaceValues(properties.getLocalPort(), channelId, channelName)); return ConnectorUtil.testConnection(host, port, timeout, localAddr, localPort); } } catch (Exception e) { throw new MirthApiException(e); } }
From source file:alpine.util.JavaVersion.java
public JavaVersion(String versionString) { if (versionString.startsWith("1.")) { final String[] javaVersionElements = versionString.split("\\.|_|-|-b"); major = NumberUtils.toInt(javaVersionElements[1]); minor = NumberUtils.toInt(javaVersionElements[2]); update = NumberUtils.toInt(javaVersionElements[3]); } else {//from ww w .j a v a2s . c o m final String[] javaVersionElements = versionString.split("\\.|\\+"); major = NumberUtils.toInt(javaVersionElements[0]); minor = NumberUtils.toInt(javaVersionElements[1]); update = NumberUtils.toInt(javaVersionElements[2]); } }
From source file:TestOfStuff.java
@Test public void Test() throws Exception { assertEquals(NumberUtils.toInt("25"), 25); }