List of usage examples for java.util Scanner useDelimiter
public Scanner useDelimiter(String pattern)
From source file:uk.ac.ebi.bioinvindex.services.browse.BrowseStudyBeanImpl.java
private AssayInfoBean createAssayInfoBean(AssayInfoBean assayInfoBean, String assayRepresentation) { assayRepresentation = assayRepresentation.replace("assay(", "").replace(")", ""); Scanner scanner = new Scanner(assayRepresentation); scanner.useDelimiter("\\|"); if (scanner.hasNext()) { assayInfoBean.setEndPoint(scanner.next()); } else {//from w w w .ja v a 2s. c o m assayInfoBean.setEndPoint(""); } if (scanner.hasNext()) { String token = scanner.next(); try { // check to see if the String can be made into a number. Integer.valueOf(token); assayInfoBean.setCount(token); assayInfoBean.setTechnology(""); } catch (NumberFormatException nfe) { assayInfoBean.setTechnology(token); if (scanner.hasNext()) { assayInfoBean.setCount(scanner.next()); } else { assayInfoBean.setCount("0"); } } } return assayInfoBean; }
From source file:com.twitter.ambrose.hive.AmbroseHiveFinishHook.java
private String getLastCmd() { CliSessionState cliss = (CliSessionState) SessionState.get(); Scanner scanner = null; try {/* w w w . ja va 2s . c o m*/ scanner = new Scanner(new File(cliss.fileName)); } catch (FileNotFoundException e) { LOG.error("Can't find Hive script", e); } if (scanner == null) { return null; } Pattern delim = Pattern.compile(";"); scanner.useDelimiter(delim); String lastLine = null; while (scanner.hasNext()) { String line = StringUtils.trim(scanner.next().replaceAll("\\n|\\r", "")); if (line.length() != 0 && !line.startsWith("--")) { lastLine = line; } } return lastLine; }
From source file:edu.harvard.hul.ois.fits.junit.VideoStdSchemaTestXmlUnit.java
@Test public void testVideoXmlUnitFitsOutput_DV() throws Exception { Fits fits = new Fits(); // First generate the FITS output File input = new File("testfiles/FITS-SAMPLE-26.mov"); FitsOutput fitsOut = fits.examine(input); XMLOutputter serializer = new XMLOutputter(Format.getPrettyFormat()); String actualXmlStr = serializer.outputString(fitsOut.getFitsXml()); // Read in the expected XML file Scanner scan = new Scanner(new File("testfiles/output/FITS-SAMPLE-26_mov_FITS.xml")); String expectedXmlStr = scan.useDelimiter("\\Z").next(); scan.close();/*w w w. ja va2 s .co m*/ // Set up XMLUnit XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalizeWhitespace(true); Diff diff = new Diff(expectedXmlStr, actualXmlStr); // Initialize attributes or elements to ignore for difference checking diff.overrideDifferenceListener(new IgnoreNamedElementsDifferenceListener("version", "toolversion", "dateModified", "fslastmodified", "startDate", "startTime", "timestamp", "fitsExecutionTime", "executionTime", "filepath", "location")); DetailedDiff detailedDiff = new DetailedDiff(diff); // Display any Differences List<Difference> diffs = detailedDiff.getAllDifferences(); if (!diff.identical()) { StringBuffer differenceDescription = new StringBuffer(); differenceDescription.append(diffs.size()).append(" differences"); System.out.println(differenceDescription.toString()); for (Difference difference : diffs) { System.out.println(difference.toString()); } } assertTrue("Differences in XML", diff.identical()); }
From source file:org.geppetto.model.neuroml.services.NeuroMLModelInterpreterService.java
public IModel readModel(URL url, List<URL> recordings, String instancePath) throws ModelInterpreterException { ModelWrapper model = new ModelWrapper(instancePath); try {/*from w w w. j a v a2s . co m*/ Scanner scanner = new Scanner(url.openStream(), "UTF-8"); String neuroMLString = scanner.useDelimiter("\\A").next(); scanner.close(); String lemsString = NeuroMLConverter.convertNeuroML2ToLems(neuroMLString); ILEMSDocumentReader lemsReader = new LEMSDocumentReader(); //ILEMSDocument document = lemsReader.readModel(lemsString); int index = url.toString().lastIndexOf('/'); String urlBase = url.toString().substring(0, index + 1); OptimizedLEMSReader reader = new OptimizedLEMSReader(urlBase); String lemsStringOptimized = reader.processLEMSInclusions(lemsString); lemsStringOptimized = reader.processLEMSInclusions(lemsStringOptimized, false); ILEMSDocument document = lemsReader.readModel(lemsStringOptimized); // NeuroMLConverter neuromlConverter = new NeuroMLConverter(); // NeuroMLDocument neuroml = neuromlConverter.urlToNeuroML(url); NeuroMLConverter neuromlConverter = new NeuroMLConverter(); String neuromlString = URLReader.readStringFromURL(url); NeuroMLDocument neuroml = neuromlConverter.loadNeuroML(neuromlString); String neuromlStringOptimized = reader.processLEMSInclusions(neuromlString, false); neuromlStringOptimized = reader.processLEMSInclusions(neuromlStringOptimized); NeuroMLDocument neuroml_inclusions = neuromlConverter.loadNeuroML(neuromlStringOptimized); model = new ModelWrapper(UUID.randomUUID().toString()); model.setInstancePath(instancePath); // two different interpretations of the same file, one used to simulate the other used to visualize model.wrapModel(NeuroMLAccessUtility.LEMS_ID, document); //model.wrapModel(NeuroMLAccessUtility.LEMS_ID_INCLUSIONS, document_inclusions); model.wrapModel(NeuroMLAccessUtility.NEUROML_ID, neuroml); model.wrapModel(NeuroMLAccessUtility.NEUROML_ID_INCLUSIONS, neuroml_inclusions); model.wrapModel(NeuroMLAccessUtility.URL_ID, url); model.wrapModel(NeuroMLAccessUtility.SUBENTITIES_MAPPING_ID, new HashMap<String, EntityNode>()); model.wrapModel(NeuroMLAccessUtility.DISCOVERED_COMPONENTS, new HashMap<String, Base>()); model.wrapModel(LEMSAccessUtility.DISCOVERED_LEMS_COMPONENTS, new HashMap<String, Object>()); model.wrapModel(NeuroMLAccessUtility.DISCOVERED_NESTED_COMPONENTS_ID, new ArrayList<String>()); } catch (IOException e) { throw new ModelInterpreterException(e); } catch (ContentError e) { throw new ModelInterpreterException(e); } catch (JAXBException e) { throw new ModelInterpreterException(e); } catch (Exception e) { throw new ModelInterpreterException(e); } return model; }
From source file:com.std.Index.java
public void find_historical_data(int month, int day, int year) { try {/*w w w .j a v a 2 s . com*/ String url = "http://real-chart.finance.yahoo.com/table.csv?s=" + this.ticker + "&d=" + month + "&e=" + day + "&f=" + year + "&g=d&a=0&b=1&c=1970&ignore=.csv"; InputStream input; input = new URL(url).openStream(); Scanner s = new Scanner(input); s.useDelimiter("\\A"); String csv = s.hasNext() ? s.next() : ""; s.close(); input.close(); csv = csv.replace("\"", ""); historical_data = new ArrayList<String>(Arrays.asList(csv.split("\n"))); } catch (Exception ex) { System.out.println("Could not retrieve historical data"); System.out.println("Error with connection"); } }
From source file:edu.harvard.hul.ois.fits.junit.VideoStdSchemaTestXmlUnit.java
@Test public void testVideoXmlUnitCombinedOutput_DV() throws Exception { File input = new File("testfiles/FITS-SAMPLE-26.mov"); Fits fits = new Fits(); FitsOutput fitsOut = fits.examine(input); // Output stream for FITS to write to ByteArrayOutputStream out = new ByteArrayOutputStream(); // Create combined output in the stream passed in Fits.outputStandardCombinedFormat(fitsOut, out); // Turn output stream into a String HtmlUnit can use String actualXmlStr = new String(out.toByteArray(), "UTF-8"); // Read in the expected XML file Scanner scan = new Scanner(new File("testfiles/output/FITS-SAMPLE-26_mov_Combined.xml")); String expectedXmlStr = scan.useDelimiter("\\Z").next(); scan.close();// w w w . j a v a2 s. c o m // Set up XMLUnit XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalizeWhitespace(true); Diff diff = new Diff(expectedXmlStr, actualXmlStr); // Initialize attributes or elements to ignore for difference checking diff.overrideDifferenceListener(new IgnoreNamedElementsDifferenceListener("version", "toolversion", "dateModified", "fslastmodified", "startDate", "startTime", "timestamp", "fitsExecutionTime", "executionTime", "filepath", "location", "ebucore:locator")); DetailedDiff detailedDiff = new DetailedDiff(diff); // Display any Differences List<Difference> diffs = detailedDiff.getAllDifferences(); if (!diff.identical()) { StringBuffer differenceDescription = new StringBuffer(); differenceDescription.append(diffs.size()).append(" differences"); System.out.println(differenceDescription.toString()); for (Difference difference : diffs) { System.out.println(difference.toString()); } } assertTrue("Differences in XML", diff.identical()); }
From source file:edu.harvard.hul.ois.fits.junit.VideoStdSchemaTestXmlUnit.java
@Test public void testVideoXmlUnitStandardOutput_DV() throws Exception { // First generate the FITS output File input = new File("testfiles/FITS-SAMPLE-26.mov"); Fits fits = new Fits(); FitsOutput fitsOut = fits.examine(input); // Output stream for FITS to write to ByteArrayOutputStream out = new ByteArrayOutputStream(); // Create standard output in the stream passed in Fits.outputStandardSchemaXml(fitsOut, out); // Turn output stream into a String HtmlUnit can use String actualXmlStr = new String(out.toByteArray(), "UTF-8"); // Read in the expected XML file Scanner scan = new Scanner(new File("testfiles/output/FITS-SAMPLE-26_mov_Standard.xml")); String expectedXmlStr = scan.useDelimiter("\\Z").next(); scan.close();/*from w w w . j a v a 2 s . c o m*/ // Set up XMLUnit XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalizeWhitespace(true); Diff diff = new Diff(expectedXmlStr, actualXmlStr); // Initialize attributes or elements to ignore for difference checking diff.overrideDifferenceListener(new IgnoreNamedElementsDifferenceListener("version", "toolversion", "dateModified", "fslastmodified", "startDate", "startTime", "timestamp", "fitsExecutionTime", "executionTime", // Not in Standard Output //"filepath", //"location", "ebucore:locator")); DetailedDiff detailedDiff = new DetailedDiff(diff); // Display any Differences List<Difference> diffs = detailedDiff.getAllDifferences(); if (!diff.identical()) { StringBuffer differenceDescription = new StringBuffer(); differenceDescription.append(diffs.size()).append(" differences"); System.out.println(differenceDescription.toString()); for (Difference difference : diffs) { System.out.println(difference.toString()); } } assertTrue("Differences in XML", diff.identical()); }
From source file:com.mendhak.gpslogger.common.OpenGTSClient.java
/** * Send locations sing HTTP GET request to the server * <p/>/* ww w .java2 s.c o m*/ * See <a href="http://opengts.sourceforge.net/OpenGTS_Config.pdf">OpenGTS_Config.pdf</a> * section 9.1.2 Default "gprmc" Configuration * * @param id id of the device * @param locations locations */ public void sendHTTP(String id, String accountName, SerializableLocation[] locations) throws Exception { for (SerializableLocation loc : locations) { List<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("id", id)); qparams.add(new BasicNameValuePair("dev", id)); if (!Utilities.IsNullOrEmpty(accountName)) { qparams.add(new BasicNameValuePair("acct", accountName)); } else { qparams.add(new BasicNameValuePair("acct", id)); } //OpenGTS 2.5.5 requires batt param or it throws exception... qparams.add(new BasicNameValuePair("batt", "0")); qparams.add(new BasicNameValuePair("code", "0xF020")); qparams.add(new BasicNameValuePair("alt", String.valueOf(loc.getAltitude()))); qparams.add(new BasicNameValuePair("gprmc", OpenGTSClient.GPRMCEncode(loc))); URI uri = URIUtils.createURI("http", server, port, path, getQuery(qparams), null); HttpGet httpget = new HttpGet(uri); URL url = httpget.getURI().toURL(); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); Scanner s; if (conn.getResponseCode() != 200) { s = new Scanner(conn.getErrorStream()); tracer.error("Status code: " + String.valueOf(conn.getResponseCode())); if (s.hasNext()) { tracer.error(s.useDelimiter("\\A").next()); } } else { tracer.debug("Status code: " + String.valueOf(conn.getResponseCode())); } } }
From source file:edu.harvard.hul.ois.fits.junit.VideoStdSchemaTestXmlUnit.java
@Test public void testVideoXmlUnitFitsOutput_AVC() throws Exception { Fits fits = new Fits(); // First generate the FITS output File input = new File("testfiles/FITS-SAMPLE-44_1_1_4_4_4_6_1_1_2_3_1.mp4"); FitsOutput fitsOut = fits.examine(input); XMLOutputter serializer = new XMLOutputter(Format.getPrettyFormat()); String actualXmlStr = serializer.outputString(fitsOut.getFitsXml()); // Read in the expected XML file Scanner scan = new Scanner(new File("testfiles/output/FITS-SAMPLE-44_1_1_4_4_4_6_1_1_2_3_1_mp4_FITS.xml")); String expectedXmlStr = scan.useDelimiter("\\Z").next(); scan.close();//from w w w. j a va 2 s . co m // Set up XMLUnit XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalizeWhitespace(true); Diff diff = new Diff(expectedXmlStr, actualXmlStr); // Initialize attributes or elements to ignore for difference checking diff.overrideDifferenceListener(new IgnoreNamedElementsDifferenceListener("version", "toolversion", "dateModified", "fslastmodified", "startDate", "startTime", "timestamp", "fitsExecutionTime", "executionTime", "filepath", "location")); DetailedDiff detailedDiff = new DetailedDiff(diff); // Display any Differences List<Difference> diffs = detailedDiff.getAllDifferences(); if (!diff.identical()) { StringBuffer differenceDescription = new StringBuffer(); differenceDescription.append(diffs.size()).append(" differences"); System.out.println(differenceDescription.toString()); for (Difference difference : diffs) { System.out.println(difference.toString()); } } assertTrue("Differences in XML", diff.identical()); }
From source file:Balo.MainFrame.java
public void getDataFileToJTable() { String fileNameDefined = "src/Balo/Data_1.csv"; File file = new File(fileNameDefined); int i = 0;/*from www .j a v a 2 s .c om*/ dvDynamic[0] = new Dovat(); //Get value from csv file try { Scanner inputStream = new Scanner(file); inputStream.useDelimiter(","); while (inputStream.hasNext()) { dvDynamic[i + 1] = dvGreedy[i] = new Dovat(); dvDynamic[i + 1].ten = dvGreedy[i].ten = inputStream.next().trim(); dvDynamic[i + 1].soluong = dvGreedy[i].soluong = Integer.valueOf(inputStream.next().trim()); dvDynamic[i + 1].giatri = dvGreedy[i].giatri = Integer.valueOf(inputStream.next().trim()); dvDynamic[i + 1].trongluong = dvGreedy[i].trongluong = Integer.valueOf(inputStream.next().trim()); i++; } //Set number of Items numOfItem = i; //Get weight bag weightBag = Integer.parseInt(TextW.getText()); inputStream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } //Set value for JTable for (int item = 0; item < numOfItem; item++) { Object[] row = new Object[4]; row[0] = dvGreedy[item].ten; row[1] = dvGreedy[item].soluong; row[2] = dvGreedy[item].giatri; row[3] = dvGreedy[item].trongluong; model.addRow(row); } }