List of usage examples for java.lang Integer decode
public static Integer decode(String nm) throws NumberFormatException
From source file:org.openintents.safe.CryptoHelper.java
public static byte[] hexStringToBytes(String hex) { byte[] bytes = new byte[hex.length() / 2]; int j = 0;//ww w . java 2s . com for (int i = 0; i < hex.length(); i += 2) { try { String hexByte = hex.substring(i, i + 2); Integer k = Integer.decode("0x" + hexByte); bytes[j++] = k.byteValue(); } catch (NumberFormatException e) { Log.i(TAG, e.getLocalizedMessage()); return bytes; } catch (StringIndexOutOfBoundsException e) { Log.i(TAG, "StringIndexOutOfBoundsException"); return bytes; } } return bytes; }
From source file:com.wandisco.s3hdfs.rewrite.redirect.VersionRedirect.java
/** * Places a new .v file in the default version directory. * * @param nnHostAddress//from w w w . j a v a 2 s . co m * @param userName * @throws IOException */ public String createVersion(String nnHostAddress, String userName) throws IOException { String[] nnHost = nnHostAddress.split(":"); String uri = (path != null) ? path.getFullHdfsObjPath() : request.getPathInfo(); String versionpath = replaceUri(uri, OBJECT_FILE_NAME, VERSION_FILE_NAME); PutMethod httpPut = (PutMethod) getHttpMethod(request.getScheme(), nnHost[0], Integer.decode(nnHost[1]), "CREATE&overwrite=true", userName, versionpath, PUT); String version = UUID.randomUUID().toString(); httpPut.setRequestEntity(new ByteArrayRequestEntity(version.getBytes(DEFAULT_CHARSET))); httpPut.setRequestHeader(S3_HEADER_NAME, S3_HEADER_VALUE); httpClient.executeMethod(httpPut); Header locationHeader = httpPut.getResponseHeader("Location"); LOG.debug("1st response: " + httpPut.getStatusLine().toString()); boolean containsRedirect = (locationHeader != null); httpPut.releaseConnection(); if (!containsRedirect) { LOG.debug("1st response did not contain redirect. " + "No version will be created."); return null; } // Handle redirect header transition assert httpPut.getStatusCode() == 307; // Consume response and re-allocate connection for redirect httpPut.setURI(new URI(locationHeader.getValue(), true)); httpClient.executeMethod(httpPut); LOG.debug("2nd response: " + httpPut.getStatusLine().toString()); if (httpPut.getStatusCode() != 200) { LOG.debug("Response not 200: " + httpPut.getResponseBodyAsString()); return null; } assert httpPut.getStatusCode() == 200; httpPut.releaseConnection(); return version; }
From source file:org.kchine.r.server.impl.RServantImpl.java
public RServantImpl(String name, String prefix, Registry registry) throws RemoteException { super(name, prefix, registry, _port); log.info("$$>rmi.port.start:" + _port); // -------------- init();/*from w w w . ja v a 2 s . c o m*/ log.info("Stub:" + PoolUtils.stubToHex(this)); if (System.getProperty("preloadall") != null && System.getProperty("preloadall").equalsIgnoreCase("true")) { try { Properties props = new Properties(); props.loadFromXML(this.getClass().getResourceAsStream("/classlist.xml")); for (Object c : props.keySet()) { this.getClass().getClassLoader().loadClass((String) c); } } catch (Exception e) { //e.printStackTrace(); } try { Properties props = new Properties(); props.loadFromXML(this.getClass().getResourceAsStream("/resourcelist.xml")); for (Object c : props.keySet()) { DirectJNI.getInstance().getResourceAsStream((String) c); } } catch (Exception e) { //e.printStackTrace(); } } if (System.getProperty("http.port") != null && !System.getProperty("http.port").equals("")) { try { final int port = Integer.decode(System.getProperty("http.port")); new Thread(new Runnable() { public void run() { try { startHttpServer(port); } catch (Exception e) { e.printStackTrace(); } } }).start(); } catch (Exception e) { e.printStackTrace(); } } new Thread(new Runnable() { public void run() { try { GroovyInterpreterSingleton.getInstance().exec("import org.kchine.r.server.R;"); GroovyInterpreterSingleton.getInstance().exec("R=org.kchine.r.server.R.getInstance();"); //GroovyInterpreterSingleton.getInstance().exec("SCI=(org.kchine.scilab.server.ScilabServices)org.kchine.r.server.R.getInstance();"); //GroovyInterpreterSingleton.getInstance().exec("OO=(org.kchine.openoffice.server.OpenOfficeServices)org.kchine.r.server.R.getInstance();"); } catch (Exception e) { e.printStackTrace(); } } }).start(); }
From source file:com.l2jfree.gameserver.templates.StatsSet.java
/** * Returns the int associated to the key put in parameter ("name"). * // w ww . jav a2 s .c o m * @param name : String designating the key in the set * @return int : value associated to the key */ public final int getInteger(String name) { Object val = get(name); if (val == null) throw new IllegalArgumentException("Integer value required, but not specified"); if (val instanceof Number) return ((Number) val).intValue(); try { return Integer.decode((String) val); } catch (Exception e) { throw new IllegalArgumentException("Integer value required, but found: " + val); } }
From source file:org.ormma.controller.OrmmaController.java
/** * Constructs an object from json via reflection * * @param json the json// w ww . j ava 2 s . c o m * @param c the class to convert into * @return the instance constructed * @throws IllegalAccessException the illegal access exception * @throws InstantiationException the instantiation exception * @throws NumberFormatException the number format exception * @throws NullPointerException the null pointer exception */ protected static Object getFromJSON(JSONObject json, Class<?> c) throws IllegalAccessException, InstantiationException, NumberFormatException, NullPointerException { Field[] fields = null; fields = c.getDeclaredFields(); Object obj = c.newInstance(); for (int i = 0; i < fields.length; i++) { Field f = fields[i]; String name = f.getName(); String JSONName = name.replace('_', '-'); Type type = f.getType(); String typeStr = type.toString(); try { if (typeStr.equals(INT_TYPE)) { String value = json.getString(JSONName).toLowerCase(); int iVal = 0; if (value.startsWith("#")) { iVal = Color.WHITE; try { if (value.startsWith("#0x")) { iVal = Integer.decode(value.substring(1)).intValue(); } else { iVal = Integer.parseInt(value.substring(1), 16); } } catch (NumberFormatException e) { // TODO: handle exception } } else { iVal = Integer.parseInt(value); } f.set(obj, iVal); } else if (typeStr.equals(STRING_TYPE)) { String value = json.getString(JSONName); f.set(obj, value); } else if (typeStr.equals(BOOLEAN_TYPE)) { boolean value = json.getBoolean(JSONName); f.set(obj, value); } else if (typeStr.equals(FLOAT_TYPE)) { float value = Float.parseFloat(json.getString(JSONName)); f.set(obj, value); } else if (typeStr.equals(NAVIGATION_TYPE)) { NavigationStringEnum value = NavigationStringEnum.fromString(json.getString(JSONName)); f.set(obj, value); } else if (typeStr.equals(TRANSITION_TYPE)) { TransitionStringEnum value = TransitionStringEnum.fromString(json.getString(JSONName)); f.set(obj, value); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return obj; }
From source file:net.bither.utils.TransactionsUtil.java
public static List<In> getInSignatureFromBither(String str) { List<In> result = new ArrayList<In>(); if (str.length() > 0) { String[] txs = str.split(";"); for (String tx : txs) { String[] ins = tx.split(":"); //todo base64 byte[] txHash = Utils.reverseBytes(Base64.decodeBase64(ins[0])); for (int i = 1; i < ins.length; i++) { String[] array = ins[i].split(","); int inSn = Integer.decode(array[0]); byte[] inSignature = Base64.decodeBase64(array[1]); In in = new In(); in.setTxHash(txHash);// w w w . j a v a2 s .c o m in.setInSn(inSn); in.setInSignature(inSignature); result.add(in); } } } return result; }
From source file:org.fire.platform.util.DateUtil.java
/** * ?/*from w w w.j a v a2 s .co m*/ * * @return */ public static Map<String, Integer> getWeekUpAndDown() { Map<String, Integer> map = new HashMap<String, Integer>(); Calendar c = Calendar.getInstance(); int weekday = c.get(Calendar.DAY_OF_WEEK) - 2; c.add(Calendar.DAY_OF_MONTH, -weekday); map.put("up", Integer.decode(getTime("yyyyMMdd", c.getTime()))); c.add(Calendar.DAY_OF_MONTH, 6); map.put("down", Integer.decode(getTime("yyyyMMdd", c.getTime()))); return map; }
From source file:fr.dutra.confluence2wordpress.action.SettingsAction.java
@Override public void validate() { if (StringUtils.isBlank(getWordpressRootUrl())) { addActionError(getText(ERRORS_REQUIRED_KEY), new Object[] { getText("settings.form.wordpressRootUrl.label") }); }//from w ww.ja v a 2s . com if (StringUtils.isBlank(getWordpressXmlRpcRelativePath())) { addActionError(getText(ERRORS_REQUIRED_KEY, new Object[] { getText("settings.form.wordpressXmlRpcRelativePath.label") })); } if (StringUtils.isBlank(getEditPostRelativePath())) { addActionError(getText(ERRORS_REQUIRED_KEY, new Object[] { getText("settings.form.editPostRelativePath.label") })); } if (StringUtils.isBlank(getWordpressUserName())) { addActionError(getText(ERRORS_REQUIRED_KEY, new Object[] { getText("settings.form.wordpressUserName.label") })); } if (StringUtils.isBlank(getWordpressPassword())) { addActionError(getText(ERRORS_REQUIRED_KEY, new Object[] { getText("settings.form.wordpressPassword.label") })); } if (StringUtils.isBlank(getWordpressBlogId())) { addActionError( getText(ERRORS_REQUIRED_KEY, new Object[] { getText("settings.form.wordpressBlogId.label") })); } if (StringUtils.isBlank(getSyntaxHighlighterPlugin())) { addActionError(getText(ERRORS_REQUIRED_KEY, new Object[] { getText("settings.form.syntaxHighlighterPlugin.label") })); } if (StringUtils.isBlank(getWordpressMaxConnections())) { addActionError(getText(ERRORS_REQUIRED_KEY, new Object[] { getText("settings.form.wordpressMaxConnections.label") })); } if (StringUtils.isNotBlank(getProxyPort())) { try { Integer.decode(getProxyPort()); } catch (NumberFormatException e) { addActionError( getText(ERRORS_INTEGER_KEY, new Object[] { getText("settings.form.proxyPort.label") })); } } if (StringUtils.isNotBlank(getWordpressMaxConnections())) { try { Integer.decode(getWordpressMaxConnections()); } catch (NumberFormatException e) { addActionError(getText(ERRORS_INTEGER_KEY, new Object[] { getText("settings.form.wordpressMaxConnections.label") })); } } String url = getWordpressRootUrl() + getWordpressXmlRpcRelativePath(); try { new URL(url); } catch (MalformedURLException e) { addActionError(getText(ERRORS_URL_KEY, new Object[] { url })); } for (int i = 0; i < tagNames.size(); i++) { String tagName = tagNames.get(i); if (StringUtils.isBlank(tagName)) { addActionError(getText(ERRORS_TAG_NAME_EMPTY_KEY, new Object[] { i + 1 })); } else if (!TAG_NAME_PATTERN.matcher(tagName).matches()) { addActionError(getText(ERRORS_TAG_NAME_INVALID_KEY, new Object[] { tagName, i + 1 })); } } for (int i = 0; i < tagAttributes.size(); i++) { String tagAttribute = tagAttributes.get(i); if (StringUtils.isBlank(tagAttribute)) { addActionError(getText(ERRORS_TAG_ATTRIBUTE_EMPTY_KEY, new Object[] { i + 1 })); } } }
From source file:marytts.server.MaryProperties.java
/** * Get a property from the underlying properties. * @param property the property requested * @param defaultValue the value to return if the property is not defined * @return the integer property value if found and valid, defaultValue otherwise. *///w w w. jav a2 s . c o m public static int getInteger(String property, int defaultValue) { String value = getProperty(property); if (value == null) { return defaultValue; } try { return Integer.decode(value).intValue(); } catch (NumberFormatException e) { return defaultValue; } }
From source file:Characters.java
/** * <p>/*ww w . j a v a 2 s .c om*/ * Converts XML Unicode character entities into their character equivalents within a given string. * </p> * <p> * This will handle entities in the form <code>&#<i>xxxx</i>;</code> (decimal character code, where <i>xxxx * </i> is a valid character code), or <code>&#x<i>xxxx</i></code> (hexadecimal character code, where * <i>xxxx </i> is a valid character code). * </p> * * @param input the string to process * @return the input with all XML Unicode character entity codes replaced */ public static String convertXMLUnicodeEntities(String input) { int inputLength = input.length(); int pointer = 0; StringBuilder result = new StringBuilder(inputLength); while (pointer < input.length()) { if (input.charAt(pointer) == '&') { if (input.charAt(pointer + 1) == '#') { // Hexadecimal character code. if (input.charAt(pointer + 2) == 'x') { int semicolon = input.indexOf(';', pointer + 3); // Check that the semicolon is not so far away that it // is likely not part of this entity. if (semicolon < pointer + 7) { try { // Integer.decode from pointer + 2 includes the // "x". result.append( (char) Integer.decode(input.substring(pointer + 2, semicolon)).intValue()); pointer += (semicolon - pointer + 1); } catch (NumberFormatException e) { // drop out } } } // Decimal character code. else { // Check that the semicolon is not so far away that it // is likely not part of this entity. int semicolon = input.indexOf(';', pointer + 2); if (semicolon < pointer + 7) { try { // Integer.parseInt from pointer + 2 excludes // the "&#". result.append((char) Integer.parseInt(input.substring(pointer + 2, semicolon))); pointer += (semicolon - pointer + 1); continue; } catch (NumberFormatException e) { // drop out } } } } } result.append(input.charAt(pointer)); pointer++; } return result.toString(); }