List of usage examples for java.lang Integer decode
public static Integer decode(String nm) throws NumberFormatException
From source file:org.kchine.r.server.http.RHttpProxy.java
public static Object invoke(String url, String sessionId, String servantName, String methodName, Class<?>[] methodSignature, Object[] methodParameters, HttpClient httpClient) throws TunnelingException { if (System.getProperty("proxy_host") != null && !System.getProperty("proxy_host").equals("")) { httpClient.getHostConfiguration().setProxy(System.getProperty("proxy_host"), Integer.decode(System.getProperty("proxy_port"))); }/*from ww w .j av a 2s. co m*/ PostMethod postPush = null; try { Object result = null; try { postPush = new PostMethod(url + "?method=invoke"); NameValuePair[] data = { new NameValuePair("servantname", PoolUtils.objectToHex(servantName)), new NameValuePair("methodname", PoolUtils.objectToHex(methodName)), new NameValuePair("methodsignature", PoolUtils.objectToHex(methodSignature)), new NameValuePair("methodparameters", PoolUtils.objectToHex(methodParameters)) }; postPush.setRequestBody(data); if (sessionId != null && !sessionId.equals("")) { postPush.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES); postPush.setRequestHeader("Cookie", "JSESSIONID=" + sessionId); } httpClient.executeMethod(postPush); result = new ObjectInputStream(postPush.getResponseBodyAsStream()).readObject(); } catch (ConnectException e) { throw new ConnectionFailedException(); } catch (Exception e) { throw new TunnelingException("Client Side", e); } if (result != null && result instanceof TunnelingException) { new Exception().printStackTrace(); throw (TunnelingException) result; } return result; } finally { if (postPush != null) { postPush.releaseConnection(); } } }
From source file:uni.bielefeld.cmg.sparkhit.util.Parameter.java
public DefaultParam importCommandLine() { /* Assigning Parameter ID to an ascending number */ putParameterID();//from w w w. j a v a2 s .c om /* Assigning parameter descriptions to each parameter ID */ addParameterInfo(); /* need a Object parser of PosixParser class for the function parse of CommandLine class */ PosixParser parser = new PosixParser(); /* print out help information */ HelpParam help = new HelpParam(parameter, parameterMap); /* check each parameter for assignment */ try { long input_limit = -1; int threads = Runtime.getRuntime().availableProcessors(); /* Set Object cl of CommandLine class for Parameter storage */ CommandLine cl = parser.parse(parameter, arguments, true); if (cl.hasOption(HELP)) { help.printHelp(); System.exit(0); } if (cl.hasOption(HELP2)) { help.printHelp(); System.exit(0); } if (cl.hasOption(VERSION)) { System.exit(0); } /* Checking all parameters */ String value; if ((value = cl.getOptionValue(IDENTITY)) != null) { if (Integer.decode(value) >= 0 || Integer.decode(value) <= 100) { param.readIdentity = Integer.decode(value); if (param.readIdentity >= 94) { param.setKmerOverlap(0); param.setKmerSize(12); } } else { throw new RuntimeException("Parameter " + IDENTITY + " should not be integer of %"); } } if ((value = cl.getOptionValue(KMER_SIZE)) != null) { if (Integer.decode(value) >= 8 || Integer.decode(value) <= 12) { param.kmerSize = Integer.decode(value); param.setKmerSize(param.kmerSize); } else { throw new RuntimeException("Parameter " + KMER_SIZE + " should be set between 8-12"); } } if ((value = cl.getOptionValue(OVERLAP)) != null) { if (Integer.decode(value) >= 0 || Integer.decode(value) <= param.kmerSize) { param.kmerOverlap = Integer.decode(value); } else { throw new RuntimeException( "Parameter " + OVERLAP + " should not be bigger than kmer size or smaller than 0"); } } /** * not available for now */ if ((value = cl.getOptionValue(BUILD_REF)) != null) { param.inputBuildPath = new File(value).getAbsolutePath(); param.inputFaPath = param.inputBuildPath; return param; } if ((value = cl.getOptionValue(THREADS)) != null) { if (Integer.decode(value) <= threads) { param.threads = Integer.decode(value); } else if (Integer.decode(value) == 0) { param.threads = threads; } else if (Integer.decode(value) < 0) { throw new RuntimeException( "Parameter " + THREADS + " come on, CPU number could not be smaller than 1"); } else { throw new RuntimeException("Parameter " + THREADS + " is bigger than the number of your CPUs. Should be smaller than " + threads); } } if ((value = cl.getOptionValue(PARTITIONS)) != null) { param.partitions = Integer.decode(value); } if ((value = cl.getOptionValue(EVALUE)) != null) { param.eValue = Double.parseDouble(value); } if ((value = cl.getOptionValue(GLOBAL)) != null) { param.globalOrLocal = Integer.decode(value); } if ((value = cl.getOptionValue(UNMASK)) != null) { if (Integer.decode(value) == 1 || Integer.decode(value) == 0) { param.maskRepeat = Integer.decode(value); } else { throw new RuntimeException("Parameter " + UNMASK + " should be set as 1 or 0"); } } if ((value = cl.getOptionValue(COVERAGE)) != null) { param.alignLength = Integer.decode(value); } if ((value = cl.getOptionValue(MINLENGTH)) != null) { if (Integer.decode(value) >= 0) { param.minReadSize = Integer.decode(value); } else { throw new RuntimeException("Parameter " + MINLENGTH + " should be larger than 0"); } } if ((value = cl.getOptionValue(ATTEMPTS)) != null) { if (Integer.decode(value) >= 1) { param.maxTrys = Integer.decode(value); } else { throw new RuntimeException("Parameter " + ATTEMPTS + " at least try once"); } } if ((value = cl.getOptionValue(HITS)) != null) { if (Integer.decode(value) >= 0) { param.reportRepeatHits = Integer.decode(value); } else { throw new RuntimeException("Parameter " + HITS + " should be bigger than 0"); } } if ((value = cl.getOptionValue(STRAND)) != null) { if (Integer.decode(value) == 0 || Integer.decode(value) == 1 || Integer.decode(value) == 2) { param.chains = Integer.decode(value); } else { throw new RuntimeException("Parameter " + STRAND + " should be either 0, 1 or 2"); } } if ((value = cl.getOptionValue(INPUT_FASTQ)) != null) { param.inputFqPath = value; } else if ((value = cl.getOptionValue(INPUT_LINE)) != null) { param.inputFqLinePath = value; param.inputFqPath = value; } else { help.printHelp(); System.exit(0); //throw new IOException("Input query file not specified.\nUse -help for list of options"); } /* not applicable for HDFS and S3 */ /* using TextFileBufferInput for such purpose */ // File inputFastq = new File(param.inputFqPath).getAbsoluteFile(); // if (!inputFastq.exists()){ // err.println("Input query file not found."); // return; //i } if ((value = cl.getOptionValue(OUTPUT_FILE)) != null) { param.outputPath = value; } else { info.readMessage("Output file not set of -outfile options"); info.screenDump(); } if ((value = cl.getOptionValue(INPUT_REF)) != null) { param.inputFaPath = new File(value).getAbsolutePath(); } else { info.readMessage("Input reference file had not specified."); info.screenDump(); } File inputFasta = new File(param.inputFaPath).getAbsoluteFile(); if (!inputFasta.exists()) { info.readMessage("Input reference file had not found."); info.screenDump(); } File outfile = new File(param.outputPath).getAbsoluteFile(); if (outfile.exists()) { info.readParagraphedMessages( "Output file : \n\t" + param.outputPath + "\nalready exists, will be overwrite."); info.screenDump(); Runtime.getRuntime().exec("rm -rf " + param.outputPath); } if (param.inputFqPath.endsWith(".gz")) { } param.bestNas = (param.alignLength * param.readIdentity) / 100; param.bestKmers = param.alignLength - (param.alignLength - param.bestNas) * 4 - 3; if (param.bestKmers < (param.kmerSize - 3)) { param.bestKmers = param.kmerSize - 3; } if (param.maskRepeat == 0) { param.validNt = param.validNtNomask; param.invalidNt = param.nxNomask; } } catch (IOException e) { // Don`t catch this, NaNaNaNa, U can`t touch this. info.readMessage("Parameter settings incorrect."); info.screenDump(); e.printStackTrace(); System.exit(0); } catch (RuntimeException e) { info.readMessage("Parameter settings incorrect."); info.screenDump(); e.printStackTrace(); System.exit(0); } catch (ParseException e) { info.readMessage("Parameter settings incorrect."); info.screenDump(); e.printStackTrace(); System.exit(0); } return param; }
From source file:com.simas.vc.background_tasks.FFprobe.java
private static FileAttributes parseJsonAttributes(@NonNull String json) throws IOException, VCException { Log.d(TAG, json);/*from w w w. j a v a2 s .c om*/ // Parse JSON List<JSONObject> jStream = new ArrayList<>(); JSONObject format; try { JSONObject obj = new JSONObject(json); // Fetch streams JSONArray streamArr = obj.getJSONArray("streams"); int streamCount = streamArr.length(); for (int i = 0; i < streamCount; ++i) { jStream.add(streamArr.getJSONObject(i)); } // Fetch format format = obj.getJSONObject("format"); } catch (JSONException e) { e.printStackTrace(); return null; } // Format FileAttributes fa = new FileAttributes(getJSONString(format, Utils.getString(R.string.format_filename)), getLong(format, Utils.getString(R.string.format_size)), getJSONDouble(format, Utils.getString(R.string.format_duration))); fa.setName(getJSONString(format, Utils.getString(R.string.format_name))) .setLongName(getJSONString(format, Utils.getString(R.string.format_long_name))); // Streams for (JSONObject jsonObj : jStream) { StreamType streamType = getStreamType(jsonObj); if (streamType == null) continue; // Stream Stream stream; // Codec name String codecName = getJSONString(jsonObj, Utils.getString(R.string.stream_name)); if (codecName == null || INVALID_CODEC_NAMES.contains(codecName.toLowerCase())) { Log.w(TAG, "Skipped invalid codec: " + codecName); continue; } switch (streamType) { case AUDIO: stream = new AudioStream(codecName) .setChannelCount(getJSONInteger(jsonObj, Utils.getString(R.string.stream_channels))) .setSampleRate(getJSONInteger(jsonObj, Utils.getString(R.string.stream_sample_rate))); break; case VIDEO: // Create VideoStream Integer w = getJSONInteger(jsonObj, Utils.getString(R.string.stream_width)); Integer h = getJSONInteger(jsonObj, Utils.getString(R.string.stream_height)); stream = new VideoStream(w, h, codecName) .setAspectRatio(getJSONString(jsonObj, Utils.getString(R.string.stream_aspect_ratio))) .setTBN(getJSONString(jsonObj, Utils.getString(R.string.stream_tbn))) .setTBC(getJSONString(jsonObj, Utils.getString(R.string.stream_tbc))) .setTBR(getJSONString(jsonObj, Utils.getString(R.string.stream_tbr))); break; default: continue; } /* Shared stream attributes */ // Codec name stream.setCodecName(codecName); // Stream duration Double duration = getJSONDouble(jsonObj, Utils.getString(R.string.stream_duration)); // Codec tag (default is 0) String tag = getJSONString(jsonObj, Utils.getString(R.string.stream_codec_tag)); try { stream.setCodecTag(Integer.decode(tag)); } catch (NumberFormatException e) { e.printStackTrace(); // throw new VCException("Unrecognized codec found!"); } // Codec long name stream.setCodecLongName(getJSONString(jsonObj, Utils.getString(R.string.stream_long_name))); // Append to FileAttributes fa.addStream(stream); } return fa; }
From source file:PVGraph.java
private JPanel makeCommonButtonsPanel(final PVGraphView view) { JPanel commonButtonsPanel = new JPanel(); commonButtonsPanel.setBorder(new EtchedBorder()); JButton newGraphButton = new JButton("New Graph"); newGraphButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { new PVGraph((Calendar) PVGraph.this.date.clone(), tabPane.getSelectedIndex()); }// w w w.j ava 2s . c o m }); JButton runSmatoolButton = new JButton("Run smatool"); runSmatoolButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { runSmatool(); view.updateChart(); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } } }); commonButtonsPanel.add(newGraphButton); if (Integer.decode(props.getProperty("smatool.havebutton", "1")) != 0) commonButtonsPanel.add(runSmatoolButton); int smatoolPeriod = Integer.decode(props.getProperty("smatool.period", "0")); if (smatoolPeriod > 0) { final JRadioButton trackDayRadioButton = new JRadioButton("Track day"); trackDayRadioButton.setSelected(trackDay); trackDayRadioButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { trackDay = trackDayRadioButton.isSelected(); } }); commonButtonsPanel.add(trackDayRadioButton); } return commonButtonsPanel; }
From source file:us.mn.state.health.lims.common.util.validator.ValidWhenParser.java
public final void integer() throws RecognitionException, TokenStreamException { Token d = null;/* w w w .j av a 2 s . c o m*/ Token h = null; Token o = null; switch (LA(1)) { case DECIMAL_LITERAL: { d = LT(1); match(DECIMAL_LITERAL); //System.out.println("Going through integer()1 " + d.getText()); argStack.push(Integer.decode(d.getText())); break; } case HEX_LITERAL: { h = LT(1); match(HEX_LITERAL); //System.out.println("Going through integer()2 " + h.getText()); argStack.push(Integer.decode(h.getText())); break; } case OCTAL_LITERAL: { o = LT(1); match(OCTAL_LITERAL); //System.out.println("Going through integer()3 " + o.getText()); argStack.push(Integer.decode(o.getText())); break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } }
From source file:com.wandisco.s3hdfs.rewrite.redirect.MultiPartFileRedirect.java
private boolean partsAreInOrder(List<String> sources) { String pathStr = path.getHdfsRootUploadPath(); int index = 0; for (String source : sources) { int nextIndex = Integer.decode(source.replace(pathStr, "").replace(PART_FILE_NAME, "")); if (nextIndex == (index + 1)) { index = nextIndex;// www .j ava 2 s . c o m } else { return false; } } return true; }
From source file:com.l2jfree.gameserver.templates.StatsSet.java
/** * Returns the int[] associated to the key put in parameter ("name"). If the value associated to the key is null, this method returns the value of the parameter deflt. * /* ww w. j a va2s .c o m*/ * @param name : String designating the key in the set * @return int[] : value associated to the key */ public final int[] getIntegerArray(String name) { Object val = get(name); if (val == null) throw new IllegalArgumentException("Integer value required, but not specified"); if (val instanceof Number) { int[] result = { ((Number) val).intValue() }; return result; } int c = 0; String[] vals = ((String) val).split(";"); int[] result = new int[vals.length]; for (String v : vals) { try { result[c++] = Integer.decode(v); } catch (Exception e) { throw new IllegalArgumentException("Integer value required, but found: " + val); } } return result; }
From source file:com.aurel.track.exchange.docx.exporter.PreprocessImage.java
private static Integer parseNumber(String imgSrc, String tag) { int workItemIndex = imgSrc.indexOf(tag); if (workItemIndex != -1) { String workItemString = imgSrc.substring(workItemIndex); StringBuilder stringBuilder = new StringBuilder(workItemString); stringBuilder.replace(0, tag.length(), ""); int i = 0; char charValue; StringBuilder numberString = new StringBuilder(); do {// w w w. j a v a 2s . c om charValue = stringBuilder.charAt(i++); if (Character.isDigit(charValue)) { numberString.append(charValue); } } while (stringBuilder.length() > i && Character.isDigit(charValue)); return Integer.decode(numberString.toString()); } return null; }
From source file:Main.java
/** * <p>Convert a <code>String</code> to a <code>Integer</code>, handling * hex and octal notations.</p>//from w w w .j av a2 s. c o m * * @param val a <code>String</code> to convert * @return converted <code>Integer</code> * @throws NumberFormatException if the value cannot be converted */ public static Integer createInteger(String val) { // decode() handles 0xAABD and 0777 (hex and octal) as well. return Integer.decode(val); }
From source file:org.apache.cocoon.transformation.JPathTransformer.java
/** * Helper method to process a <jpath:continuation select=""/> element. * * @param a an <code>Attributes</code> value * @exception SAXException if an error occurs */// w w w . ja v a 2 s . c om private void doContinuation(final Attributes a) throws SAXException { final String level = a.getValue(JPATH_CONTINUATION_SELECT); final String id = (level != null) ? m_kont.getContinuation(Integer.decode(level).intValue()).getId() : m_kont.getContinuation(0).getId(); sendTextEvent(id); }