java.util.Scanner#skip ( )源码实例Demo

下面列出了java.util.Scanner#skip ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: visualvm   文件: HeapHistogramImpl.java
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());
}
 
源代码2 项目: visualvm   文件: JRockitHeapHistogramImpl.java
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;
}
 
源代码3 项目: StompProtocolAndroid   文件: StompMessage.java
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);
}
 
源代码4 项目: visualvm   文件: HeapHistogramImpl.java
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());
}
 
源代码5 项目: javamelody   文件: HeapHistogram.java
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();
	}
}
 
源代码6 项目: tutorials   文件: JavaScannerUnitTest.java
@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();
}
 
源代码7 项目: jphp   文件: DateFormat.java
private void skip(Scanner scanner, String pattern) {
    try {
        scanner.skip(pattern);
    } catch (NoSuchElementException e) {
        DateTimeMessageContainer.addError("Data missing", position(date, scanner));
        throw e;
    }
}
 
源代码8 项目: javamelody   文件: ProcessInformations.java
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();
	}
}