List of usage examples for java.util Scanner next
public String next()
From source file:com.evolveum.midpoint.task.quartzimpl.work.segmentation.StringWorkSegmentationStrategy.java
private String expand(String s) { StringBuilder sb = new StringBuilder(); Scanner scanner = new Scanner(s); while (scanner.hasNext()) { if (scanner.isDash()) { if (sb.length() == 0) { throw new IllegalArgumentException("Boundary specification cannot start with '-': " + s); } else { scanner.next(); if (!scanner.hasNext()) { throw new IllegalArgumentException("Boundary specification cannot end with '-': " + s); } else { appendFromTo(sb, sb.charAt(sb.length() - 1), scanner.next()); }//from w ww . ja v a2 s . co m } } else { sb.append(scanner.next()); } } String expanded = sb.toString(); if (marking == INTERVAL) { checkBoundary(expanded); } return expanded; }
From source file:org.collectionspace.chain.csp.schema.Record.java
private static String getURLTail(String url) { String result = null;// w ww .j a v a 2s. c om Scanner scanner = null; try { scanner = new Scanner(url).useDelimiter("\\/+"); while (scanner.hasNext() == true) { result = scanner.next(); } } catch (Exception e) { // Ignore the exception or logger.trace(e); } finally { scanner.close(); } return result; }
From source file:com.rapid.server.RapidServletContextListener.java
public static int loadActions(ServletContext servletContext) throws Exception { // assume no actions int actionCount = 0; // create a list of json actions which we will sort later List<JSONObject> jsonActions = new ArrayList<JSONObject>(); // retain our class constructors in a hashtable - this speeds up initialisation HashMap<String, Constructor> actionConstructors = new HashMap<String, Constructor>(); // build a collection of classes so we can re-initilise the JAXB context to recognise our injectable classes ArrayList<Action> actions = new ArrayList<Action>(); // get the directory in which the control xml files are stored File dir = new File(servletContext.getRealPath("/WEB-INF/actions/")); // create a filter for finding .control.xml files FilenameFilter xmlFilenameFilter = new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".action.xml"); }//from w w w .j a v a 2s. c om }; // create a schema object for the xsd Schema schema = _schemaFactory .newSchema(new File(servletContext.getRealPath("/WEB-INF/schemas/") + "/action.xsd")); // create a validator Validator validator = schema.newValidator(); // loop the xml files in the folder for (File xmlFile : dir.listFiles(xmlFilenameFilter)) { // get a scanner to read the file Scanner fileScanner = new Scanner(xmlFile).useDelimiter("\\A"); // read the xml into a string String xml = fileScanner.next(); // close the scanner (and file) fileScanner.close(); // validate the control xml file against the schema validator.validate(new StreamSource(new ByteArrayInputStream(xml.getBytes("UTF-8")))); // convert the string into JSON JSONObject jsonActionCollection = org.json.XML.toJSONObject(xml).getJSONObject("actions"); JSONObject jsonAction; int index = 0; int count = 0; // the JSON library will add a single key of there is a single class, otherwise an array if (jsonActionCollection.optJSONArray("action") == null) { jsonAction = jsonActionCollection.getJSONObject("action"); } else { jsonAction = jsonActionCollection.getJSONArray("action").getJSONObject(index); count = jsonActionCollection.getJSONArray("action").length(); } do { // check this type does not already exist for (int i = 0; i < jsonActions.size(); i++) { if (jsonAction.getString("type").equals(jsonActions.get(i).getString("type"))) throw new Exception(" action type is loaded already. Type names must be unique"); } // add the jsonControl to our array jsonActions.add(jsonAction); // get the named type from the json String type = jsonAction.getString("type"); // get the class name from the json String className = jsonAction.getString("class"); // get the class Class classClass = Class.forName(className); // check the class extends com.rapid.Action if (!Classes.extendsClass(classClass, com.rapid.core.Action.class)) throw new Exception(type + " action class " + classClass.getCanonicalName() + " must extend com.rapid.core.Action."); // check this type is unique if (actionConstructors.get(type) != null) throw new Exception(type + " action already loaded. Type names must be unique."); // add to constructors hashmap referenced by type actionConstructors.put(type, classClass.getConstructor(RapidHttpServlet.class, JSONObject.class)); // add to our jaxb classes collection _jaxbClasses.add(classClass); // inc the control count actionCount++; // inc the count of controls in this file index++; // get the next one if (index < count) jsonAction = jsonActionCollection.getJSONArray("control").getJSONObject(index); } while (index < count); } // sort the list of actions by name Collections.sort(jsonActions, new Comparator<JSONObject>() { @Override public int compare(JSONObject c1, JSONObject c2) { try { return Comparators.AsciiCompare(c1.getString("name"), c2.getString("name"), false); } catch (JSONException e) { return 0; } } }); // create a JSON Array object which will hold json for all of the available controls JSONArray jsonArrayActions = new JSONArray(jsonActions); // put the jsonControls in a context attribute (this is available via the getJsonActions method in RapidHttpServlet) servletContext.setAttribute("jsonActions", jsonArrayActions); // put the constructors hashmapin a context attribute (this is available via the getContructor method in RapidHttpServlet) servletContext.setAttribute("actionConstructors", actionConstructors); _logger.info(actionCount + " actions loaded in .action.xml files"); return actionCount; }
From source file:edu.harvard.iq.dataverse.dataaccess.TabularSubsetGenerator.java
public static Long[] subsetLongVector(InputStream in, int column, int numCases) { Long[] retVector = new Long[numCases]; Scanner scanner = new Scanner(in); scanner.useDelimiter("\\n"); for (int caseIndex = 0; caseIndex < numCases; caseIndex++) { if (scanner.hasNext()) { String[] line = (scanner.next()).split("\t", -1); try { retVector[caseIndex] = new Long(line[column]); } catch (NumberFormatException ex) { retVector[caseIndex] = null; // assume missing value }// w w w .ja v a 2s . co m } else { scanner.close(); throw new RuntimeException("Tab file has fewer rows than the stored number of cases!"); } } int tailIndex = numCases; while (scanner.hasNext()) { String nextLine = scanner.next(); if (!"".equals(nextLine)) { scanner.close(); throw new RuntimeException( "Column " + column + ": tab file has more nonempty rows than the stored number of cases (" + numCases + ")! current index: " + tailIndex + ", line: " + nextLine); } tailIndex++; } scanner.close(); return retVector; }
From source file:org.orekit.files.ccsds.OEMParser.java
/** * Parse an ephemeris data line and add its content to the ephemerides * block.//from w w w .j a va 2 s . c o m * * @param reader the reader * @param pi the parser info * @exception IOException if an error occurs while reading from the stream * @exception OrekitException if a date cannot be parsed */ private void parseEphemeridesDataLines(final BufferedReader reader, final ParseInfo pi) throws OrekitException, IOException { for (String line = reader.readLine(); line != null; line = reader.readLine()) { ++pi.lineNumber; if (line.trim().length() > 0) { pi.keyValue = new KeyValue(line, pi.lineNumber, pi.fileName); if (pi.keyValue.getKeyword() == null) { Scanner sc = null; try { sc = new Scanner(line); final AbsoluteDate date = parseDate(sc.next(), pi.lastEphemeridesBlock.getMetaData().getTimeSystem()); final Vector3D position = new Vector3D(Double.parseDouble(sc.next()) * 1000, Double.parseDouble(sc.next()) * 1000, Double.parseDouble(sc.next()) * 1000); final Vector3D velocity = new Vector3D(Double.parseDouble(sc.next()) * 1000, Double.parseDouble(sc.next()) * 1000, Double.parseDouble(sc.next()) * 1000); final CartesianOrbit orbit = new CartesianOrbit(new PVCoordinates(position, velocity), pi.lastEphemeridesBlock.getMetaData().getFrame(), date, pi.file.getMuUsed()); Vector3D acceleration = null; if (sc.hasNext()) { acceleration = new Vector3D(Double.parseDouble(sc.next()) * 1000, Double.parseDouble(sc.next()) * 1000, Double.parseDouble(sc.next()) * 1000); } final OEMFile.EphemeridesDataLine epDataLine = new OEMFile.EphemeridesDataLine(orbit, acceleration); pi.lastEphemeridesBlock.getEphemeridesDataLines().add(epDataLine); } catch (NumberFormatException nfe) { throw new OrekitException(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, pi.lineNumber, pi.fileName, line); } finally { if (sc != null) { sc.close(); } } } else { switch (pi.keyValue.getKeyword()) { case META_START: pi.lastEphemeridesBlock.setEphemeridesDataLinesComment(pi.commentTmp); pi.commentTmp.clear(); pi.lineNumber--; reader.reset(); return; case COVARIANCE_START: pi.lastEphemeridesBlock.setEphemeridesDataLinesComment(pi.commentTmp); pi.commentTmp.clear(); pi.lineNumber--; reader.reset(); return; case COMMENT: pi.commentTmp.add(pi.keyValue.getValue()); break; default: throw new OrekitException(OrekitMessages.CCSDS_UNEXPECTED_KEYWORD, pi.lineNumber, pi.fileName, line); } } } reader.mark(300); } }
From source file:org.wso2.charon3.core.config.SCIMUserSchemaExtensionBuilder.java
private void readConfiguration(String configFilePath) throws CharonException { File provisioningConfig = new File(configFilePath); try {/*from w w w . j a va2 s .c om*/ InputStream inputStream = new FileInputStream(provisioningConfig); //Scanner scanner = new Scanner(new FileInputStream(provisioningConfig)); Scanner scanner = new Scanner(inputStream, "utf-8").useDelimiter("\\A"); String jsonString = scanner.hasNext() ? scanner.next() : ""; JSONArray attributeConfigArray = new JSONArray(jsonString); for (int index = 0; index < attributeConfigArray.length(); ++index) { JSONObject attributeConfig = attributeConfigArray.getJSONObject(index); ExtensionAttributeSchemaConfig attrubteConfig = new ExtensionAttributeSchemaConfig(attributeConfig); extensionConfig.put(attrubteConfig.getName(), attrubteConfig); /** * NOTE: Assume last config is the root config */ if (index == attributeConfigArray.length() - 1) { extensionRootAttributeName = attrubteConfig.getName(); } } inputStream.close(); } catch (FileNotFoundException e) { throw new CharonException(SCIMConfigConstants.SCIM_SCHEMA_EXTENSION_CONFIG + " file not found!", e); } catch (JSONException e) { throw new CharonException( "Error while parsing " + SCIMConfigConstants.SCIM_SCHEMA_EXTENSION_CONFIG + " file!", e); } catch (IOException e) { throw new CharonException( "Error while closing " + SCIMConfigConstants.SCIM_SCHEMA_EXTENSION_CONFIG + " file!", e); } }
From source file:eremeykin.pete.plotter.PlotterTopComponent.java
public void update(File home) { // for first rpt file if (model == null) { clear();//w ww. ja va2 s .c o m return; } File[] rptFiles = home.listFiles(filter()); // catch if there is no such file if (rptFiles.length == 0) { clear(); return; } File firstRPT = rptFiles[0]; Scanner scanner; try { scanner = new Scanner(firstRPT); scanner.useDelimiter("\\s+|\n"); } catch (FileNotFoundException ex) { clear(); return; } List<Map.Entry<Double, Double>> tmpList = new ArrayList<>(); for (int i = 0; scanner.hasNext(); i++) { String line = scanner.next(); try { double x1 = Double.valueOf(line); line = scanner.next(); double x2 = Double.valueOf(line); // System.out.println("x1=" + x1 + "\nx2=" + x2); tmpList.add(new AbstractMap.SimpleEntry<>(x1, x2)); } catch (NumberFormatException ex) { // only if it is the third or following line if (i > 1) { LOGGER.error("Error while parsing double from file: " + firstRPT.getAbsolutePath()); JOptionPane.showMessageDialog(this, "Error while parsing result file.", "Parsing error", JOptionPane.ERROR_MESSAGE); } } } if (tmpList.isEmpty()) { clear(); return; } fillData(tmpList, dataSeries, toleranceSeries); }
From source file:edu.harvard.iq.dataverse.dataaccess.TabularSubsetGenerator.java
public static Double[][] subsetDoubleVectors(InputStream in, Set<Integer> columns, int numCases) throws IOException { Double[][] retVector = new Double[columns.size()][numCases]; Scanner scanner = new Scanner(in); scanner.useDelimiter("\\n"); for (int caseIndex = 0; caseIndex < numCases; caseIndex++) { if (scanner.hasNext()) { String[] line = (scanner.next()).split("\t", -1); int j = 0; for (Integer i : columns) { try { // TODO: verify that NaN and +-Inf are going to be // handled correctly here! -- L.A. // NO, "+-Inf" is not handled correctly; see the // comment further down below. retVector[j][caseIndex] = new Double(line[i]); } catch (NumberFormatException ex) { retVector[j][caseIndex] = null; // missing value }/*from w w w. j a v a2s . c o m*/ j++; } } else { scanner.close(); throw new IOException("Tab file has fewer rows than the stored number of cases!"); } } int tailIndex = numCases; while (scanner.hasNext()) { String nextLine = scanner.next(); if (!"".equals(nextLine)) { scanner.close(); throw new IOException("Tab file has more nonempty rows than the stored number of cases (" + numCases + ")! current index: " + tailIndex + ", line: " + nextLine); } tailIndex++; } scanner.close(); return retVector; }
From source file:jvm.ncatz.netbour.ActivityAbout.java
@NonNull @Override/*from w w w .jav a 2s.c om*/ protected MaterialAboutList getMaterialAboutList(@NonNull Context context) { count = 0; MaterialAboutCard.Builder builderCardApp = new MaterialAboutCard.Builder(); builderCardApp.title(R.string.aboutApp); MaterialAboutCard.Builder builderCardAuthor = new MaterialAboutCard.Builder(); builderCardAuthor.title(R.string.aboutAuthor); MaterialAboutCard.Builder builderCardSocial = new MaterialAboutCard.Builder(); builderCardSocial.title(R.string.aboutSocial); MaterialAboutCard.Builder builderCardOther = new MaterialAboutCard.Builder(); builderCardOther.title(R.string.aboutOther); IconicsDrawable iconAppVersion = new IconicsDrawable(this).icon(MaterialDesignIconic.Icon.gmi_info_outline) .color(ContextCompat.getColor(this, R.color.grey_800)).sizeDp(20); IconicsDrawable iconAppRepository = new IconicsDrawable(this).icon(MaterialDesignIconic.Icon.gmi_github_box) .color(ContextCompat.getColor(this, R.color.grey_800)).sizeDp(20); IconicsDrawable iconAppLicenses = new IconicsDrawable(this).icon(MaterialDesignIconic.Icon.gmi_file) .color(ContextCompat.getColor(this, R.color.grey_800)).sizeDp(20); IconicsDrawable iconAuthorEmail = new IconicsDrawable(this).icon(MaterialDesignIconic.Icon.gmi_email) .color(ContextCompat.getColor(this, R.color.grey_800)).sizeDp(20); IconicsDrawable iconAuthorWeb = new IconicsDrawable(this).icon(MaterialDesignIconic.Icon.gmi_view_web) .color(ContextCompat.getColor(this, R.color.grey_800)).sizeDp(20); IconicsDrawable iconSocialGithub = new IconicsDrawable(this).icon(MaterialDesignIconic.Icon.gmi_github_alt) .color(ContextCompat.getColor(this, R.color.grey_800)).sizeDp(20); IconicsDrawable iconSocialLinkedin = new IconicsDrawable(this).icon(MaterialDesignIconic.Icon.gmi_linkedin) .color(ContextCompat.getColor(this, R.color.grey_800)).sizeDp(20); IconicsDrawable iconSocialStack = new IconicsDrawable(this) .icon(MaterialDesignIconic.Icon.gmi_stackoverflow) .color(ContextCompat.getColor(this, R.color.grey_800)).sizeDp(20); IconicsDrawable iconSocialTwitter = new IconicsDrawable(this).icon(MaterialDesignIconic.Icon.gmi_twitter) .color(ContextCompat.getColor(this, R.color.grey_800)).sizeDp(20); IconicsDrawable iconOtherBugs = new IconicsDrawable(this).icon(MaterialDesignIconic.Icon.gmi_bug) .color(ContextCompat.getColor(this, R.color.grey_800)).sizeDp(20); MaterialAboutTitleItem itemAppName = new MaterialAboutTitleItem(getString(R.string.app_name), ContextCompat.getDrawable(this, R.drawable.logo160)); MaterialAboutActionItem itemAppVersion = new MaterialAboutActionItem(getString(R.string.app_version_title), getString(R.string.app_version_sub), iconAppVersion, new MaterialAboutItemOnClickListener() { @Override public void onClick(boolean b) { count++; if (count == 7) { try { stopPlaying(); player = MediaPlayer.create(ActivityAbout.this, R.raw.easteregg); player.start(); count = 0; } catch (Exception e) { e.printStackTrace(); } } } }); MaterialAboutActionItem itemAppRepository = new MaterialAboutActionItem( getString(R.string.app_repository_title), getString(R.string.app_repository_sub), iconAppRepository, new MaterialAboutItemOnClickListener() { @Override public void onClick(boolean b) { String url = "https://github.com/JMedinilla/Netbour"; openUrl(url); } }); MaterialAboutActionItem itemAppLicenses = new MaterialAboutActionItem( getString(R.string.app_licenses_title), getString(R.string.app_licenses_sub), iconAppLicenses, new MaterialAboutItemOnClickListener() { @Override public void onClick(boolean b) { DialogPlus dialogPlus = DialogPlus.newDialog(ActivityAbout.this).setGravity(Gravity.BOTTOM) .setContentHolder(new ViewHolder(R.layout.licenses_dialog)).setCancelable(true) .setExpanded(true, 600).create(); View view = dialogPlus.getHolderView(); FButton apacheButton = (FButton) view.findViewById(R.id.apacheButton); FButton mitButton = (FButton) view.findViewById(R.id.mitButton); WebView webView = (WebView) view.findViewById(R.id.licensesWeb); apacheButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { AssetManager am = getAssets(); InputStream is = am.open("apache"); Scanner s = new Scanner(is).useDelimiter("\\A"); String apache = s.hasNext() ? s.next() : ""; AlertDialog.Builder builder = new AlertDialog.Builder(ActivityAbout.this); builder.setTitle(R.string.apache_title); builder.setMessage(apache); builder.create().show(); } catch (IOException e) { e.printStackTrace(); } } }); mitButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { AssetManager am = getAssets(); InputStream is = am.open("mit"); Scanner s = new Scanner(is).useDelimiter("\\A"); String mit = s.hasNext() ? s.next() : ""; AlertDialog.Builder builder = new AlertDialog.Builder(ActivityAbout.this); builder.setTitle(R.string.mit_title); builder.setMessage(mit); builder.create().show(); } catch (IOException e) { e.printStackTrace(); } } }); try { AssetManager am = getAssets(); InputStream is = am.open("licenses.html"); webView.loadData(inputStreamToString(is), "text/html", "UTF-8"); } catch (IOException e) { e.printStackTrace(); } dialogPlus.show(); } }); MaterialAboutTitleItem itemAuthorName = new MaterialAboutTitleItem(getString(R.string.author_name), ContextCompat.getDrawable(this, R.drawable.favicon)); MaterialAboutActionItem itemAuthorEmail = new MaterialAboutActionItem( getString(R.string.author_email_title), getString(R.string.author_email_sub), iconAuthorEmail, new MaterialAboutItemOnClickListener() { @Override public void onClick(boolean b) { sendEmail(getString(R.string.author_email_subject)); } }); MaterialAboutActionItem itemAuthorWeb = new MaterialAboutActionItem(getString(R.string.author_web_title), getString(R.string.author_web_sub), iconAuthorWeb, new MaterialAboutItemOnClickListener() { @Override public void onClick(boolean b) { String url = "https://jvmedinilla.ncatz.com/"; openUrl(url); } }); MaterialAboutActionItem itemSocialGithub = new MaterialAboutActionItem( getString(R.string.social_github_title), getString(R.string.social_github_sub), iconSocialGithub, new MaterialAboutItemOnClickListener() { @Override public void onClick(boolean b) { String url = "https://github.com/JMedinilla"; openUrl(url); } }); MaterialAboutActionItem itemSocialLinkedin = new MaterialAboutActionItem( getString(R.string.social_linkedin_title), getString(R.string.social_linkedin_sub), iconSocialLinkedin, new MaterialAboutItemOnClickListener() { @Override public void onClick(boolean b) { String url = "https://www.linkedin.com/in/javier-medinilla-ag%C3%BCera-951749121/"; openUrl(url); } }); MaterialAboutActionItem itemSocialStackoverflow = new MaterialAboutActionItem( getString(R.string.social_stack_title), getString(R.string.social_stack_sub), iconSocialStack, new MaterialAboutItemOnClickListener() { @Override public void onClick(boolean b) { String url = "http://stackoverflow.com/users/7426526/jmedinilla?tab=profile"; openUrl(url); } }); MaterialAboutActionItem itemSocialTwitter = new MaterialAboutActionItem( getString(R.string.social_twitter_title), getString(R.string.social_twitter_sub), iconSocialTwitter, new MaterialAboutItemOnClickListener() { @Override public void onClick(boolean b) { String url = "https://twitter.com/JMedinillaDev"; openUrl(url); } }); MaterialAboutActionItem itemOtherBugs = new MaterialAboutActionItem(getString(R.string.other_bug_title), getString(R.string.other_bug_sub), iconOtherBugs, new MaterialAboutItemOnClickListener() { @Override public void onClick(boolean b) { sendEmail(getString(R.string.other_bug_subject)); } }); builderCardApp.addItem(itemAppName); builderCardApp.addItem(itemAppVersion); builderCardApp.addItem(itemAppRepository); builderCardApp.addItem(itemAppLicenses); builderCardAuthor.addItem(itemAuthorName); builderCardAuthor.addItem(itemAuthorEmail); builderCardAuthor.addItem(itemAuthorWeb); builderCardSocial.addItem(itemSocialGithub); builderCardSocial.addItem(itemSocialLinkedin); builderCardSocial.addItem(itemSocialStackoverflow); builderCardSocial.addItem(itemSocialTwitter); builderCardOther.addItem(itemOtherBugs); MaterialAboutList.Builder builderList = new MaterialAboutList.Builder(); builderList.addCard(builderCardApp.build()); builderList.addCard(builderCardAuthor.build()); builderList.addCard(builderCardSocial.build()); builderList.addCard(builderCardOther.build()); return builderList.build(); }
From source file:edu.harvard.iq.dataverse.dataaccess.TabularSubsetGenerator.java
public static Float[] subsetFloatVector(InputStream in, int column, int numCases) { Float[] retVector = new Float[numCases]; Scanner scanner = new Scanner(in); scanner.useDelimiter("\\n"); for (int caseIndex = 0; caseIndex < numCases; caseIndex++) { if (scanner.hasNext()) { String[] line = (scanner.next()).split("\t", -1); // Verified: new Float("nan") works correctly, // resulting in Float.NaN; // Float("[+-]Inf") doesn't work however; // (the constructor appears to be expecting it // to be spelled as "Infinity", "-Infinity", etc. if ("inf".equalsIgnoreCase(line[column]) || "+inf".equalsIgnoreCase(line[column])) { retVector[caseIndex] = java.lang.Float.POSITIVE_INFINITY; } else if ("-inf".equalsIgnoreCase(line[column])) { retVector[caseIndex] = java.lang.Float.NEGATIVE_INFINITY; } else if (line[column] == null || line[column].equals("")) { // missing value: retVector[caseIndex] = null; } else { try { retVector[caseIndex] = new Float(line[column]); } catch (NumberFormatException ex) { retVector[caseIndex] = null; // missing value }/*from w ww . ja v a2s . co m*/ } } else { scanner.close(); throw new RuntimeException("Tab file has fewer rows than the stored number of cases!"); } } int tailIndex = numCases; while (scanner.hasNext()) { String nextLine = scanner.next(); if (!"".equals(nextLine)) { scanner.close(); throw new RuntimeException( "Column " + column + ": tab file has more nonempty rows than the stored number of cases (" + numCases + ")! current index: " + tailIndex + ", line: " + nextLine); } tailIndex++; } scanner.close(); return retVector; }