Java 8 Scanner - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Scanner class.

This code example shows how to use the following methods:close, hasNext, next
    s.close();
  } 
 
  static void readFile() { 
    try { 
      Scanner darkly = new Scanner(new File("./classes/test/ScannerTest.java"));
      System.out.println(darkly.hasNext());
      System.out.println(darkly.next());
      System.out.println(darkly.next());
      System.out.println(darkly.next());
      darkly.close();
    } catch (FileNotFoundException e) {
      System.out.println(e);
    } 
  } 
 
  public static void main(String[] args) {
    readFile(); 
    useDelimiters(); 
    useRegex(); 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:hasNextBigInteger, hasNextBoolean, nextBigInteger, nextBoolean
            stringVal = stringVal.substring(2, stringVal.length() - 2);
        } else if (stringVal.startsWith("(") && stringVal.endsWith(")")) {
            return new DatabaseFunction(stringVal.substring(1, stringVal.length() - 1));
        } 
 
        Scanner scanner = new Scanner(stringVal.trim());
        if (typeId == Types.ARRAY) {
            return new DatabaseFunction(stringVal);
        } else if ((liquibaseDataType instanceof BigIntType || typeId == Types.BIGINT)) {
            if (scanner.hasNextBigInteger()) {
                return scanner.nextBigInteger();
            } else { 
                return new DatabaseFunction(stringVal);
            } 
        } else if (typeId == Types.BINARY) {
            return new DatabaseFunction(stringVal.trim());
        } else if (typeId == Types.BIT) {
            if (stringVal.startsWith("b'")) { //mysql returns boolean values as b'0' and b'1'
                stringVal = stringVal.replaceFirst("b'", "").replaceFirst("'$", "");
            } 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
    public ConsoleThread(Query query) {
        setName("ConsoleTrehad");
        this.query = query;
        parser = new CommandParser(query);
        parser.printHelp();
        scanner = new Scanner(System.in);
    } 
 
 
    public void run() { 
        String command = null;
        while (true) { 
            print(); 
            command = scanner.nextLine();
            int result = parser.prase(command);
            if (result == -1) {
                break; 
            } 
        } 
    } 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:nextLine
    super.load(); 
 
    if (getInt("internalPort") == getInt("port")) { 
      System.out.println("OH NO! Your 'internalPort' and 'port' properties are the same! Edit simpleserver.properties and change them to different values. 'port' is recommended to be 25565, the default port of minecraft, and will be the port you actually connect to.");
      System.out.println("Press enter to continue...");
      Scanner in = new Scanner(System.in);
      in.nextLine();
      System.exit(0);
    } 
  } 
 
  @Override 
  protected String getComment() {
    return "Some of the options which used to be here are now stored in config.xml"; 
  } 
 
  @Override 
  protected void missingFile() { 
    super.missingFile(); 
 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:next, useDelimiter
public class GoogleQuoteFetcherTest extends TestCase {
 
    public void testParseQuotes() throws Exception {
        String samplePath = "src/main/resources/sample_google_response.csv";
 
        Scanner scan = new Scanner(new File(samplePath));
        scan.useDelimiter("\\Z");
        String sampleResponse = scan.next().replaceAll("\r\n", "\n");
 
        GoogleQuoteFetcher fetcher = new GoogleQuoteFetcher();
 
        List<Quote> quotes = fetcher.parseQuotes(sampleResponse, 60);
 
        Quote firstQuote = quotes.get(0);
        assertEquals(firstQuote.getOpen(), new BigDecimal("444.05"));
        assertEquals(firstQuote.getHigh(), new BigDecimal("444.19"));
        assertEquals(firstQuote.getLow(), new BigDecimal("443.8"));
        assertEquals(firstQuote.getClose(), new BigDecimal("443.8"));
        assertEquals(firstQuote.getVolume(), 78179);
        assertEquals(firstQuote.getOpenDate().getMillis(), 1362061800000L);
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:close, nextLine
     
    private YammerAccessCodeGenerator() { 
    } 
     
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
 
        System.out.println("Paste the consumerKey here");
        System.out.print(">>");
        String apiKey = in.nextLine();
 
        System.out.println("Paste the consumerSecret here");
        System.out.print(">>");
        String apiSecret = in.nextLine();
 
        OAuthService service = new ServiceBuilder()
            .provider(YammerApi.class) 
            .apiKey(apiKey)
            .apiSecret(apiSecret)
            .build(); 

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:next, useDelimiter
public class YahooQuoteFetcherTest extends TestCase {
 
    public void testParseQuotes() throws Exception {
        String samplePath = "src/main/resources/sample_yahoo_response.csv";
 
        Scanner scan = new Scanner(new File(samplePath));
        scan.useDelimiter("\\Z");
        String sampleResponse = scan.next().replaceAll("\r\n", "\n");
 
        YahooQuoteFetcher fetcher = new YahooQuoteFetcher();
 
        List<Quote> quotes = fetcher.parseQuotes(sampleResponse, 60 * 60 * 24);
 
        // Date,Open,High,Low,Close,Volume,Adj Close 
        // 2013-03-25,812.41,819.23,806.82,809.64,1712000,809.64 
 
        Quote firstQuote = quotes.get(0);
        assertEquals(firstQuote.getOpen(), new BigDecimal("812.41"));
        assertEquals(firstQuote.getHigh(), new BigDecimal("819.23"));
        assertEquals(firstQuote.getLow(), new BigDecimal("806.82"));
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
        assertFileContains(moduleXMLFile,rootElement);
        assertFileContains(moduleXMLFile, format("name=\"%s\"", moduleName));
    } 
 
    private static void assertFileContains(File f, String string) throws Exception {
        String content = new Scanner(f, "UTF-8").useDelimiter("\\Z").next();
        assertTrue(string + " not found in " + f + " with content=" + content, content.contains(string));
    } 
 
    public static void assertPatchHasBeenApplied(PatchingResult result, Patch patch) {
        if (CUMULATIVE == patch.getIdentity().getPatchType()) {
            assertEquals(patch.getPatchId(), result.getPatchInfo().getCumulativePatchID());
            assertTrue(result.getPatchInfo().getPatchIDs().isEmpty());
            assertEquals(patch.getIdentity().forType(CUMULATIVE, org.jboss.as.patching.metadata.Identity.IdentityUpgrade.class).getResultingVersion(), result.getPatchInfo().getVersion());
        } else { 
            assertTrue(result.getPatchInfo().getPatchIDs().contains(patch.getPatchId()));
            // applied one-off patch is at the top of the patchIDs 
            assertEquals(patch.getPatchId(), result.getPatchInfo().getPatchIDs().get(0));
        } 
    } 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:close, next
	private static int readVersionFile() { 
		if (! versionFile.exists()) return 0;
		Scanner in;
		int versionCode = 0;
		try { 
			in = new Scanner(versionFile);
			versionCode = Integer.parseInt(in.next());
			in.close();
		} catch (Exception e) {
			LilDebi.log.append("Can't read app version file: " + e.getLocalizedMessage() + "\n");
		} 
		return versionCode;
	} 
 
	private static void writeVersionFile(Context context) {
		try { 
			PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
			FileOutputStream fos = new FileOutputStream(versionFile);
			OutputStreamWriter out = new OutputStreamWriter(fos);
			out.write(String.valueOf(pInfo.versionCode) + "\n");
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:findWithinHorizon, hasNext, match
            } 
        } 
 
        void init() { 
            // use a scanner with the default delimiter 
            this.scanner = new Scanner(in, charset);
            this.image = scanner.hasNext() ? (String) next(true) : null;
        } 
 
        String getNext(boolean first) {
            // initialize inherited namespaces on first 
            if (first && inheritNamespaceToken != null && !wrapToken) {
                rootTokenNamespaces =  getNamespacesFromNamespaceToken(scanner.findWithinHorizon(inheritNamespaceTokenPattern, 0));
            } 
 
            String next = scanner.findWithinHorizon(tagTokenPattern, 0);
            if (next == null) {
                return null; 
            } 
            if (first && wrapToken) {

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Java 8 Scanner Questions & Answers:

See Code Examples for Java 8 Scanner Methods: