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

The following examples show how to use java.util.Scanner#skip() . 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: HeapHistogramImpl.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
HeapHistogramImpl(String histogramText) {
    Map<String,ClassInfoImpl> classesMap = new HashMap(1024);
    Map<String,ClassInfoImpl> permGenMap = new HashMap(1024);
    time = new Date();
    Scanner sc = new Scanner(histogramText);
    sc.useRadix(10);
    while(!sc.hasNext("-+")) {
        sc.nextLine();
    }
    sc.skip("-+");
    sc.nextLine();


    while(sc.hasNext("[0-9]+:")) {  // NOI18N
        ClassInfoImpl newClInfo = new ClassInfoImpl(sc);
        storeClassInfo(newClInfo, classesMap);
        totalHeapBytes += newClInfo.getBytes();
        totalHeapInstances += newClInfo.getInstancesCount();
    }
    sc.next("Total");   // NOI18N
    totalInstances = sc.nextLong();
    totalBytes = sc.nextLong();
    classes = new HashSet(classesMap.values());
}
 
Example 2
Source File: JRockitHeapHistogramImpl.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
JRockitHeapHistogramImpl(InputStream in) {
    Map<String,ClassInfoImpl> classesMap = new HashMap(1024);
    time = new Date();
    Scanner sc = new Scanner(in, "UTF-8");  // NOI18N
    sc.useRadix(10);
    sc.nextLine();
    sc.skip("-+");
    sc.nextLine();

    while(sc.hasNext("[0-9]+\\.[0-9]%")) {  // NOI18N
        JRockitClassInfoImpl newClInfo = new JRockitClassInfoImpl(sc);
        storeClassInfo(newClInfo, classesMap);
        totalHeapBytes += newClInfo.getBytes();
        totalHeapInstances += newClInfo.getInstancesCount();                
    }
    totalInstances = totalHeapInstances;
    totalBytes = totalHeapBytes;
    classes = new HashSet(classesMap.values());
    permGenClasses = Collections.EMPTY_SET;
}
 
Example 3
Source File: StompMessage.java    From StompProtocolAndroid with MIT License 6 votes vote down vote up
public static StompMessage from(@Nullable String data) {
    if (data == null || data.trim().isEmpty()) {
        return new StompMessage(StompCommand.UNKNOWN, null, data);
    }
    Scanner reader = new Scanner(new StringReader(data));
    reader.useDelimiter("\\n");
    String command = reader.next();
    List<StompHeader> headers = new ArrayList<>();

    while (reader.hasNext(PATTERN_HEADER)) {
        Matcher matcher = PATTERN_HEADER.matcher(reader.next());
        matcher.find();
        headers.add(new StompHeader(matcher.group(1), matcher.group(2)));
    }

    reader.skip("\n\n");

    reader.useDelimiter(TERMINATE_MESSAGE_SYMBOL);
    String payload = reader.hasNext() ? reader.next() : null;

    return new StompMessage(command, headers, payload);
}
 
Example 4
Source File: HeapHistogramImpl.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
HeapHistogramImpl(InputStream in) {
    Map<String,ClassInfoImpl> classesMap = new HashMap(1024);
    Map<String,ClassInfoImpl> permGenMap = new HashMap(1024);
    time = new Date();
    Scanner sc = new Scanner(in, "UTF-8");  // NOI18N
    sc.useRadix(10);
    while(!sc.hasNext("-+")) {
        sc.nextLine();
    }
    sc.skip("-+");
    sc.nextLine();

    
    while(sc.hasNext("[0-9]+:")) {  // NOI18N
        ClassInfoImpl newClInfo = new ClassInfoImpl(sc);
        if (newClInfo.isPermGen()) {
            storeClassInfo(newClInfo, permGenMap);
            totalPermGenBytes += newClInfo.getBytes();
            totalPermgenInstances += newClInfo.getInstancesCount();
        } else {
            storeClassInfo(newClInfo, classesMap);
            totalHeapBytes += newClInfo.getBytes();
            totalHeapInstances += newClInfo.getInstancesCount();                
        }
    }
    sc.next("Total");   // NOI18N
    totalInstances = sc.nextLong();
    totalBytes = sc.nextLong();
    classes = new HashSet(classesMap.values());
    permGenClasses = new HashSet(permGenMap.values());
}
 
Example 5
Source File: HeapHistogram.java    From javamelody with Apache License 2.0 5 votes vote down vote up
private void skipHeader(Scanner sc, boolean jrockit) {
	final String nextLine = sc.nextLine();
	// avant jdk 9, il y a une ligne blanche puis le header, mais en jdk 9 il y a juste le header
	if (nextLine.isEmpty()) {
		sc.nextLine();
	}
	if (!jrockit) {
		sc.skip("-+");
		sc.nextLine();
	}
}
 
Example 6
Source File: JavaScannerUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenSkipPatternUsingScanner_thenSkiped() throws IOException {
    final FileInputStream inputStream = new FileInputStream("src/test/resources/test_read.in");
    final Scanner scanner = new Scanner(inputStream);

    scanner.skip(".e.lo");

    assertEquals("world", scanner.next());

    scanner.close();
}
 
Example 7
Source File: DateFormat.java    From jphp with Apache License 2.0 5 votes vote down vote up
private void skip(Scanner scanner, String pattern) {
    try {
        scanner.skip(pattern);
    } catch (NoSuchElementException e) {
        DateTimeMessageContainer.addError("Data missing", position(date, scanner));
        throw e;
    }
}
 
Example 8
Source File: ProcessInformations.java    From javamelody with Apache License 2.0 4 votes vote down vote up
private ProcessInformations(Scanner sc, boolean windows, boolean macOrAix) {
	super();
	if (windows) {
		final StringBuilder imageNameBuilder = new StringBuilder(sc.next());
		while (!sc.hasNextInt()) {
			imageNameBuilder.append(' ').append(sc.next());
		}
		pid = sc.nextInt();
		if ("Console".equals(sc.next())) {
			// ce if est nécessaire si windows server 2003 mais sans connexion à distance ouverte
			// (comme tasklist.txt dans resources de test,
			// car parfois "Console" est présent mais parfois non)
			sc.next();
		}
		final String memory = sc.next();
		cpuPercentage = -1;
		memPercentage = -1;
		vsz = Integer.parseInt(memory.replace(".", "").replace(",", "").replace("ÿ", ""));
		rss = -1;
		tty = null;
		sc.next();
		sc.skip(WINDOWS_STATE_PATTERN);
		stat = null;
		final StringBuilder userBuilder = new StringBuilder(sc.next());
		while (!sc.hasNext(WINDOWS_CPU_TIME_PATTERN)) {
			userBuilder.append(' ').append(sc.next());
		}
		this.user = userBuilder.toString();
		start = null;
		cpuTime = sc.next();
		command = imageNameBuilder.append("   (").append(sc.nextLine().trim()).append(')')
				.toString();
	} else {
		user = sc.next();
		pid = sc.nextInt();
		cpuPercentage = Float.parseFloat(sc.next().replace(",", "."));
		memPercentage = Float.parseFloat(sc.next().replace(",", "."));
		vsz = sc.nextInt();
		rss = sc.nextInt();
		tty = sc.next();
		stat = sc.next();
		if (macOrAix && sc.hasNextInt()) {
			start = sc.next() + ' ' + sc.next();
		} else {
			start = sc.next();
		}
		cpuTime = sc.next();
		command = sc.nextLine();
	}
}