Java Code Examples for java.util.Scanner#findInLine()

The following examples show how to use java.util.Scanner#findInLine() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultFormat.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
protected MethodInfo parseMethodInfo(String line) {

        MethodInfo result = new MethodInfo();
        Scanner s = new Scanner(line);

        s.findInLine(methodInfoPattern());
        MatchResult rexp = s.match();
        if (rexp.group(4) != null && rexp.group(4).length() > 0) {
            // line "  at tmtools.jstack.share.utils.Utils.sleep(Utils.java:29)"
            result.setName(rexp.group(1));
            result.setCompilationUnit(rexp.group(2));
            result.setLine(rexp.group(4));

        } else {
            // line "  at java.lang.Thread.sleep(Native Method)"
            result.setName(rexp.group(1));
        }

        s.close();
        return result;
    }
 
Example 2
Source File: PluginMessagesCLIResult.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
private void parseMessage(){
	
	Scanner scanner = new Scanner(getMessage());
	
	while(scanner.hasNextLine()){
		//check of --variable APP_ID=value is needed
		if( scanner.findInLine("(?:\\s\\-\\-variable\\s(\\w*)=value)") != null ){
			MatchResult mr = scanner.match();
			StringBuilder missingVars = new StringBuilder();
			for(int i = 0; i<mr.groupCount();i++){
				if(i>0){
					missingVars.append(",");
				}
				missingVars.append(mr.group());
			}
			pluginStatus = new HybridMobileStatus(IStatus.ERROR, HybridCore.PLUGIN_ID, CordovaCLIErrors.ERROR_MISSING_PLUGIN_VARIABLE,
					NLS.bind("This plugin requires {0} to be defined",missingVars), null);
		
		}
		scanner.nextLine();
	}
	scanner.close();
	
}
 
Example 3
Source File: FcFontConfiguration.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the OS version string from a Linux release-specific file.
 */
private String getVersionString(File f){
    try {
        Scanner sc  = new Scanner(f);
        return sc.findInLine("(\\d)+((\\.)(\\d)+)*");
    }
    catch (Exception e){
    }
    return null;
}
 
Example 4
Source File: MFontConfiguration.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the OS version string from a Linux release-specific file.
 */
private String getVersionString(File f){
    try {
        Scanner sc  = new Scanner(f);
        return sc.findInLine("(\\d)+((\\.)(\\d)+)*");
    }
    catch (Exception e){
    }
    return null;
}
 
Example 5
Source File: DefaultFormat.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected LockInfo parseLockInfo(String line) {
    LockInfo res = new LockInfo();

    Scanner s = new Scanner(line);
    s.findInLine(ownableSynchronizersPattern());

    MatchResult matchRes = s.match();
    String lock = matchRes.group(1).equals("None") ? matchRes.group(1) : matchRes.group(2);
    res.setLock(lock);

    return res;
}
 
Example 6
Source File: VelocityGeneratorTest.java    From celerio with Apache License 2.0 5 votes vote down vote up
@Test
public void testExtraction() {
    String message = "Object 'com.jaxio.celerio.convention.WellKnownFolder' does not contain property 'resource' at src/main/resources/spring/springmvc-parent.p.vm.xml[line "
            + "28, column 47]";
    Scanner s = new Scanner(message);
    String u = s.findInLine("\\[line (\\d+), column (\\d+)\\]");
    assertThat(u).isNotEmpty();
    MatchResult result = s.match();
    assertThat(result.groupCount()).isEqualTo(2);
    assertThat(result.group(1)).isEqualTo("28");
    assertThat(result.group(2)).isEqualTo("47");
}
 
Example 7
Source File: DefaultFormat.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected String parseJNIGlobalRefs(String line) {
    Scanner s = new Scanner(line);
    s.findInLine(jniGlobalRefInfoPattern());
    String result = s.match().group(1);
    s.close();
    return result;
}
 
Example 8
Source File: MFontConfiguration.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the OS version string from a Linux release-specific file.
 */
private String getVersionString(File f){
    try {
        Scanner sc  = new Scanner(f);
        return sc.findInLine("(\\d)+((\\.)(\\d)+)*");
    }
    catch (Exception e){
    }
    return null;
}
 
Example 9
Source File: MFontConfiguration.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the OS version string from a Linux release-specific file.
 */
private String getVersionString(File f){
    try {
        Scanner sc  = new Scanner(f);
        return sc.findInLine("(\\d)+((\\.)(\\d)+)*");
    }
    catch (Exception e){
    }
    return null;
}
 
Example 10
Source File: Gfsh.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private String expandProperties(final String input) {
  String output = input;
  Scanner s = new Scanner(output);
  String foundInLine = null;
  while ( (foundInLine = s.findInLine("(\\$[\\{]\\w+[\\}])"))  != null) {
    String envProperty = getEnvProperty(extractKey(foundInLine));
    envProperty = envProperty != null ? envProperty : "";
    output = output.replace(foundInLine, envProperty);
  }
  return output;
}
 
