List of usage examples for java.lang Integer decode
public static Integer decode(String nm) throws NumberFormatException
From source file:sam_testclient.services.FileSubmitService.java
protected static byte[] getBytesFromMessage(Message m) { String[] array = m.getContent().split(","); String[] array2 = new String[array.length]; for (int i = 0; i < array.length; i++) { array2[i] = array[i].replaceAll(" |\\[|\\]", ""); }//from ww w.j a v a 2s .co m List<byte[]> resultList = new ArrayList<>(); int[] intBuffer = new int[array2.length]; for (int i = 0; i < array2.length; i++) { intBuffer[i] = Integer.decode(array2[i]); } byte[] result = new byte[intBuffer.length]; for (int i = 0; i < intBuffer.length; i++) { result[i] = (byte) intBuffer[i]; } return result; }
From source file:eu.comsode.unifiedviews.plugins.transformer.generatedtorelational.GeneratedToRelational.java
@Override protected void innerExecute() throws DPUException { Connection conn = null;// w w w .j ava 2s . co m try { createOutputTable(); //Retrieves data from CKAN resource fillInputTableFromCKAN(); LOG.debug("{} records retrieved from CKAN.", inputFromCkan.size()); Collections.sort(inputFromCkan, new Comparator<GenTableRow>() { @Override public int compare(GenTableRow o1, GenTableRow o2) { return Long.compare(o1.id, o2.id); } }); this.output.addExistingDatabaseTable(GENERATED_TABLE_NAME.toUpperCase(), GENERATED_TABLE_NAME.toUpperCase()); //If there are no data on input, create first row, else update table in CKAN if (inputFromCkan.size() == 0) { LOG.debug("No input table found!"); String dateToInsert = fmt.format(new Date()); String insertIntoQuery = String.format("INSERT INTO %s VALUES (0, '%s');", GENERATED_TABLE_NAME, dateToInsert); LOG.debug("Inserting first data to Output table with query: " + insertIntoQuery); DatabaseHelper.executeUpdate(insertIntoQuery, output); } else { Integer todayInt = Integer.decode(intFmt.format(new Date())); PreparedStatement psInsert = null; PreparedStatement ps = null; int counter = 0; conn = output.getDatabaseConnection(); //Iterate throgh data retrieved from CKAN for (GenTableRow currentRow : inputFromCkan) { counter++; Integer lastRunInt = Integer .decode(currentRow.data.substring(0, 10).replaceAll("-", "").trim()); LOG.debug(String.format("Last run date is: %d, today is: %d", lastRunInt, todayInt)); //If the record is not deleted and it is from previous day, delete it if (currentRow.deletedTimestamp != null) { //Create new record in database if (counter == inputFromCkan.size() && lastRunInt.compareTo(todayInt) < 0) { LOG.debug("Starting to insert record."); String dateToInsert = fmt.format(new Date()); String insertIntoQuery = String.format("INSERT INTO %s VALUES (%d,'%s');", GENERATED_TABLE_NAME, currentRow.id + 1, dateToInsert); LOG.debug("Inserting data to Output table with query: " + insertIntoQuery); DatabaseHelper.executeUpdate(insertIntoQuery, output); } LOG.debug("Commiting changes in output table."); conn.commit(); continue; } else if (lastRunInt.compareTo(todayInt) < 0) { if (counter == inputFromCkan.size() && lastRunInt.compareTo(todayInt) < 0) { LOG.debug("Starting to insert record."); String dateToInsert = fmt.format(new Date()); String insertIntoQuery = String.format("INSERT INTO %s VALUES (%d,'%s');", GENERATED_TABLE_NAME, currentRow.id + 1, dateToInsert); LOG.debug("Inserting data to Output table with query: " + insertIntoQuery); DatabaseHelper.executeUpdate(insertIntoQuery, output); } LOG.debug("Commiting changes in output table."); conn.commit(); continue; } String insertRecQuery = insertRecordForPrepStmt(GENERATED_TABLE_NAME, currentRow.id, currentRow.data); LOG.debug("Executing query: {}", insertRecQuery); psInsert = conn.prepareStatement(insertRecQuery); psInsert.execute(); conn.commit(); //If record is created today, update it if (lastRunInt.compareTo(todayInt) == 0 && currentRow.deletedTimestamp == null) { LOG.debug("Starting to update records."); String queryModify = updateModifyRecordForPrepStmt(GENERATED_TABLE_NAME.toUpperCase(), "data", fmt.format(new Date())); ps = conn.prepareStatement(queryModify); ps.setLong(1, currentRow.id); LOG.debug("Executing query: {} for ID: {}", queryModify, currentRow.id.toString()); ps.execute(); } LOG.debug("Commiting changes in output table."); conn.commit(); } } this.faultTolerance.execute(new FaultTolerance.Action() { @Override public void action() throws Exception { eu.unifiedviews.helpers.dataunit.resource.Resource resource = ResourceHelpers .getResource(GeneratedToRelational.this.output, GENERATED_TABLE_NAME); Date now = new Date(); resource.setCreated(now); resource.setLast_modified(now); ResourceHelpers.setResource(GeneratedToRelational.this.output, GENERATED_TABLE_NAME, resource); } }); } catch (DataUnitException | SQLException ex) { ContextUtils.sendError(this.ctx, "errors.dpu.failed", ex, "errors.dpu.failed"); return; } finally { DatabaseHelper.tryCloseConnection(conn); } }
From source file:uni.bielefeld.cmg.sparkhit.util.ParameterForReductioner.java
public DefaultParam importCommandLine() { /* Assigning Parameter ID to an ascending number */ putParameterID();/*from ww w . j a v a2s . co m*/ /* 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.printStatisticerHelp(); System.exit(0); } if (cl.hasOption(HELP2)) { help.printStatisticerHelp(); System.exit(0); } if (cl.hasOption(VERSION)) { System.exit(0); } /* Checking all parameters */ String value; if ((value = cl.getOptionValue(PARTITIONS)) != null) { param.partitions = Integer.decode(value); } if ((value = cl.getOptionValue(WINDOW)) != null) { param.window = Integer.decode(value); } if ((value = cl.getOptionValue(COLUMN)) != null) { param.columns = value; param.columnStart = Integer.decode(value.split("-")[0]); param.columnEnd = Integer.decode(value.split("-")[1]); } else { param.columnStart = Integer.decode(param.columns.split("-")[0]); param.columnEnd = Integer.decode(param.columns.split("-")[1]); } if (cl.hasOption(CACHE)) { param.cache = true; } if ((value = cl.getOptionValue(COMPO)) != null) { param.componentNum = Integer.decode(value); } if ((value = cl.getOptionValue(INPUT_VCF)) != null) { param.inputFqPath = value; } else if ((value = cl.getOptionValue(INPUT_TAB)) != null) { param.inputFqPath = value; } else { help.printStatisticerHelp(); System.exit(0); // throw new IOException("Input 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_LINE)) != null) { param.outputPath = value; } else { help.printStatisticerHelp(); info.readMessage("Output file not set with -outfile options"); info.screenDump(); System.exit(0); } 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); } } 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:uni.bielefeld.cmg.sparkhit.util.ParameterForVariantCaller.java
public DefaultParam importCommandLine() { /* Assigning Parameter ID to an ascending number */ putParameterID();/*from w ww .j av a 2s . co m*/ /* 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.printScriptPiperHelp(); System.exit(0); } if (cl.hasOption(HELP2)) { help.printScriptPiperHelp(); System.exit(0); } if (cl.hasOption(VERSION)) { System.exit(0); } /* Checking all parameters */ String value; if ((value = cl.getOptionValue(PARTITIONS)) != null) { param.partitions = Integer.decode(value); } if ((value = cl.getOptionValue(INPUT_LIST)) != null) { param.inputList = value; } else { help.printScriptPiperHelp(); System.exit(0); // throw new IOException("Input 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_LINE)) != null) { param.outputPath = value; } else { help.printScriptPiperHelp(); info.readMessage("Output file not set with -outfile options"); info.screenDump(); System.exit(0); } 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 ((value = cl.getOptionValue(INPUT_TOOL)) != null) { param.tool = value.replaceAll("\"", ""); info.readParagraphedMessages("External tool locate at : \n\t" + param.tool + "\nplease ensure that all nodes have such tools in the same path.\nOr it is located in a shared file system.\nOr use a Docker container"); info.screenDump(); } else { help.printScriptPiperHelp(); info.readMessage("External tool path have not been set with parameter -tool"); info.screenDump(); System.exit(0); } if ((value = cl.getOptionValue(TOOL_DEPEND)) != null) { param.toolDepend = value.replaceAll("\"", ""); info.readParagraphedMessages("External tool Dependencies : \n\t" + param.toolDepend + "\n"); info.screenDump(); } else { info.readMessage( "External tool dependencies have not been set, will run with tool build-in Interpreter"); info.screenDump(); } if ((value = cl.getOptionValue(TOOL_PARAM)) != null) { param.toolParam = value.replaceAll("\"", ""); info.readParagraphedMessages("External tool parameter : \n\t" + param.toolParam + "\nThe entire command looks like : \n\t" + param.toolDepend + " " + param.tool + " " + param.toolParam); info.screenDump(); info.readParagraphedMessages("Final external command is : \n\t" + param.toolDepend + " " + param.tool + " " + param.toolParam); info.screenDump(); } else { info.readMessage("External tool parameter have not been set, will run with its default parameter"); info.screenDump(); } // param.bestNas = (param.alignLength * param.readIdentity) / 100; // param.bestKmers = param.alignLength - (param.alignLength - param.bestNas) * 4 - 3; } 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:uni.bielefeld.cmg.sparkhit.util.ParameterForParallelizer.java
public DefaultParam importCommandLine() { /* Assigning Parameter ID to an ascending number */ putParameterID();// w w w . ja v a2 s . co m /* 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.printScriptPiperHelp(); System.exit(0); } if (cl.hasOption(HELP2)) { help.printScriptPiperHelp(); System.exit(0); } if (cl.hasOption(VERSION)) { System.exit(0); } /* Checking all parameters */ String value; if ((value = cl.getOptionValue(PARTITIONS)) != null) { param.partitions = Integer.decode(value); } if ((value = cl.getOptionValue(INPUT_NODES)) != null) { param.inputNodes = Integer.decode(value); } else { help.printScriptPiperHelp(); System.exit(0); // throw new IOException("Input 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_LINE)) != null) { param.outputPath = value; } else { help.printScriptPiperHelp(); info.readMessage("Output file not set with -outfile options"); info.screenDump(); System.exit(0); } 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 ((value = cl.getOptionValue(INPUT_TOOL)) != null) { param.tool = value.replaceAll("\"", ""); info.readParagraphedMessages("External tool locate at : \n\t" + param.tool + "\nplease ensure that all nodes have such tools in the same path.\nOr it is located in a shared file system.\nOr use a Docker container"); info.screenDump(); } else { help.printScriptPiperHelp(); info.readMessage("External tool path have not been set with parameter -tool"); info.screenDump(); System.exit(0); } if ((value = cl.getOptionValue(TOOL_DEPEND)) != null) { param.toolDepend = value.replaceAll("\"", ""); info.readParagraphedMessages("External tool Dependencies : \n\t" + param.toolDepend + "\n"); info.screenDump(); } else { info.readMessage( "External tool dependencies have not been set, will run with tool build-in Interpreter"); info.screenDump(); } if ((value = cl.getOptionValue(TOOL_PARAM)) != null) { param.toolParam = value.replaceAll("\"", ""); info.readParagraphedMessages("External tool parameter : \n\t" + param.toolParam + "\nThe entire command looks like : \n\t" + param.toolDepend + " " + param.tool + " " + param.toolParam); info.screenDump(); info.readParagraphedMessages("Final external command is : \n\t" + param.toolDepend + " " + param.tool + " " + param.toolParam); info.screenDump(); } else { info.readMessage("External tool parameter have not been set, will run with its default parameter"); info.screenDump(); } // param.bestNas = (param.alignLength * param.readIdentity) / 100; // param.bestKmers = param.alignLength - (param.alignLength - param.bestNas) * 4 - 3; } 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:ispyb.client.common.shipping.UploadShipmentAction.java
/** * displayAfterDewarTracking/*from w w w . j a v a 2s .com*/ * * @param mapping * @param actForm * @param request * @param in_reponse * @return */ public ActionForward displayAfterDewarTracking(ActionMapping mapping, ActionForm actForm, HttpServletRequest request, HttpServletResponse in_reponse) { // Retrieve Attributes UploadForm form = (UploadForm) actForm; // Populate Template for Shipment Integer shippingId = Integer.decode(request.getParameter(Constants.SHIPPING_ID)); // DLS #### if (!Constants.SITE_IS_DLS()) { String populatedTemplatePath = PopulateTemplate(request, false, false, false, null, null, false, 0, true, shippingId); form.setPopulatedForShipmentTemplageURL(populatedTemplatePath); } form.setCurrentShippingId(shippingId.intValue()); try { Shipping3VO selectedShipping = DBTools.getSelectedShipping(shippingId); BreadCrumbsForm.getIt(request).setSelectedShipping(selectedShipping); } catch (Exception e) { e.printStackTrace(); } return this.display(mapping, form, request, in_reponse); }
From source file:uni.bielefeld.cmg.sparkhit.util.ParameterForDecompresser.java
public DefaultParam importCommandLine() { /* Assigning Parameter ID to an ascending number */ putParameterID();/*from w w w. j a va 2 s . c o m*/ /* 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.printDecompresserHelp(); System.exit(0); } if (cl.hasOption(HELP2)) { help.printDecompresserHelp(); System.exit(0); } if (cl.hasOption(VERSION)) { System.exit(0); } /* Checking all parameters */ String value; if ((value = cl.getOptionValue(PARTITIONS)) != null) { param.partitions = Integer.decode(value); } 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.printDecompresserHelp(); System.exit(0); // throw new IOException("Input 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_LINE)) != null) { param.outputPath = value; } else { help.printDecompresserHelp(); info.readMessage("Output file not set with -outfile options"); info.screenDump(); System.exit(0); } 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 (cl.hasOption(FASTQ_FILTER)) { param.filterFastq = true; } if (cl.hasOption(FASTA_CONVERT)) { param.filterToFasta = true; } if (cl.hasOption(LINE_FASTA)) { param.lineToFasta = true; } // param.bestNas = (param.alignLength * param.readIdentity) / 100; // param.bestKmers = param.alignLength - (param.alignLength - param.bestNas) * 4 - 3; } 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.wandisco.s3hdfs.rewrite.redirect.MetadataFileRedirect.java
/** * Sends a GET command to read a metadata file inside of HDFS. * It uses the URL from the original request to do so. * It will then consume the 307 response and read from the DataNode as well. * * @throws IOException/* w ww . ja v a2 s . co m*/ * @throws ServletException */ public Properties sendRead(String nnHostAddress, String userName) throws IOException, ServletException { // Set up HttpGet and get response String[] nnHost = nnHostAddress.split(":"); String metapath = replaceUri(request.getRequestURI(), OBJECT_FILE_NAME, META_FILE_NAME); GetMethod httpGet = (GetMethod) getHttpMethod(request.getScheme(), nnHost[0], Integer.decode(nnHost[1]), "OPEN", userName, metapath, GET); // Try up to 5 times to get the metadata httpClient.executeMethod(httpGet); LOG.debug("1st response: " + httpGet.getStatusLine().toString()); for (int i = 0; i < 5 && httpGet.getStatusCode() == 403; i++) { httpGet.releaseConnection(); httpClient.executeMethod(httpGet); LOG.debug("Next response: " + httpGet.getStatusLine().toString()); } assert httpGet.getStatusCode() == 200; // Read metadata map InputStream is = httpGet.getResponseBodyAsStream(); Properties metadata = new Properties(); metadata.load(is); // Consume response remainder to re-allocate connection and return map httpGet.releaseConnection(); return metadata; }
From source file:com.csipsimple.models.RemoteLibInfo.java
/** * Test whether this lib is more up to date than an other version of the lib * @param oldLibVersion the other version to compare to * @return true if our lib is more up to date *//*from w w w . j a v a 2 s.co m*/ public boolean isMoreUpToDateThan(String oldLibVersion) { if (oldLibVersion.equalsIgnoreCase("0.01-00")) { //FORCE SINCE WE MADE A PRIMARY BAD COMMIT return true; } //Speed up things if version is the same if (version.equalsIgnoreCase(oldLibVersion)) { return false; } //Else do a real comparaison parsing versions String[] split_master_old = oldLibVersion.split("\\."); String[] split_master = version.split("\\."); try { Log.d(THIS_FILE, "We have " + split_master_old.length); int int_master_old = Integer.decode(split_master_old[0]); int int_master = Integer.decode(split_master[0]); if (int_master > int_master_old) { return true; } if (int_master < int_master_old) { return false; } String[] split_build_old = split_master_old[1].split("-"); String[] split_build = split_master[1].split("-"); int int_vers_old = Integer.decode(split_build_old[0]); int int_vers = Integer.decode(split_build[0]); if (int_vers > int_vers_old) { return true; } if (int_vers < int_vers_old) { return false; } int int_build_old = Integer.decode(split_build_old[1]); int int_build = Integer.decode(split_build[1]); if (int_build > int_build_old) { return true; } if (int_build < int_build_old) { return false; } } catch (NumberFormatException e) { return true; } catch (Exception e) { Log.w(THIS_FILE, "Error while trying to decode versions", e); return true; } return false; }
From source file:org.soaplab.clients.ServiceLocator.java
/************************************************************************** * * @throws IllegalArgumentException if the 'newPort' is * not null but cannot be converted into an integer *************************************************************************/ public final void setPort(final String newPort) { if (StringUtils.isNotEmpty(newPort)) { try {/*from w w w . ja va 2 s . c o m*/ Integer.decode(newPort); } catch (NumberFormatException e) { throw new IllegalArgumentException( "A non-numeric port passed to a ServiceLocator: '" + newPort + "'"); } } this.port = newPort; }