List of usage examples for java.lang Short decode
public static Short decode(String nm) throws NumberFormatException
From source file:org.opendaylight.ovsdb.openstack.netvirt.impl.BridgeConfigurationManagerImpl.java
private short getControllerOFPort() { Short defaultOpenFlowPort = 6633; Short openFlowPort = defaultOpenFlowPort; String portString = ConfigProperties.getProperty(this.getClass(), "of.listenPort"); if (portString != null) { try {/*w w w.ja v a 2s. c om*/ openFlowPort = Short.decode(portString).shortValue(); } catch (NumberFormatException e) { LOGGER.warn("Invalid port:{}, use default({})", portString, openFlowPort); } } return openFlowPort; }
From source file:org.opendaylight.controller.sal.core.NodeConnector.java
/** * return a NodeConnector from a string not containing explicitly * the Node portion which has to be supplied as parameter * * @param str String to be parsed in a NodeConnector * @param n Node to which the NodeConnector is attached * * @return the NodeConnector if parse is successful, null otherwise *//* ww w .j a va 2 s.com*/ public static NodeConnector fromStringNoNode(String str, Node n) { if (str == null) { return null; } String nodeConnectorParts[] = str.split("\\|"); if (nodeConnectorParts.length != 2) { // Try to guess from a String formatted as a short because // for long time openflow has been prime citizen so lets // keep this legacy for now String numStr = str.toUpperCase(); Short ofPortID = null; // Try as an decimal/hex number try { ofPortID = Short.decode(numStr); } catch (Exception ex) { ofPortID = null; } // Lets try the special ports we know about if (ofPortID == null) { try { if (str.equalsIgnoreCase(NodeConnectorIDType.CONTROLLER.toString())) { return new NodeConnector(NodeConnectorIDType.CONTROLLER, SPECIALNODECONNECTORID, n); } if (str.equalsIgnoreCase(NodeConnectorIDType.HWPATH.toString())) { return new NodeConnector(NodeConnectorIDType.HWPATH, SPECIALNODECONNECTORID, n); } if (str.equalsIgnoreCase(NodeConnectorIDType.SWSTACK.toString())) { return new NodeConnector(NodeConnectorIDType.SWSTACK, SPECIALNODECONNECTORID, n); } if (str.equalsIgnoreCase(NodeConnectorIDType.ALL.toString())) { return new NodeConnector(NodeConnectorIDType.ALL, SPECIALNODECONNECTORID, n); } } catch (ConstructionException ex) { return null; } return null; } // Lets return the cooked up NodeID try { return new NodeConnector(NodeConnectorIDType.OPENFLOW, ofPortID, n); } catch (ConstructionException ex) { return null; } } String typeStr = nodeConnectorParts[0]; String IDStr = nodeConnectorParts[1]; return fromStringNoNode(typeStr, IDStr, n); }
From source file:org.opendaylight.ovsdb.plugin.impl.ConfigurationServiceImpl.java
private short getControllerOFPort() { Short defaultOpenFlowPort = 6633; Short openFlowPort = defaultOpenFlowPort; String portString = ConfigProperties.getProperty(this.getClass(), "of.listenPort"); if (portString != null) { try {//from w w w .j av a 2 s . co m openFlowPort = Short.decode(portString).shortValue(); } catch (NumberFormatException e) { logger.warn("Invalid port:{}, use default({})", portString, openFlowPort); } } return openFlowPort; }
From source file:org.opendaylight.ovsdb.plugin.ConnectionService.java
private short getControllerOFPort() { Short defaultOpenFlowPort = 6633; Short openFlowPort = defaultOpenFlowPort; String portString = System.getProperty("of.listenPort"); if (portString != null) { try {// w w w . j a v a 2 s .c om openFlowPort = Short.decode(portString).shortValue(); } catch (NumberFormatException e) { logger.warn("Invalid port:{}, use default({})", portString, openFlowPort); } } return openFlowPort; }
From source file:com.bigstep.datalake.DLFileSystem.java
@Override public synchronized void initialize(URI uri, Configuration conf) throws IOException { super.initialize(uri, conf); uri = selectDatalakeEndpointURI(uri, conf); /* set user pattern based on configuration file */ UserParam.setUserPattern(conf.get(DFSConfigKeys.DFS_WEBHDFS_USER_PATTERN_KEY, DFSConfigKeys.DFS_WEBHDFS_USER_PATTERN_DEFAULT)); kerberosIdentity = initialiseKerberosIdentity(conf); this.shouldUseEncryption = conf.getBoolean(FS_DL_IMPL_SHOULD_USE_ENCRYPTION_CONFIG_NAME, false); if (this.shouldUseEncryption) { initialiseAesEncryption(conf);/*from w w w. j av a 2 s . c om*/ } this.homeDirectory = conf.get(FS_DL_IMPL_HOME_DIRECTORY); if (homeDirectory == null) throw new IOException( "The Datalake requires a home directory to be configured in the fs.dl.impl.homeDirectory configuration variable. This is in the form /data_lake/dlxxxx"); this.defaultEndpoint = conf.get(FS_DL_IMPL_DEFAULT_ENDPOINT); if (defaultEndpoint == null) throw new IOException( "The Datalake requires a default endpoint to be configured the fs.dl.impl.defaultEndpoint configuration variable. This is in the form /data_lake/dlxxxx"); URI defaultEndpointURI = URI.create(defaultEndpoint); String authority = uri.getAuthority() == null ? defaultEndpointURI.getAuthority() : uri.getAuthority(); this.baseUri = URI.create(uri.getScheme() + "://" + authority + this.homeDirectory); this.nnAddrs = resolveNNAddr(); LOG.debug("Created kerberosIdentity " + kerberosIdentity + " for " + this.baseUri); boolean isHA = HAUtil.isClientFailoverConfigured(conf, this.baseUri); boolean isLogicalUri = isHA && HAUtil.isLogicalUri(conf, this.baseUri); // In non-HA or non-logical URI case, the code needs to call // getCanonicalUri() in order to handle the case where no port is // specified in the URI this.tokenServiceName = isLogicalUri ? HAUtil.buildTokenServiceForLogicalUri(this.baseUri, getScheme()) : SecurityUtil.buildTokenService(getCanonicalUri()); if (!isHA) { this.retryPolicy = RetryUtils.getDefaultRetryPolicy(conf, DFSConfigKeys.DFS_HTTP_CLIENT_RETRY_POLICY_ENABLED_KEY, DFSConfigKeys.DFS_HTTP_CLIENT_RETRY_POLICY_ENABLED_DEFAULT, DFSConfigKeys.DFS_HTTP_CLIENT_RETRY_POLICY_SPEC_KEY, DFSConfigKeys.DFS_HTTP_CLIENT_RETRY_POLICY_SPEC_DEFAULT, SafeModeException.class); } else { int maxFailoverAttempts = conf.getInt(DFSConfigKeys.DFS_HTTP_CLIENT_FAILOVER_MAX_ATTEMPTS_KEY, DFSConfigKeys.DFS_HTTP_CLIENT_FAILOVER_MAX_ATTEMPTS_DEFAULT); int maxRetryAttempts = conf.getInt(DFSConfigKeys.DFS_HTTP_CLIENT_RETRY_MAX_ATTEMPTS_KEY, DFSConfigKeys.DFS_HTTP_CLIENT_RETRY_MAX_ATTEMPTS_DEFAULT); int failoverSleepBaseMillis = conf.getInt(DFSConfigKeys.DFS_HTTP_CLIENT_FAILOVER_SLEEPTIME_BASE_KEY, DFSConfigKeys.DFS_HTTP_CLIENT_FAILOVER_SLEEPTIME_BASE_DEFAULT); int failoverSleepMaxMillis = conf.getInt(DFSConfigKeys.DFS_HTTP_CLIENT_FAILOVER_SLEEPTIME_MAX_KEY, DFSConfigKeys.DFS_HTTP_CLIENT_FAILOVER_SLEEPTIME_MAX_DEFAULT); this.retryPolicy = RetryPolicies.failoverOnNetworkException(RetryPolicies.TRY_ONCE_THEN_FAIL, maxFailoverAttempts, maxRetryAttempts, failoverSleepBaseMillis, failoverSleepMaxMillis); } this.workingDir = getHomeDirectory(); //Delegation tokens don't work with httpfs this.canRefreshDelegationToken = false; this.disallowFallbackToInsecureCluster = !conf.getBoolean( CommonConfigurationKeys.IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_KEY, CommonConfigurationKeys.IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_DEFAULT); this.delegationToken = null; this.defaultFilePermissions = Short .decode(conf.get(FS_DL_IMPL_DEFAULT_FILE_PERMISSIONS, this.DEFAULT_FILE_PERMISSIONS)); this.defaultUMask = Short.decode(conf.get(FS_DL_IMPL_DEFAULT_UMASK, this.DEFAULT_UMASK)); this.transportScheme = conf.get(FS_DL_IMPL_TRANSPORT_SCHEME_CONFIG_NAME, FS_DL_IMPL_DEFAULT_TRANSPORT_SCHEME); if (!checkJCE()) throw new IOException(JCE_ERROR); }
From source file:org.apache.catalina.core.NamingContextListener.java
/** * Set the specified environment entries in the naming context. *//*from ww w . j av a 2 s .c o m*/ public void addEnvironment(ContextEnvironment env) { Object value = null; // Instantiating a new instance of the correct object type, and // initializing it. String type = env.getType(); try { if (type.equals("java.lang.String")) { value = env.getValue(); } else if (type.equals("java.lang.Byte")) { if (env.getValue() == null) { value = new Byte((byte) 0); } else { value = Byte.decode(env.getValue()); } } else if (type.equals("java.lang.Short")) { if (env.getValue() == null) { value = new Short((short) 0); } else { value = Short.decode(env.getValue()); } } else if (type.equals("java.lang.Integer")) { if (env.getValue() == null) { value = new Integer(0); } else { value = Integer.decode(env.getValue()); } } else if (type.equals("java.lang.Long")) { if (env.getValue() == null) { value = new Long(0); } else { value = Long.decode(env.getValue()); } } else if (type.equals("java.lang.Boolean")) { value = Boolean.valueOf(env.getValue()); } else if (type.equals("java.lang.Double")) { if (env.getValue() == null) { value = new Double(0); } else { value = Double.valueOf(env.getValue()); } } else if (type.equals("java.lang.Float")) { if (env.getValue() == null) { value = new Float(0); } else { value = Float.valueOf(env.getValue()); } } else if (type.equals("java.lang.Character")) { if (env.getValue() == null) { value = new Character((char) 0); } else { if (env.getValue().length() == 1) { value = new Character(env.getValue().charAt(0)); } else { throw new IllegalArgumentException(); } } } else { log(sm.getString("naming.invalidEnvEntryType", env.getName())); } } catch (NumberFormatException e) { log(sm.getString("naming.invalidEnvEntryValue", env.getName())); } catch (IllegalArgumentException e) { log(sm.getString("naming.invalidEnvEntryValue", env.getName())); } // Binding the object to the appropriate name if (value != null) { try { if (debug >= 2) log(" Adding environment entry " + env.getName()); createSubcontexts(envCtx, env.getName()); envCtx.bind(env.getName(), value); } catch (NamingException e) { log(sm.getString("naming.invalidEnvEntryValue", e)); } } }
From source file:com.funambol.foundation.items.dao.PIMCalendarDAO.java
/** * Extracts a Short value from the status property of a task object. * If any error occurs or the object/property is missing, 0 is returned. * * @param task the object containing the status property as String * * @return the short corresponding to the status property. *//*from w w w. ja v a2 s .co m*/ private Short getTaskStatus(Task task) { Short status = null; if (task != null && task.getStatus() != null) { String tmp = task.getStatus().getPropertyValueAsString(); if (tmp != null && tmp.length() > 0) { try { status = Short.decode(tmp); } catch (NumberFormatException e) { } } } return status; }
From source file:org.ohmage.domain.campaign.Campaign.java
/** * Process the property Nodes from the XML and creates a mapping of all of * the keys to label/value pairs.//from w w w.jav a 2s .c om * * @param properties The properties for the prompt in the XML. * * @return A mapping of property keys to their label/value pairs. * * @throws DomainException Thrown if a property is invalid. */ private static Map<String, LabelValuePair> getKeyValueLabelTrios(final String containerId, final Nodes properties) throws DomainException { int numProperties = properties.size(); if (numProperties == 0) { return Collections.emptyMap(); } Map<String, LabelValuePair> result = new HashMap<String, LabelValuePair>(numProperties); for (int i = 0; i < numProperties; i++) { Node propertyNode = properties.get(i); Nodes keys = propertyNode.query(XML_PROPERTY_KEY); if (keys.size() == 0) { throw new DomainException("The property key is missing: " + containerId); } else if (keys.size() > 1) { throw new DomainException("Multiple property keys were found: " + containerId); } String key = keys.get(0).getValue().trim(); if (key.length() == 0) { throw new DomainException("The property key cannot be whitespace only: " + containerId); } Nodes labels = propertyNode.query(XML_PROPERTY_LABEL); if (labels.size() == 0) { throw new DomainException("The property label is missing: " + containerId); } else if (labels.size() > 1) { throw new DomainException("Multiple property labels were found: " + containerId); } String label = labels.get(0).getValue().trim(); Number value = null; Nodes values = propertyNode.query(XML_PROPERTY_VALUE); if (values.size() > 1) { throw new DomainException("Multiple property values found: " + containerId); } else if (values.size() == 1) { String valueString = values.get(0).getValue().trim(); try { value = Short.decode(valueString); } catch (NumberFormatException notShort) { try { value = Integer.decode(valueString); } catch (NumberFormatException notInteger) { try { value = Long.decode(valueString); } catch (NumberFormatException notLong) { try { value = Float.parseFloat(valueString); } catch (NumberFormatException notFloat) { try { value = Double.parseDouble(valueString); } catch (NumberFormatException notDouble) { throw new DomainException( "The property value is not a numeric value: " + containerId); } } } } } } if (result.put(key, new LabelValuePair(label, value)) != null) { throw new DomainException( "Multiple properties with the same key were found for the container with id: " + containerId); } } return result; }