Example 11
Source File: ReferenceSequenceFromSeekable.java    From cramtools with Apache License 2.0 5 votes vote down vote up
private static Map<String, FastaSequenceIndexEntry> buildIndex(InputStream is) {
	Scanner scanner = new Scanner(is);

	int sequenceIndex = 0;
	Map<String, FastaSequenceIndexEntry> index = new HashMap<String, FastaSequenceIndexEntry>();
	while (scanner.hasNext()) {
		// Tokenize and validate the index line.
		String result = scanner.findInLine("(.+)\\t+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)");
		if (result == null)
			throw new RuntimeException("Found invalid line in index file:" + scanner.nextLine());
		MatchResult tokens = scanner.match();
		if (tokens.groupCount() != 5)
			throw new RuntimeException("Found invalid line in index file:" + scanner.nextLine());

		// Skip past the line separator
		scanner.nextLine();

		// Parse the index line.
		String contig = tokens.group(1);
		long size = Long.valueOf(tokens.group(2));
		long location = Long.valueOf(tokens.group(3));
		int basesPerLine = Integer.valueOf(tokens.group(4));
		int bytesPerLine = Integer.valueOf(tokens.group(5));

		contig = SAMSequenceRecord.truncateSequenceName(contig);
		// Build sequence structure
		index.put(contig, new FastaSequenceIndexEntry(contig, location, size, basesPerLine, bytesPerLine,
				sequenceIndex++));
	}
	scanner.close();
	return index;
}
 
Example 12
Source File: JGoogleAnalyticsTracker.java    From Hook-Manager with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Define the proxy to use for all GA tracking requests.
 * <p>
 * Call this static method early (before creating any tracking requests).
 *
 * @param proxyAddr
 *            "addr:port" of the proxy to use; may also be given as URL
 *            ("http://addr:port/").
 */
public static void setProxy(String proxyAddr)
{
	if(proxyAddr != null)
	{
		Scanner s = new Scanner(proxyAddr);
		
		// Split into "proxyAddr:proxyPort".
		proxyAddr = null;
		int proxyPort = 8080;
		try
		{
			s.findInLine("(http://|)([^:/]+)(:|)([0-9]*)(/|)");
			MatchResult m = s.match();
			
			if(m.groupCount() >= 2)
				proxyAddr = m.group(2);
			
			if(m.groupCount() >= 4 && !(m.group(4).length() == 0))
				proxyPort = Integer.parseInt(m.group(4));
		}finally
		{
			s.close();
		}
		
		if(proxyAddr != null)
		{
			SocketAddress sa = new InetSocketAddress(proxyAddr, proxyPort);
			setProxy(new Proxy(Type.HTTP, sa));
		}
	}
}
 
Example 13
Source File: MFontConfiguration.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the OS version string from a Linux release-specific file.
 */
private String getVersionString(File f){
    try {
        Scanner sc  = new Scanner(f);
        return sc.findInLine("(\\d)+((\\.)(\\d)+)*");
    }
    catch (Exception e){
    }
    return null;
}
 
Example 14
Source File: FcFontConfiguration.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the OS version string from a Linux release-specific file.
 */
private String getVersionString(File f){
    try {
        Scanner sc  = new Scanner(f);
        return sc.findInLine("(\\d)+((\\.)(\\d)+)*");
    }
    catch (Exception e){
    }
    return null;
}
 
Example 15
Source File: FcFontConfiguration.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the OS version string from a Linux release-specific file.
 */
private String getVersionString(File f){
    try {
        Scanner sc  = new Scanner(f);
        return sc.findInLine("(\\d)+((\\.)(\\d)+)*");
    }
    catch (Exception e){
    }
    return null;
}
 
Example 16
Source File: FcFontConfiguration.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the OS version string from a Linux release-specific file.
 */
private String getVersionString(File f){
    try {
        Scanner sc  = new Scanner(f);
        return sc.findInLine("(\\d)+((\\.)(\\d)+)*");
    }
    catch (Exception e){
    }
    return null;
}
 
Example 17
Source File: LinkFormat.java    From SI with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static Set<WebLink> parse(String linkFormat) {
	Pattern DELIMITER = Pattern.compile("\\s*,+\\s*");

	Set<WebLink> links = new ConcurrentSkipListSet<WebLink>();
	
	if (linkFormat!=null) {
		Scanner scanner = new Scanner(linkFormat);
		String path = null;
		while ((path = scanner.findInLine("<[^>]*>")) != null) {
			
			// Trim <...>
			path = path.substring(1, path.length() - 1);
			
			WebLink link = new WebLink(path);
			
			// Read link format attributes
			String attr = null;
			while (scanner.findWithinHorizon(DELIMITER, 1)==null && (attr = scanner.findInLine(WORD))!=null) {
				if (scanner.findWithinHorizon("=", 1) != null) {
					String value = null;
					if ((value = scanner.findInLine(QUOTED_STRING)) != null) {
						value = value.substring(1, value.length()-1); // trim " "
						if (attr.equals(TITLE)) {
							link.getAttributes().addAttribute(attr, value);
						} else {
							for (String part : value.split("\\s", 0)) {
								link.getAttributes().addAttribute(attr, part);
							}
						}
					} else if ((value = scanner.findInLine(WORD)) != null) {
						link.getAttributes().setAttribute(attr, value);
					} else if ((value = scanner.findInLine(CARDINAL)) != null) {
						link.getAttributes().setAttribute(attr, value);
					} else if (scanner.hasNext()) {
						value = scanner.next();
					}
					
				} else {
					// flag attribute without value
					link.getAttributes().addAttribute(attr);
				}
			}
			
			links.add(link);
		}
		scanner.close();
	}
	return links;
}
 
