List of usage examples for java.lang Integer parseUnsignedInt
public static int parseUnsignedInt(String s) throws NumberFormatException
From source file:net.atomique.ksar.xml.PlotStackConfig.java
public void setBase(String s) { if (s == null) { return; } base = Integer.parseUnsignedInt(s); }
From source file:org.fcrepo.sword.integration.ServiceDocumentIT.java
@Test public void specifiesMaxUploadSizeAsInteger() throws IOException { final HttpResponse response = requestServiceDocument(); final Service service = serviceDocumentFromStream(response.getEntity().getContent()); try {/* w ww.ja v a 2 s . c om*/ final int maxUploadSize = Integer.parseUnsignedInt( service.getSimpleExtension("http://purl.org/net/sword/terms/", "maxUploadSize", "sword")); assertEquals("Expected default value for sword:maxUploadSize", Integer.MAX_VALUE, maxUploadSize); } catch (NumberFormatException e) { fail("sword:maxUploadSize is not an Integer"); } }
From source file:com.joyent.manta.client.crypto.EncryptionType.java
/** * Validates that the encryption type and version is compatible with the SDK. * @param encryptionType string of encryption type and version to parse and validate * @throws MantaEncryptionException when encryption type can't be validated *//* ww w.ja v a 2 s . c o m*/ public static void validateEncryptionTypeIsSupported(final String encryptionType) { if (encryptionType == null) { String msg = "Invalid encryption type identifier must not be null"; throw new MantaEncryptionException(msg); } if (StringUtils.isBlank(encryptionType)) { String msg = "Invalid encryption type identifier must not be blank"; MantaEncryptionException e = new MantaEncryptionException(msg); e.setContextValue("malformedEncryptionType", String.format("[%s]", encryptionType)); throw e; } final String[] parts = encryptionType.split(SEPARATOR, 2); if (parts.length != 2) { String msg = "Invalid encryption type identifier specified: missing version separator."; MantaEncryptionException e = new MantaEncryptionException(msg); e.setContextValue("malformedEncryptionType", encryptionType); throw e; } final EncryptionType type = SUPPORTED_ENCRYPTION_TYPES.get(parts[0]); if (type == null) { String msg = "Invalid encryption type identifier specified: Unknown type."; MantaEncryptionException e = new MantaEncryptionException(msg); e.setContextValue("malformedEncryptionType", encryptionType); e.setContextValue("type", parts[0]); throw e; } final int version; try { version = Integer.parseUnsignedInt(parts[1]); } catch (NumberFormatException e) { String msg = "Invalid encryption type version identifier specified."; MantaEncryptionException mcee = new MantaEncryptionException(msg, e); mcee.setContextValue("malformedEncryptionType", encryptionType); mcee.setContextValue("malformedVersionString", parts[1]); throw mcee; } if (version > type.maxVersionSupported) { String msg = "Encryption type version is greater than supported"; MantaEncryptionException e = new MantaEncryptionException(msg); e.setContextValue("encryptionType", encryptionType); e.setContextValue("desiredVersion", version); e.setContextValue("minimumVersionSupported", type.minVersionSupported); e.setContextValue("maximumVersionSupported", type.maxVersionSupported); throw e; } if (version < type.maxVersionSupported) { String msg = "Encryption type version is less than supported"; MantaEncryptionException e = new MantaEncryptionException(msg); e.setContextValue("encryptionType", encryptionType); e.setContextValue("desiredVersion", version); e.setContextValue("minimumVersionSupported", type.minVersionSupported); e.setContextValue("maximumVersionSupported", type.maxVersionSupported); throw e; } }
From source file:org.apache.pulsar.common.net.ServiceURI.java
private static String validateHostName(String serviceName, String[] serviceInfos, String hostname) { String[] parts = hostname.split(":"); if (parts.length >= 3) { throw new IllegalArgumentException("Invalid hostname : " + hostname); } else if (parts.length == 2) { try {/*from w ww.ja va2s . c om*/ Integer.parseUnsignedInt(parts[1]); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("Invalid hostname : " + hostname); } return hostname; } else if (parts.length == 1) { return hostname + ":" + getServicePort(serviceName, serviceInfos); } else { return hostname; } }
From source file:com.ibm.cics.ca1y.JavaHTTP.java
public boolean send() { if (props.getPropertyMime(JAVA_HTTP_CONTENT) == null) { props.setPropertyMime(JAVA_HTTP_CONTENT, JAVA_HTTP_CONTENT_MIME_TEXT_DEFAULT); }// ww w.jav a 2s .co m int retry = JAVA_HTTP_RETRY_DEFAULT; if (props.containsKey(JAVA_HTTP_RETRY)) { try { retry = Integer.parseUnsignedInt(props.getProperty(JAVA_HTTP_RETRY)); } catch (NumberFormatException e) { // Ignore invalid values and use default } } // Prepare HTTP request Client client = ClientBuilder.newClient(); WebTarget target = client.target(props.getProperty(JAVA_HTTP_URI)); // Prepare HTTP filter if (props.getProperty(JAVA_HTTP_FILTER_CLASS) != null) { logger.fine(Emit.messages.getString("HTTPRegisteringFilterClass") + " - " + props.getProperty(JAVA_HTTP_FILTER_CLASS)); try { target.register(Class.forName(props.getProperty(JAVA_HTTP_FILTER_CLASS))); } catch (ClassNotFoundException e) { logger.warning(Emit.messages.getString("HTTPFilterClassNotFound") + " - " + props.getProperty(JAVA_HTTP_FILTER_CLASS)); } } // Add all properties that start with the prefix as HTTP headers to the // HTTP request Builder builder = target.request(props.getPropertyMime(JAVA_HTTP_CONTENT)); Enumeration<?> list = props.propertyNames(); while (list.hasMoreElements()) { String key = (String) list.nextElement(); if (key.startsWith(JAVA_HTTP_HEADER_PREFIX)) { // Set the HTTP header builder.header(key.substring(JAVA_HTTP_HEADER_PREFIX.length()), props.getProperty(key)); } else if (key.startsWith(JAVA_HTTP_FILTER_PREFIX)) { // Set the HTTP request property for use by the HTTP filter builder.property(key, props.getProperty(key)); } } // Prepare the HTTP content in an entity Entity<String> entity = Entity.entity(props.getProperty(JAVA_HTTP_CONTENT), props.getPropertyMime(JAVA_HTTP_CONTENT)); // Send HTTP request long retryDelay; Response response = null; for (; retry >= 0; retry--) { // Send the HTTP request response = builder.method(props.getProperty(JAVA_HTTP_METHOD, JAVA_HTTP_METHOD_DEFAULT), entity); if ((response.getStatus() == Response.Status.OK.getStatusCode()) || (response.getStatus() == Response.Status.CREATED.getStatusCode()) || (response.getStatus() == Response.Status.ACCEPTED.getStatusCode())) { // HTTP request was processed successfully // Get the HTTP response body String responseHttpBody = ""; if (response.getEntity() != null) { try { responseHttpBody = IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8); } catch (IOException e) { e.printStackTrace(); } } // Log the HTTP request was successful if (logger.isLoggable(Level.INFO)) { logger.info(Emit.messages.getString("HTTPLogSuccess") + " - " + getMessageSummary() + ",HTTP response status:" + response.getStatus() + ",HTTP response body:" + responseHttpBody); } return true; } if (retry > 0) { // Delay for the specified period retryDelay = JAVA_HTTP_RETRY_DELAY_DEFAULT; if (props.containsKey(JAVA_HTTP_RETRY_DELAY)) { try { retryDelay = Integer.parseUnsignedInt(props.getProperty(JAVA_HTTP_RETRY_DELAY)); } catch (NumberFormatException e) { // Ignore invalid values and use default } } if (logger.isLoggable(Level.FINE)) { logger.fine(Emit.messages.getString("HTTP_RETRYING") + " " + retryDelay + "ms"); } try { Thread.sleep(retryDelay); } catch (InterruptedException e) { // Thread cancelled so do not retry break; } } } if (logger.isLoggable(Level.INFO)) { logger.info(Emit.messages.getString("HTTPLogFail") + " - " + getMessageSummary() + ",HTTP response status:" + response.getStatus()); } return false; }
From source file:in.flipbrain.controllers.BaseController.java
protected void sendEmail(String to, String subject, String body) throws EmailException { logger.debug("Sending email to " + to + "\nSubject: " + subject + "\nMessage: " + body); if ("true".equalsIgnoreCase(getConfigValue(Constants.EM_FAKE_SEND))) return;//from ww w . j a v a2 s . c o m Email email = new SimpleEmail(); email.setHostName(getConfigValue("smtp.host")); email.setSmtpPort(Integer.parseUnsignedInt(getConfigValue("smtp.port"))); email.setAuthenticator( new DefaultAuthenticator(getConfigValue("smtp.user"), getConfigValue("smtp.password"))); email.setSSLOnConnect(Boolean.parseBoolean(getConfigValue("smtp.ssl"))); email.setFrom(getConfigValue("smtp.sender")); email.setSubject(subject); email.setMsg(body); email.addTo(to); email.send(); }
From source file:com.github.aptd.simulation.CMain.java
private static void execute(final CommandLine p_cli) { final double l_changetimemin = Double.parseDouble(p_cli.getOptionValue("changetimemin", "100")); final double l_changetimemax = Double.parseDouble(p_cli.getOptionValue("changetimemax", "100")); final int l_numberofpassengers = Integer.parseUnsignedInt(p_cli.getOptionValue("numberofpassengers", "20")); final double l_lightbarrierminfreetime = Double .parseDouble(p_cli.getOptionValue("lightbarrierminfreetime", "3.0")); final double l_delayseconds = Double.parseDouble(p_cli.getOptionValue("delayseconds", "0.0")); // load configuration CConfiguration.INSTANCE.loadfile(p_cli.getOptionValue("config", "")); // execute experiments in batch processing and starts http server new Thread(() -> datamodel(p_cli).map(i -> i.getLeft().model().get( EFactory.from(CConfiguration.INSTANCE.getOrDefault("local", "runtime", "type")).factory(), i.getRight(),//from w w w .j ava 2 s. c o m p_cli.hasOption("iteration") ? Long.parseLong(p_cli.getOptionValue("iteration")) : (long) CConfiguration.INSTANCE.getOrDefault(0, "default", "iteration"), !p_cli.hasOption("sequential") && CConfiguration.INSTANCE.<Boolean>getOrDefault(true, "runtime", "parallel"), p_cli.hasOption("timemodel") ? p_cli.getOptionValue("timemodel") : "step", () -> { if (l_changetimemax <= l_changetimemin) return new ConstantRealDistribution(l_changetimemin); final RandomGenerator l_randomgenerator = new JDKRandomGenerator(); l_randomgenerator.setSeed(Long.parseLong(p_cli.getOptionValue("changetimeseed", "1"))); return new UniformRealDistribution(l_randomgenerator, l_changetimemin, l_changetimemax); }, l_numberofpassengers, l_lightbarrierminfreetime, l_delayseconds)) .forEach(i -> ERuntime.LOCAL.get().execute(i))).start(); // start http server if possible if (p_cli.hasOption("interactive")) CHTTPServer.execute(); }
From source file:org.apache.bookkeeper.common.net.ServiceURI.java
private static String validateHostName(String serviceName, String hostname) { String[] parts = hostname.split(":"); if (parts.length >= 3) { throw new IllegalArgumentException("Invalid hostname : " + hostname); } else if (parts.length == 2) { try {//from ww w. j a v a 2 s . c om Integer.parseUnsignedInt(parts[1]); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("Invalid hostname : " + hostname); } return hostname; } else if (parts.length == 1 && serviceName.toLowerCase().equals(SERVICE_BK)) { return hostname + ":" + SERVICE_BK_PORT; } else { return hostname; } }
From source file:org.openhab.binding.gpioremotecontrol.internal.GpioRemoteControlBinding.java
/** * @{inheritDoc}// ww w.j a v a 2 s. c o m */ @Override protected void internalReceiveCommand(String itemName, Command command) { // the code being executed when a command was sent on the openHAB // event bus goes here. This method is only called if one of the // BindingProviders provide a binding for the given 'itemName'. logger.debug("GpioRemoteControl: internalReceiveCommand({},{}) is called!", itemName, command); for (GpioRemoteControlBindingProvider provider : providers) { if (provider.getConfig(itemName).configMode != ConfigMode.OUTPUT) { logger.warn("The Item '{}' wasn't configured as output item. It can't receive any commands!", itemName); return; //If it is not a output Item, stop here } try { int pinNumber = provider.getConfig(itemName).pinConfiguration.getNumber(); PinConfiguration pinConf = null; logger.debug("GpioRemoteControl: internalReceiveCommand: Event Auswahl folgt... " + "ItemName: {}, Command: {}", itemName, command); if (command == OnOffType.ON || command.toString().toLowerCase().equals("on")) { pinConf = new PinConfiguration(Event.SET, pinNumber, true); provider.getConfig(itemName).pinConfiguration.setPwmValue(100); } else if (command == OnOffType.OFF || command.toString().toLowerCase().equals("off")) { pinConf = new PinConfiguration(Event.SET, pinNumber, false); provider.getConfig(itemName).pinConfiguration.setPwmValue(0); } else if (command.toString().toLowerCase().equals("toggle")) { pinConf = handleToggleCommand(provider, itemName, pinNumber, command); } else if (command == IncreaseDecreaseType.INCREASE || command.toString().toLowerCase().equals("increase")) { provider.getConfig(itemName).pinConfiguration .setPwmValue(provider.getConfig(itemName).pinConfiguration.getPwmValue() + 1); pinConf = new PinConfiguration(Event.DIM, pinNumber, provider.getConfig(itemName).pinConfiguration.getPwmValue() + 1); } else if (command == IncreaseDecreaseType.DECREASE || command.toString().toLowerCase().equals("decrease")) { provider.getConfig(itemName).pinConfiguration .setPwmValue(provider.getConfig(itemName).pinConfiguration.getPwmValue() - 1); pinConf = new PinConfiguration(Event.DIM, pinNumber, provider.getConfig(itemName).pinConfiguration.getPwmValue()); } else if (command.toString().toLowerCase().contains("dim_")) { String[] split = command.toString().split("_"); //Should be: 0:dim;1:pwmValue pinConf = new PinConfiguration(Event.DIM, pinNumber, Integer.parseInt(split[1])); provider.getConfig(itemName).pinConfiguration.setPwmValue(Integer.parseInt(split[1])); //Save value of PWM } else if (command.toString().toLowerCase().contains("fade_")) { pinConf = handleEvent(provider, itemName, pinNumber, command, Event.FADE); } else if (command.toString().toLowerCase().contains("fadeupdown_")) { pinConf = handleEvent(provider, itemName, pinNumber, command, Event.FADE_UP_DOWN); } else if (command.toString().toLowerCase().contains("blink_")) { pinConf = handleBlinkEvent(provider, itemName, pinNumber, command); } else { //parseable as Integer? int tempPwmVal = Integer.parseUnsignedInt(command.toString()); provider.getConfig(itemName).pinConfiguration.setPwmValue(tempPwmVal); //pinConfiguration.setPwmValue ensures the value is 0-100 pinConf = new PinConfiguration(Event.DIM, pinNumber, provider.getConfig(itemName).pinConfiguration.getPwmValue()); } URI uriOfPin = new URI("ws://" + provider.getConfig(itemName).getHostWithPort()); provider.getClientMap().get(uriOfPin).send(gson.toJson(pinConf)); //Send Command to Remote GPIO Pin // provider.getClientMap().get(uriOfPin).send(gson.toJson("{\"event\":\"TEMP\",\"deviceId\":\"28-00044a72b1ff\"}")); } catch (IndexOutOfBoundsException e) { logger.warn( "GpioRemoteControl: internalReceiveCommand: EventConfig not readable! Maybe wrong parameter in Sitemap? " + "ItemName: {}, Command: {}", itemName, command); } catch (URISyntaxException e) { e.printStackTrace(); } catch (NumberFormatException e) { } catch (Exception e) { e.printStackTrace(); } } }
From source file:uk.ac.open.crc.jim.Jim.java
private List<String> processThreadSettings(CommandLine cl) throws CommandLineArgumentException { // exit jim if options are given and values are missing or non-digit List<String> optionsSelected = new ArrayList<>(); boolean hasMin = cl.hasOption(MIN_THREADS); boolean hasMax = cl.hasOption(MAX_THREADS); if (hasMin && hasMax) { // now are the values set? String minValueString = cl.getOptionValue(MIN_THREADS); String maxValueString = cl.getOptionValue(MAX_THREADS); if ((minValueString != null && !minValueString.isEmpty()) && (maxValueString != null && !maxValueString.isEmpty())) { // so are values parsable into ints? int minValue = 0; int maxValue = 0; try { minValue = Integer.parseUnsignedInt(minValueString); maxValue = Integer.parseUnsignedInt(maxValueString); } catch (NumberFormatException e) { // no, so throw a wobbly and die throw new CommandLineArgumentException("Require numeric value for number of threads."); }/* w ww . j av a 2 s . c om*/ // yes -- so populate the values in setting and // leave the detection of irrational values to QueueManager this.settings.set("threads.minimum", Integer.toString(minValue)); optionsSelected.add("--" + MIN_THREADS + " " + minValue); this.settings.set("threads.maximum", Integer.toString(maxValue)); optionsSelected.add("--" + MAX_THREADS + " " + maxValue); } else { // tell user a value is missing throw new CommandLineArgumentException( "Missing value for --" + MIN_THREADS + " or --" + MAX_THREADS + "."); } } else if (hasMin || hasMax) { // tell user both are required and bail throw new CommandLineArgumentException("When setting size of thread pool " + "both --" + MIN_THREADS + " and --" + MAX_THREADS + " must be defined."); } return optionsSelected; }