Example 18
Source File: Utilities.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Parses menu line like IDE Log L ============================ Toolbars > T
 * [x] Show Editor Toolbar h [ ] Show Line Numbers S (x) Show Diff Sidebar D
 *
 * @param lineText
 * @return parsed menu item from line
 */
public static NbMenuItem parseMenuLineText(String lineText) {
    //parse line
    Scanner line = new Scanner(lineText);
    NbMenuItem menuitem = new NbMenuItem();
    if (debug) {
        System.out.println("Parsing line: " + line);
    }
    //is it separator? "======="
    if (line.hasNext("^={5,}+\\s*")) { //at least 5x =

        menuitem.setSeparator(true);
    } else {
        //does the line start with ( ?
        String isRadio = line.findInLine("\\(.\\)");
        if (isRadio != null) {
            //System.out.println("parsing radiobutton: " + isRadio);
            menuitem.setRadiobutton(true);
            menuitem.setChecked(isRadio.indexOf("o") != -1);
        } else {
            //does the line start with [ ?
            String isCheck = line.findInLine("\\[.\\]");
            if (isCheck != null) {
                //System.out.println("parsing checkbox: " + isCheck);
                menuitem.setCheckbox(true);
                menuitem.setChecked(isCheck.indexOf("x") != -1);
            }
        }

        //read menu item text
        StringBuffer text = new StringBuffer();
        boolean read = true;
        while (read && line.hasNext()) {
            String partOfText = line.next();
            if (partOfText.length() == 1 && partOfText.charAt(0) != '/') {
                if (partOfText.charAt(0) == '>') {
                    menuitem.setSubmenu(new ArrayList<NbMenuItem>());
                } else if (partOfText.charAt(0) == '-') {
                    // There is following project name, which has to be
                    // loaded right now. It is dynamicly changing.
                    partOfText = partOfText + " " + projectName;
                    text.append(partOfText);
                    text.append(" ");
                } else {
                    //it must be the mnemonic
                    menuitem.setMnemo(partOfText.charAt(0));
                    read = false;
                }
            } else {
                text.append(partOfText);
                text.append(" ");
            }
        }
        menuitem.setName(text.substring(0, text.length() - 1)); //remove the last " "

    }

    return menuitem;
}
 
Example 19
Source File: LinkFormat.java    From SI with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static Set<WebLink> parse(String linkFormat) {
	Pattern DELIMITER = Pattern.compile("\\s*,+\\s*");

	Set<WebLink> links = new ConcurrentSkipListSet<WebLink>();
	
	if (linkFormat!=null) {
		Scanner scanner = new Scanner(linkFormat);
		String path = null;
		while ((path = scanner.findInLine("<[^>]*>")) != null) {
			
			// Trim <...>
			path = path.substring(1, path.length() - 1);
			
			WebLink link = new WebLink(path);
			
			// Read link format attributes
			String attr = null;
			while (scanner.findWithinHorizon(DELIMITER, 1)==null && (attr = scanner.findInLine(WORD))!=null) {
				if (scanner.findWithinHorizon("=", 1) != null) {
					String value = null;
					if ((value = scanner.findInLine(QUOTED_STRING)) != null) {
						value = value.substring(1, value.length()-1); // trim " "
						if (attr.equals(TITLE)) {
							link.getAttributes().addAttribute(attr, value);
						} else {
							for (String part : value.split("\\s", 0)) {
								link.getAttributes().addAttribute(attr, part);
							}
						}
					} else if ((value = scanner.findInLine(WORD)) != null) {
						link.getAttributes().setAttribute(attr, value);
					} else if ((value = scanner.findInLine(CARDINAL)) != null) {
						link.getAttributes().setAttribute(attr, value);
					} else if (scanner.hasNext()) {
						value = scanner.next();
					}
					
				} else {
					// flag attribute without value
					link.getAttributes().addAttribute(attr);
				}
			}
			
			links.add(link);
		}
		scanner.close();
	}
	return links;
}
 
Example 20
Source File: NetTool.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
public static String getMacAddress() throws IOException{
	Process proc = Runtime.getRuntime().exec("cmd /c ipconfig /all");
	Scanner s = new Scanner(proc.getInputStream());
	return s.findInLine("\\p{XDigit}\\p{XDigit}(-\\p{XDigit}\\p{XDigit}){5}");
}